erp-suite/apps/shared-libs/core/interfaces/base-service.interface.ts

84 lines
1.8 KiB
TypeScript

/**
* Base Service Interface - Contract for all domain services
*
* @module @erp-suite/core/interfaces
*/
import { PaginatedResult, PaginationOptions } from '../types/pagination.types';
/**
* Service context with tenant and user info
*/
export interface ServiceContext {
tenantId: string;
userId: string;
}
/**
* Query options for service methods
*/
export interface QueryOptions {
includeDeleted?: boolean;
}
/**
* Base service interface for CRUD operations
*
* @template T - Entity type
* @template CreateDto - DTO for create operations
* @template UpdateDto - DTO for update operations
*/
export interface IBaseService<T, CreateDto, UpdateDto> {
/**
* Find all records with pagination
*/
findAll(
ctx: ServiceContext,
filters?: PaginationOptions & Record<string, any>,
options?: QueryOptions,
): Promise<PaginatedResult<T>>;
/**
* Find record by ID
*/
findById(
ctx: ServiceContext,
id: string,
options?: QueryOptions,
): Promise<T | null>;
/**
* Create new record
*/
create(ctx: ServiceContext, data: CreateDto): Promise<T>;
/**
* Update existing record
*/
update(ctx: ServiceContext, id: string, data: UpdateDto): Promise<T | null>;
/**
* Soft delete record
*/
softDelete(ctx: ServiceContext, id: string): Promise<boolean>;
/**
* Hard delete record
*/
hardDelete(ctx: ServiceContext, id: string): Promise<boolean>;
/**
* Count records
*/
count(
ctx: ServiceContext,
filters?: Record<string, any>,
options?: QueryOptions,
): Promise<number>;
/**
* Check if record exists
*/
exists(ctx: ServiceContext, id: string, options?: QueryOptions): Promise<boolean>;
}