import { DeepPartial, DeleteResult, FindOptionsWhere, FindManyOptions, FindOneOptions, Repository, UpdateResult } from 'typeorm'; import { IBasePerTenantEntityModel, ID, IPagination, IUser } from '@metad/contracts'; import { TenantBaseEntity, User } from '../entities/internal'; import { CrudService } from './crud.service'; import { ICrudService } from './icrud.service'; import { ITryRequest } from './try-request'; /** * This abstract class adds tenantId to all query filters if a user is available in the current RequestContext * If a user is not available in RequestContext, then it behaves exactly the same as CrudService */ export declare abstract class TenantAwareCrudService extends CrudService implements ICrudService { protected readonly repository: Repository; protected constructor(repository: Repository); protected findConditionsWithTenantByUser(user: IUser): FindOptionsWhere; protected findConditionsWithTenant(user: User, where?: FindOptionsWhere[] | FindOptionsWhere): FindOptionsWhere[] | FindOptionsWhere; protected findOneWithTenant(filter?: FindOneOptions): FindOneOptions; private findManyWithTenant; count(filter?: FindManyOptions): Promise; findAll(filter?: FindManyOptions): Promise>; /** * Finds first entity by a given find options with current tenant. * If entity was not found in the database - rejects with error. * * @param id * @param options * @returns */ findOneOrFailByIdString(id: ID, options?: FindOneOptions): Promise>; /** * Finds first entity that matches given options with current tenant. * If entity was not found in the database - rejects with error. * * @param options * @returns */ findOneOrFailByOptions(options?: FindOneOptions): Promise>; /** * Finds first entity that matches given where condition with current tenant. * If entity was not found in the database - rejects with error. * * @param options * @returns */ findOneOrFailByWhereOptions(options: FindOptionsWhere): Promise>; findOne(id: string | number | FindOneOptions, options?: FindOneOptions): Promise; /** * Finds first entity that matches given id and options with current tenant. * * @param id {string} * @param options * @returns */ findOneByIdString(id: string, options?: FindOneOptions): Promise; /** * Finds first entity that matches given options with current tenant. * * @param options * @returns */ findOneByOptions(options: FindOneOptions): Promise; /** * Finds first entity that matches given where condition with current tenant. * If entity was not found in the database - returns null. * * @param options * @returns */ findOneByWhereOptions(options: FindOptionsWhere): Promise; create(entity: DeepPartial, ...options: any[]): Promise; /** * DELETE source related to tenant * * @param criteria - A string ID or a set of conditions to identify which record to delete. * @param options - Additional options for querying, such as extra conditions or query parameters. * @returns {Promise} - The result of the delete operation. */ delete(criteria: string | FindOptionsWhere, options?: FindOneOptions): Promise; findMyAll(filter?: FindManyOptions): Promise>; protected findConditionsWithUser(user: IUser, where?: FindManyOptions['where']): FindManyOptions['where']; /** * 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 complex query to identify which entity to soft-delete. * @param options - Additional options for the operation. * @returns {Promise} - Result indicating success or failure. */ softDelete(criteria: string | number | FindOptionsWhere, options?: FindOneOptions): Promise; /** * Alternatively, You can recover the soft deleted rows by using the restore() method: */ restoreSoftDelete(id: string, options?: IBasePerTenantEntityModel): Promise; }