UNPKG

@alecslab/nestjs-crud-kit

Version:

Base clases of CRUD operations for NestJs

39 lines 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseService = void 0; const common_1 = require("@nestjs/common"); class BaseService { constructor(repository) { this.repository = repository; this.baseServiceLogger = new common_1.Logger(BaseService.name); } async create(item) { this.baseServiceLogger.debug(`create: ${item}`); return await this.repository.create(item); } async findAll(options) { this.baseServiceLogger.debug(`findAll options: ${options}`); return await this.repository.findAll(options); } async findOne(id, options) { this.baseServiceLogger.debug(`findOne id: ${id}`); this.baseServiceLogger.debug(`findOne options: ${options}`); const entity = await this.repository.findOne(id); if (entity) { return entity; } throw new common_1.NotFoundException(); } async update(id, item) { this.baseServiceLogger.debug(`update id: ${id}`); this.baseServiceLogger.debug(`update entity values: ${item}`); const entity = await this.repository.findOne(id); return await this.repository.update(id, entity); } async remove(id) { this.baseServiceLogger.debug(`remove id: ${id}`); return this.repository.delete(id); } } exports.BaseService = BaseService; //# sourceMappingURL=BaseService.js.map