bb-inspired
Version:
Core library for BB-inspired NestJS backend
51 lines • 1.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseService = void 0;
const common_1 = require("@nestjs/common");
class BaseService {
constructor(repository, entityName) {
this.repository = repository;
this.entityName = entityName;
}
async findAll(filters) {
return this.repository.findAll(filters);
}
async findById(id) {
try {
return await this.repository.findById(id);
}
catch (error) {
if (error instanceof common_1.NotFoundException) {
throw error;
}
throw new common_1.NotFoundException(`${this.entityName} with ID ${id} not found`);
}
}
async findOne(filters) {
try {
return await this.repository.findOne(filters);
}
catch (error) {
if (error instanceof common_1.NotFoundException) {
throw error;
}
throw new common_1.NotFoundException(`${this.entityName} not found with specified criteria`);
}
}
async create(data) {
return this.repository.create(data);
}
async update(id, data) {
await this.findById(id);
return this.repository.update(id, data);
}
async remove(id) {
await this.findById(id);
return this.repository.softDelete(id);
}
async count(filters) {
return this.repository.count(filters);
}
}
exports.BaseService = BaseService;
//# sourceMappingURL=base.service.js.map