import { ID, IPagination } from '@metad/contracts'; import { DeepPartial, DeleteResult, FindManyOptions, FindOneOptions, FindOptionsWhere, Repository, SaveOptions, UpdateResult } from 'typeorm'; import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity'; import { BaseEntity } from '../entities/internal'; import { ICrudService, IFindOneOptions, IFindWhereOptions } from './icrud.service'; import { ITryRequest } from './try-request'; export declare abstract class CrudService implements ICrudService { protected readonly repository: Repository; /** * Alias (default we used table name) for pagination crud */ protected get alias(): string; protected constructor(repository: Repository); findMyAll(filter?: FindManyOptions): Promise>; count(filter?: FindManyOptions): Promise; countBy(filter?: FindOptionsWhere): Promise; findAll(filter?: FindManyOptions): Promise>; paginate(filter?: any): Promise>; /** * @internal */ protected _findOneOrFailByIdString(id: string, options?: IFindOneOptions): Promise>; /** * Finds first entity by a given find options. * If entity was not found in the database - rejects with error. * * @param id * @param options * @returns */ findOneOrFailByIdString(id: string, options?: IFindOneOptions): Promise>; /** * @internal */ protected _findOneOrFailByOptions(options: IFindOneOptions): Promise>; /** * Finds first entity by a given find options. * If entity was not found in the database - rejects with error. * * @param options * @returns */ findOneOrFailByOptions(options: IFindOneOptions): Promise>; /** * @deprecated use findOneOrFailByIdString or findOneOrFailByOptions instead */ findOneOrFail(id: string | number | FindOneOptions, options?: FindOneOptions): Promise; /** * Finds first entity that matches given where condition. * If entity was not found in the database - rejects with error. * * @param options * @returns */ findOneOrFailByWhereOptions(options: IFindWhereOptions): Promise>; /** * Finds first entity by a given find options. * If entity was not found in the database - returns null. * * @param id {string} * @param options * @returns */ findOneByIdString(id: ID, options?: IFindOneOptions): Promise; findOne(id: string | number | FindOneOptions, options?: FindOneOptions): Promise; /** * Finds first entity that matches given options. * * @param options * @returns */ findOneByOptions(options: FindOneOptions): Promise; /** * Finds first entity that matches given where condition. * If entity was not found in the database - returns null. * * @param options * @returns */ findOneByWhereOptions(options: IFindWhereOptions): Promise; create(entity: DeepPartial, ...options: any[]): Promise; protected checkUpdateAuthorization(id: string | number | FindOptionsWhere): Promise; update(id: string | number | FindOptionsWhere, partialEntity: QueryDeepPartialEntity, ...options: any[]): Promise; /** * Deletes a record based on the given criteria. * Criteria can be an ID (string or number) or a complex object with conditions. * * @param criteria - Identifier or condition to delete specific record(s). * @returns {Promise} - Result indicating the number of affected records. */ delete(criteria: string | number | FindOptionsWhere): Promise; /** * Softly deletes entities by a given criteria. * This method sets a flag or timestamp indicating the entity is considered deleted. * It does not actually remove the entity from the database, allowing for recovery or audit purposes. * * @param criteria - Entity ID or condition to identify which entities to soft-delete. * @param options - Additional options for the operation. * @returns {Promise} - Result indicating success or failure. */ softDelete(criteria: string | number | FindOptionsWhere): Promise; /** * Softly removes an entity from the database. * * @param id - The unique identifier of the entity to be softly removed. * @param options - Optional parameters for finding the entity * @param saveOptions - Additional save options for the ORM operation * @returns A promise that resolves to the softly removed entity. */ softRemove(id: T['id'], options?: FindOneOptions, saveOptions?: SaveOptions): Promise; /** * Soft-recover a previously soft-deleted entity. * * Depending on the ORM, this method restores a soft-deleted entity by resetting its deletion indicator. * * @param entity - The soft-deleted entity to recover. * @param options - Optional settings for database save operations. * @returns A promise that resolves with the recovered entity. */ softRecover(id: T['id'], options?: FindOneOptions, saveOptions?: SaveOptions): Promise; }