feat: implement dynamic create DTO for User

This commit is contained in:
yassinedorbozgithub 2025-01-10 07:57:37 +01:00
parent 382bdd4ef1
commit 7f59f593c5
3 changed files with 22 additions and 11 deletions

View File

@ -22,6 +22,7 @@ import {
IsString,
} from 'class-validator';
import { DtoConfig } from '@/utils/types/dto.types';
import { IsObjectId } from '@/utils/validation-rules/is-object-id';
export class UserCreateDto {
@ -98,3 +99,7 @@ export class UserResetPasswordDto extends PickType(UserCreateDto, [
]) {}
export class UserRequestResetDto extends PickType(UserCreateDto, ['email']) {}
export type TUserCrudsDto = DtoConfig<{
create: UserCreateDto;
}>;

View File

@ -50,6 +50,16 @@ export class UserStub extends BaseSchema {
})
password: string;
@Prop([{ type: MongooseSchema.Types.ObjectId, ref: 'Role' }])
roles: unknown;
@Prop({
type: MongooseSchema.Types.ObjectId,
ref: 'Attachment',
default: null,
})
avatar: unknown;
@Prop({
type: Boolean,
default: false,
@ -83,16 +93,6 @@ export class UserStub extends BaseSchema {
})
resetCount?: number;
@Prop([{ type: MongooseSchema.Types.ObjectId, ref: 'Role' }])
roles: unknown;
@Prop({
type: MongooseSchema.Types.ObjectId,
ref: 'Attachment',
default: null,
})
avatar: unknown;
@Prop({
type: String,
default: null,

View File

@ -10,11 +10,17 @@ import { Injectable } from '@nestjs/common';
import { BaseService } from '@/utils/generics/base-service';
import { TUserCrudsDto } from '../dto/user.dto';
import { UserRepository } from '../repositories/user.repository';
import { User, UserFull, UserPopulate } from '../schemas/user.schema';
@Injectable()
export class UserService extends BaseService<User, UserPopulate, UserFull> {
export class UserService extends BaseService<
User,
UserPopulate,
UserFull,
TUserCrudsDto
> {
constructor(readonly repository: UserRepository) {
super(repository);
}