I have many resolvers and one abstract resolver from which all will inherit.
How can I pass a model to this abstract resolver? – I need to put it in Query and ResolveField
Below is the code resolver(Users) and resolver(Entity) – Users is inherited from Entity. As well as the entity and users model module
@Resolver(() => EntityModel)
export abstract class EntityResolver<M, CMD, UMD> {
protected constructor(protected service: EntityService<M>) {}
@RolesGuards([ROLES.USER])
@ResolveField(() => /* MODEL */)
@Query(() => /* MODEL */)
async findAll(): Promise<{ response: M[]; statusCode: number }> {
return {
statusCode: HttpStatus.OK,
response: await this.service.findAll(),
}
}
}
@Resolver(() => Users)
export default class UsersResolver extends EntityResolver<Users, CreateUsersDto, UpdateUsersDto> {
constructor(protected service: UsersService) {
super(service)
}
@RolesGuards([ROLES.ADMIN])
@Get('/email/:email')
async findByEmail(
@Param('email') email: string,
): Promise<{ response: Users; statusCode: number }> {
return {
statusCode: HttpStatus.OK,
response: await this.service.findByEmail(email),
}
}
}
@Module({
controllers: [UsersController],
providers: [UsersService, UsersResolver],
imports: [SequelizeModule.forFeature([Users]), RolesModule, LoggerModule],
exports: [SequelizeModule, UsersService],
})
export class UsersModule {}
@ObjectType()
export class EntityModel<M, MCA = {}> extends Model<M, MCA> {
user_id: string;
}
interface UserCreationAttrs {
id: string
email: string
password: string
}
@ObjectType()
@Table({ tableName: 'Users' })
export class Users extends EntityModel<Users, UserCreationAttrs> {
@Column({
type: DataType.STRING,
unique: true,
primaryKey: true,
})
id: string
@Column({ type: DataType.STRING, unique: true, allowNull: false })
email: string
@Column({ type: DataType.STRING, allowNull: false })
password: string
@BelongsToMany(() => Roles, () => UsersRoles)
roles: Roles[]
@HasMany(() => Funds)
funds: Funds[]
@HasMany(() => Expense)
expense: Expense[]
@HasMany(() => ExpenseCategories)
expenseCategories: ExpenseCategories[]
@HasMany(() => Income)
income: Income[]
@HasMany(() => IncomeCategories)
incomeCategories: IncomeCategories[]
}
I tried to pass the model through the constructor, but for some reason I was told that the model could be undefined.