Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Hooks #1547

Open
kingrootid opened this issue Jul 7, 2022 · 7 comments
Open

Create Hooks #1547

kingrootid opened this issue Jul 7, 2022 · 7 comments

Comments

@kingrootid
Copy link

Hello,

i was created hooks for CreateOne, CreateMany, UpdatedOne, UpdatedMany

but i want to make BeforeFindOne and BeforeFindMany using hooks

i dont now how to write in hooks
@Injectable() export class findByUserHook<T extends CreatedBy> implements BeforeFindOneHook<UserContext> { run( instance: FindOneArgsType, context: UserContext, ): Promise<FindOneArgsType>; async run( instance: FindOneArgsType, context: UserContext, ): Promise<FindOneArgsType> { instance.createdBy = { eq: context.req.user.id }; // error in here }

@TriPSs
Copy link

TriPSs commented Jul 7, 2022

You can also overwrite the service and then overwrite the query methods

@kingrootid
Copy link
Author

@BeforeCreateOne( (input: CreateOneInputType<CytologyDto>, context: UserContext) => { console.log('inputan', input); return input; }, ) @BeforeUpdateOne( (input: UpdateOneInputType<CytologyDto>, context: UserContext) => { console.log('inputan', input); return input; }, )
ref: https://doug-martin.github.io/nestjs-query/docs/graphql/hooks/#hook-fnction
and the console not printed

@TriPSs
Copy link

TriPSs commented Apr 18, 2023

Could you please share your whole DTO? And put it between ``` for better reading.

@kingrootid
Copy link
Author

import { TransactionDto } from '../transaction/transaction.dto';
import { UserDto } from '../../master/user/user.dto';
import { TransactionBaseDto } from '@/src/config/transaction_base.dto';

import {
  BeforeCreateOne,
  BeforeDeleteMany,
  BeforeDeleteOne,
  BeforeUpdateOne,
  CreateOneInputType,
  FilterableField,
  FilterableRelation,
  IDField,
  PagingStrategies,
  QueryOptions,
  UnPagedRelation,
  UpdateOneInputType,
} from '@nestjs-query/query-graphql';
import {
  Field,
  Float,
  GraphQLISODateTime,
  ID,
  ObjectType,
  PartialType,
} from '@nestjs/graphql';
import { IsArray, IsBoolean, isNumber, IsNumber } from 'class-validator';
import { DeleteByAdminHook } from '../../../common/hooks/admin_hook';
import { CustomerDto } from '../../master/customer/customer.dto';
import { LabDto } from '../../master/lab/lab.dto';
import { PatientDto } from '../../master/patient/patient.dto';
import { CreateLogHook } from '../../../common/hooks/log_hook';
import { UserContext } from '../../auth/auth.types';

@ObjectType('cytology')
@BeforeCreateOne(
  (input: CreateOneInputType<CytologyDto>, context: UserContext) => {
    console.log('inputan', input);
    return input;
  },
)
@BeforeUpdateOne(
  (input: UpdateOneInputType<CytologyDto>, context: UserContext) => {
    console.log('inputan', input);
    return input;
  },
)
@BeforeDeleteOne(DeleteByAdminHook)
@BeforeDeleteMany(DeleteByAdminHook)
@QueryOptions({
  pagingStrategy: PagingStrategies.OFFSET,
  enableTotalCount: true,
})
@FilterableRelation('transaction', () => TransactionDto, {
  disableRemove: true,
  disableUpdate: true,
})
@FilterableRelation('user1stApprover', () => UserDto, {
  disableRemove: true,
  disableUpdate: true,
  nullable: true,
})
@FilterableRelation('user2ndApprover', () => UserDto, {
  disableRemove: true,
  disableUpdate: true,
  nullable: true,
})
export class CytologyDto {
  @FilterableField({ nullable: true })
  approval_status: string;

  @FilterableField({ nullable: true })
  user_1st_approver_id: string;

  @FilterableField({ nullable: true })
  user_2nd_approver_id: string;

  @IDField(() => ID)
  id: string;

  @FilterableField({ name: 'transaction_id' })
  transaction_id: string;

  // REQUEST FORM
  @FilterableField({ nullable: true })
  rf_notes: string;
  @FilterableField({ nullable: true })
  rf_result_reporting_method: string;
  @FilterableField({ nullable: true })
  rf_result_reporting_email: string;

  // SAMPLE INFORMATION
  @FilterableField({ nullable: true })
  si_specimen_location: string;
  @FilterableField({ nullable: true })
  si_hormon_status: string;
  @FilterableField({ nullable: true })
  si_hormon_status_others: string;
  @FilterableField({ nullable: true })
  si_contraception: string;
  @FilterableField({ nullable: true })
  si_gynaecology_status: string;
  @FilterableField({ nullable: true })
  si_gynaecology_status_others: string;
  @FilterableField({ nullable: true })
  si_fixation: string;
  @FilterableField({ nullable: true })
  si_fixation_others: string;
  @FilterableField({ nullable: true })

  // TEST REQUEST
  // tr_gc_fnab: boolean;
  // @FilterableField({ nullable: true })
  // tr_gc_tbna: boolean;
  // @FilterableField({ nullable: true })
  // tr_gc_ttna: boolean;
  // @FilterableField({ nullable: true })
  // tr_gc_bal: boolean;
  // @FilterableField({ nullable: true })
  // tr_gc_bronchial_brushing: boolean;
  // @FilterableField({ nullable: true })
  // tr_gc_bronchial_washing: boolean;
  // @FilterableField({ nullable: true })
  // tr_gc_body_fluid: string;
  // @FilterableField({ nullable: true })
  // tr_gc_body_fluid_others: string;
  // @FilterableField({ nullable: true })
  // tr_gc_sputum_1x: boolean;
  // @FilterableField({ nullable: true })
  // tr_gc_sputum_3x: boolean;
  // @FilterableField({ nullable: true })
  // tr_gc_urine: boolean;
  // @FilterableField({ nullable: true })
  // tr_gc_tb_suspected_review: boolean;
  // @FilterableField({ nullable: true })
  // tr_as_add_unstained_slide: number;
  // @FilterableField({ nullable: true })
  // tr_as_add_papanicolaou_slide: number;
  // @FilterableField({ nullable: true })
  // tr_as_add_giemsa_slide: number;
  // @FilterableField({ nullable: true })
  // tr_as_add_h_n_e_slide: number;
  // @FilterableField({ nullable: true })
  // tr_as_produce_a_cell_block: boolean;
  // @FilterableField({ nullable: true })
  // tr_as_processing_cytology_pa_only_without_review: boolean;
  // @FilterableField({ nullable: true })
  // tr_as_pathology_review_or_second_opinion_per_2_slides: boolean;
  // @FilterableField({ nullable: true })
  // tr_as_slide: number;
  // @FilterableField({ nullable: true })
  // tr_as_ffpe: number;
  // @FilterableField({ nullable: true })
  // tr_as_conventional_pap_smear_review: boolean;
  // @FilterableField({ nullable: true })

  // // CYTOLOGY INFORMATION
  ci_clinical_diagnosis: string;
  @FilterableField({ nullable: true })
  ci_main_symptom_n_desc_of_the_disease: string;
  @FilterableField({ nullable: true })
  ci_prev_cytology_or_histopathology_testing_result: string;

  // TERM AND CONDITIONS
  // @FilterableField({ nullable: true })
  @FilterableField({ nullable: true })
  tnc: string;
  @FilterableField({ name: 'other_order_or_comment', nullable: true })
  other_order_or_comment: string;

  @FilterableField(() => GraphQLISODateTime)
  createdAt: Date;

  @FilterableField(() => GraphQLISODateTime)
  updatedAt: Date;
}

@TriPSs
Copy link

TriPSs commented Apr 18, 2023

What version are you using?

FYI this repo is no longer maintained (See #1538) so you could try to use my fork to see if that one works for you.

@kingrootid
Copy link
Author

"@nestjs-query/query-graphql": "^0.30.0",

@TriPSs
Copy link

TriPSs commented Apr 19, 2023

When do you expect it to be called? With one of the methods this lib creates for you for the DTO? Or did you create your own resolver?

Could you also share the module file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants