????
Current Path : C:/inetpub/vhost/qnquyhoach.nextform.vn/api/dist/apps/audit-logs/ |
Current File : C:/inetpub/vhost/qnquyhoach.nextform.vn/api/dist/apps/audit-logs/audit-logs.service.js |
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AuditLogService = void 0; const crud_typeorm_1 = require("@dataui/crud-typeorm"); const common_1 = require("@nestjs/common"); const audit_log_entity_1 = require("./entities/audit-log.entity"); const typeorm_1 = require("@nestjs/typeorm"); const log_cay_xanh_entity_1 = require("../log-cay-xanhs/entities/log-cay-xanh.entity"); const typeorm_2 = require("typeorm"); const ht_cay_xanh_entity_1 = require("../ht-cay-xanhs/entities/ht-cay-xanh.entity"); const nestjs_cls_1 = require("nestjs-cls"); let AuditLogService = class AuditLogService extends crud_typeorm_1.TypeOrmCrudService { constructor(repo, logCayXanhRepo, htCayXanhRepo, dataSource, cls) { super(repo); this.logCayXanhRepo = logCayXanhRepo; this.htCayXanhRepo = htCayXanhRepo; this.dataSource = dataSource; this.cls = cls; } async auditLogCayXanh(dto) { try { const logCayXanh = await this.logCayXanhRepo.findOne({ where: { id: dto.logId, status: 'pending' } }); if (!logCayXanh) { throw new common_1.HttpException('Không tìm thấy log', common_1.HttpStatus.NOT_FOUND); } const existingAuditLog = await this.repo.findOne({ where: { logTableName: 'cay-xanh', logId: logCayXanh.id } }); if (existingAuditLog) { throw new common_1.HttpException('Log đã được xét duyệt', common_1.HttpStatus.NOT_FOUND); } if (dto.status === 'approved') { if (logCayXanh.action === 'POST') { const newHtCayXanh = new ht_cay_xanh_entity_1.HTCayXanh(); newHtCayXanh.DoCao = logCayXanh.DoCao; newHtCayXanh.DuongKinhGoc = logCayXanh.DuongKinhGoc; newHtCayXanh.MaDuong = logCayXanh.MaDuong; newHtCayXanh.GhiChu = logCayXanh.GhiChu; newHtCayXanh.NamCapNhat = logCayXanh.NamCapNhat; newHtCayXanh.TinhTrang = logCayXanh.TinhTrang; newHtCayXanh.TenLoaiCay = logCayXanh.TenLoaiCay; await this.htCayXanhRepo.save(newHtCayXanh); } if (logCayXanh.action === 'PUT' || logCayXanh.action === 'PATCH') { const updatedHtCayXanh = { DoCao: logCayXanh.DoCao, DuongKinhGoc: logCayXanh.DuongKinhGoc, MaDuong: logCayXanh.MaDuong, GhiChu: logCayXanh.GhiChu, NamCapNhat: logCayXanh.NamCapNhat, TinhTrang: logCayXanh.TinhTrang, TenLoaiCay: logCayXanh.TenLoaiCay, }; await this.htCayXanhRepo.update(logCayXanh.gidCayXanh, updatedHtCayXanh); } } await this.logCayXanhRepo.update(logCayXanh.id, { status: dto.status }); return { logId: logCayXanh.id, tableName: this.dataSource.getMetadata(log_cay_xanh_entity_1.LogCayXanh).tableName }; } catch (error) { throw new common_1.HttpException('Đã xảy ra lỗi trong quá trình xét duyệt log', common_1.HttpStatus.NOT_FOUND); } } }; exports.AuditLogService = AuditLogService; exports.AuditLogService = AuditLogService = __decorate([ (0, common_1.Injectable)(), __param(0, (0, typeorm_1.InjectRepository)(audit_log_entity_1.AuditLog)), __param(1, (0, typeorm_1.InjectRepository)(log_cay_xanh_entity_1.LogCayXanh)), __param(2, (0, typeorm_1.InjectRepository)(ht_cay_xanh_entity_1.HTCayXanh)), __metadata("design:paramtypes", [typeorm_2.Repository, typeorm_2.Repository, typeorm_2.Repository, typeorm_2.DataSource, nestjs_cls_1.ClsService]) ], AuditLogService); //# sourceMappingURL=audit-logs.service.js.map