erp-construccion-backend/dist/shared/services/base.service.d.ts

73 lines
2.1 KiB
TypeScript

/**
* BaseService - Abstract Service with Common CRUD Operations
*
* Provides multi-tenant aware CRUD operations using TypeORM.
* All domain services should extend this base class.
*
* @module @shared/services
*/
import { Repository, FindOptionsWhere, FindManyOptions, DeepPartial, ObjectLiteral } from 'typeorm';
export interface PaginationOptions {
page?: number;
limit?: number;
}
export interface PaginatedResult<T> {
data: T[];
meta: {
total: number;
page: number;
limit: number;
totalPages: number;
};
}
export interface ServiceContext {
tenantId: string;
userId?: string;
}
export declare abstract class BaseService<T extends ObjectLiteral> {
protected readonly repository: Repository<T>;
constructor(repository: Repository<T>);
/**
* Find all records for a tenant with optional pagination
*/
findAll(ctx: ServiceContext, options?: PaginationOptions & {
where?: FindOptionsWhere<T>;
}): Promise<PaginatedResult<T>>;
/**
* Find one record by ID for a tenant
*/
findById(ctx: ServiceContext, id: string): Promise<T | null>;
/**
* Find one record by criteria
*/
findOne(ctx: ServiceContext, where: FindOptionsWhere<T>): Promise<T | null>;
/**
* Find records by custom options
*/
find(ctx: ServiceContext, options: FindManyOptions<T>): Promise<T[]>;
/**
* Create a new record
*/
create(ctx: ServiceContext, data: DeepPartial<T>): Promise<T>;
/**
* Update an existing record
*/
update(ctx: ServiceContext, id: string, data: DeepPartial<T>): Promise<T | null>;
/**
* Soft delete a record
*/
softDelete(ctx: ServiceContext, id: string): Promise<boolean>;
/**
* Hard delete a record (use with caution)
*/
hardDelete(ctx: ServiceContext, id: string): Promise<boolean>;
/**
* Count records
*/
count(ctx: ServiceContext, where?: FindOptionsWhere<T>): Promise<number>;
/**
* Check if a record exists
*/
exists(ctx: ServiceContext, where: FindOptionsWhere<T>): Promise<boolean>;
}
//# sourceMappingURL=base.service.d.ts.map