fix: enhance enum naming

This commit is contained in:
yassinedorbozgithub 2025-01-10 09:11:54 +01:00
parent e5e5495a42
commit 1b788cc78f
3 changed files with 10 additions and 10 deletions

View File

@ -30,7 +30,7 @@ import {
import { TFilterQuery } from '@/utils/types/filter.types';
import { PageQueryDto, QuerySortDto } from '../pagination/pagination-query.dto';
import { DtoInfer, DtoOperations, DtoProps } from '../types/dto.types';
import { DtoActions, DtoInfer, DtoProps } from '../types/dto.types';
import { BaseSchema } from './base-schema';
import { LifecycleHookManager } from './lifecycle-hook-manager';
@ -456,7 +456,7 @@ export abstract class BaseRepository<
return await this.model.countDocuments(criteria).exec();
}
async create(dto: DtoInfer<DtoOperations.Create, DTOCruds, U>): Promise<T> {
async create(dto: DtoInfer<DtoActions.Create, DTOCruds, U>): Promise<T> {
const doc = await this.model.create(dto);
return plainToClass(
@ -467,7 +467,7 @@ export abstract class BaseRepository<
}
async createMany(
dtoArray: DtoInfer<DtoOperations.Create, DTOCruds, U>[],
dtoArray: DtoInfer<DtoActions.Create, DTOCruds, U>[],
): Promise<T[]> {
const docs = await this.model.create(dtoArray);

View File

@ -14,7 +14,7 @@ import { ProjectionType, QueryOptions } from 'mongoose';
import { TFilterQuery } from '@/utils/types/filter.types';
import { PageQueryDto, QuerySortDto } from '../pagination/pagination-query.dto';
import { DtoInfer, DtoOperations, DtoProps } from '../types/dto.types';
import { DtoActions, DtoInfer, DtoProps } from '../types/dto.types';
import { BaseRepository } from './base-repository';
import { BaseSchema } from './base-schema';
@ -145,7 +145,7 @@ export abstract class BaseService<
}
async create<D extends Omit<T, keyof BaseSchema>>(
dto: DtoInfer<DtoOperations.Create, DTOCruds, D>,
dto: DtoInfer<DtoActions.Create, DTOCruds, D>,
): Promise<T> {
try {
return await this.repository.create(dto);
@ -161,7 +161,7 @@ export abstract class BaseService<
async findOneOrCreate<D extends Omit<T, keyof BaseSchema>>(
criteria: string | TFilterQuery<T>,
dto: DtoInfer<DtoOperations.Create, DTOCruds, D>,
dto: DtoInfer<DtoActions.Create, DTOCruds, D>,
): Promise<T> {
const result = await this.findOne(criteria);
if (!result) {
@ -171,7 +171,7 @@ export abstract class BaseService<
}
async createMany<D extends Omit<T, keyof BaseSchema>>(
dtoArray: DtoInfer<DtoOperations.Create, DTOCruds, D>[],
dtoArray: DtoInfer<DtoActions.Create, DTOCruds, D>[],
): Promise<T[]> {
return await this.repository.createMany(dtoArray);
}

View File

@ -6,17 +6,17 @@
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/
export enum DtoOperations {
export enum DtoActions {
Create = 'create',
Read = 'read',
Update = 'update',
Delete = 'delete',
}
export type DtoConfig<T extends Partial<Record<DtoOperations, object>>> = T;
export type DtoConfig<T extends Partial<Record<DtoActions, object>>> = T;
export type DtoProps<T extends Record<string, unknown>> = {
[K in DtoOperations]?: T[K];
[K in DtoActions]?: T[K];
};
export type DtoInfer<K extends keyof DTO, DTO, T> = DTO[K] extends object