UNPKG

@aequum/typeorm

Version:

aequum TypeORM tools for repository, pagination, CRUD/CRUDL, configs and utils

63 lines (62 loc) 2.77 kB
import type { FindOptionsWhere } from 'typeorm'; import { BaseCRUDLService } from '@aequum/crudl'; import { TypeORMRepository } from '../repositories'; /** * Base CRUD/CRUDL TypeORM Service for a TypeORM Entity Model. * * **NOTE**: If you want to present different primary key * field you must pass the `PrimaryKeyField` type parameter. * and set the `primaryKeyField` property to the name of * the field. */ export declare abstract class BaseCRUDLTypeORMService<EntityModel extends { [key in PrimaryKeyField]: any; }, EntityModelDto, EntityModelCreateDto, EntityModelUpdateDto, QueryFilter = any, PrimaryKeyField extends string = 'id'> extends BaseCRUDLService implements BaseCRUDLService { /** The primary key field */ protected primaryKeyField: PrimaryKeyField; /** Unique fields to show when a dulplicate error is found */ static uniqueFields: string[]; /** Custom duplicated entry exception message */ static duplicatedEntryMessage?: string; /** Default TypeORM filter to apply to all queries */ protected defaultTypeORMFilter: FindOptionsWhere<EntityModel>; /** * Method to get the default TypeORM filter to apply to all * queries when an instance member is needed to create the * default filter, by default returns the * `defaultTypeORMFilter` property. * * If you don't need a local instance member to create the * default filter, you just need to change the * `defaultTypeORMFilter` property. * * @protected */ protected getDefaultTypeORMFilter(): FindOptionsWhere<EntityModel>; /** @ignore */ static duplicateEntryExceptionMessage(): string; /** * Convert a custom query filter to a TypeORM filter * * @param filter Custom query filter, the fifth type argument * @returns TypeORM filter */ queryFilterToTypeORMFilter(filter: QueryFilter): FindOptionsWhere<EntityModel>; /** TypeORM Repository to interact with the Mongoose Model */ protected readonly repository: TypeORMRepository<EntityModel>; /** @inheritdoc */ create(data: EntityModelCreateDto): Promise<EntityModelDto>; /** @inheritdoc */ retrieve(id: EntityModel[PrimaryKeyField]): Promise<EntityModelDto>; /** @inheritdoc */ retrieveBy(filter: QueryFilter): Promise<EntityModelDto>; /** @inheritdoc */ update(id: EntityModel[PrimaryKeyField], data: EntityModelUpdateDto): Promise<EntityModelDto>; updateBy(filter: QueryFilter, data: EntityModelUpdateDto): Promise<EntityModelDto>; /** @inheritdoc */ delete(id: EntityModel[PrimaryKeyField]): Promise<void>; /** @inheritdoc */ deleteBy(filter: QueryFilter): Promise<void>; /** @inheritdoc */ list(filter?: any): Promise<EntityModelDto[]>; }