nest-base-structure v0.0.26
The code is defining an abstract class called BaseService
in Typescript that serves as a base service for other services to inherit from.
This class contains several async methods that can be used by any inheriting service to perform CRUD (Create, Read, Update and Delete) operations on a database. These methods include:
createAndSave(dto: object)
: creates and saves a new entityfind(options?: CustomFindManyOptions<ReadModel>): Promise<{ data: ReadModel[]; skip: number; take: number; total: number } | undefined>
: finds entities based on given conditions and returns an array ofReadModel
objects along with paging information likeskip
,take
andtotal
.findReport(options?: CustomFindManyOptions<ReadModel>): Promise<{ items: ReadModel[]; skip: number; take: number; total: number } | undefined>
: finds entities and returns a report containingReadModel
objects along with paging information.reportTotal(where?: GenericEntity<ReadModel>): Promise<{ items: object }>
: returns a report containingitems
based on given conditions.findOne(conditions?: FindConditions<ReadModel>, options?: FindOneOptions<ReadModel>): Promise<ReadModel | undefined>
: finds one entity based on given conditions.findById(id: number): Promise<ReadModel>
: finds an entity by its id.delete(criteria: ...): Promise<DeleteResult>
: deletes one or multiple entities based on given criteria.deleteById(id: number): Promise<DeleteResult>
: deletes an entity by its id.update(criteria: ..., partialEntity: QueryDeepPartialEntity<WriteModel>): Promise<UpdateResult>
: updates one or multiple entities based on given criteria and a partial entity object.max(dto: MaxDto): Promise<any>
: returns the maximum value of a numeric field in a table.softDelete(criteria: ...): Promise<UpdateResult>
: soft-deletes one or multiple entities based on given criteria.
This class is essentially a generic implementation of a base service with all common CRUD operations provided. Any inheriting service can then use these methods by injecting a BaseDataAccess
object that matches the data model being worked with.
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago