mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: update DTO type naming
This commit is contained in:
@@ -30,7 +30,7 @@ import {
|
||||
import { TFilterQuery } from '@/utils/types/filter.types';
|
||||
|
||||
import { PageQueryDto, QuerySortDto } from '../pagination/pagination-query.dto';
|
||||
import { DtoActions, DtoInfer, DtoProps } from '../types/dto.types';
|
||||
import { DtoAction, 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<DtoActions.Create, DTOCruds, U>): Promise<T> {
|
||||
async create(dto: DtoInfer<DtoAction.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<DtoActions.Create, DTOCruds, U>[],
|
||||
dtoArray: DtoInfer<DtoAction.Create, DTOCruds, U>[],
|
||||
): Promise<T[]> {
|
||||
const docs = await this.model.create(dtoArray);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import { FlattenMaps } from 'mongoose';
|
||||
|
||||
import { DtoActions, DtoInfer, DtoProps } from '../types/dto.types';
|
||||
import { DtoAction, DtoInfer, DtoProps } from '../types/dto.types';
|
||||
|
||||
import { BaseRepository } from './base-repository';
|
||||
import { BaseSchema } from './base-schema';
|
||||
@@ -33,7 +33,7 @@ export abstract class BaseSeeder<
|
||||
}
|
||||
|
||||
async seed<D extends Omit<T, keyof BaseSchema>>(
|
||||
models: DtoInfer<DtoActions.Create, DTOCruds, D>[],
|
||||
models: DtoInfer<DtoAction.Create, DTOCruds, D>[],
|
||||
): Promise<boolean> {
|
||||
if (await this.isEmpty()) {
|
||||
await this.repository.createMany(models);
|
||||
|
||||
@@ -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 { DtoActions, DtoInfer, DtoProps } from '../types/dto.types';
|
||||
import { DtoAction, 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<DtoActions.Create, DTOCruds, D>,
|
||||
dto: DtoInfer<DtoAction.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<DtoActions.Create, DTOCruds, D>,
|
||||
dto: DtoInfer<DtoAction.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<DtoActions.Create, DTOCruds, D>[],
|
||||
dtoArray: DtoInfer<DtoAction.Create, DTOCruds, D>[],
|
||||
): Promise<T[]> {
|
||||
return await this.repository.createMany(dtoArray);
|
||||
}
|
||||
|
||||
@@ -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 DtoActions {
|
||||
export enum DtoAction {
|
||||
Create = 'create',
|
||||
Read = 'read',
|
||||
Update = 'update',
|
||||
Delete = 'delete',
|
||||
}
|
||||
|
||||
export type DtoConfig<T extends Partial<Record<DtoActions, object>>> = T;
|
||||
export type DtoConfig<T extends Partial<Record<DtoAction, object>>> = T;
|
||||
|
||||
export type DtoProps<T extends Record<string, unknown>> = {
|
||||
[K in DtoActions]?: T[K];
|
||||
[K in DtoAction]?: T[K];
|
||||
};
|
||||
|
||||
export type DtoInfer<K extends keyof DTO, DTO, T> = DTO[K] extends object
|
||||
|
||||
Reference in New Issue
Block a user