UNPKG

@tomei/rental

Version:
225 lines 10.2 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HirerChangeRequestSignature = void 0; const general_1 = require("@tomei/general"); const hirer_change_request_signature_repository_1 = require("./hirer-change-request-signature.repository"); const activity_history_1 = require("@tomei/activity-history"); class HirerChangeRequestSignature extends general_1.ObjectBase { constructor(attr) { super(); this.ObjectType = 'HirerChangeRequestSignature'; this.TableName = 'hirerChangeRequest_Signature'; if (attr) { this.SignatureId = attr.SignatureId; this.RequestId = attr.RequestId; this.CustomerId = attr.CustomerId; this.JointHirerId = attr.JointHirerId; this.SignedAt = attr.SignedAt; this.Method = attr.Method; this.HirerType = attr.HirerType; this.Remarks = attr.Remarks; this.CreatedAt = attr.CreatedAt; this.UpdatedAt = attr.UpdatedAt; this.UpdatedById = attr.UpdatedById; } } get SignatureId() { return this.ObjectId; } set SignatureId(value) { this.ObjectId = value; } static init(signatureId, dbTransaction) { return __awaiter(this, void 0, void 0, function* () { try { if (signatureId) { const hirerChangeReqSignature = yield HirerChangeRequestSignature._Repository.findByPk(signatureId, dbTransaction); if (hirerChangeReqSignature) { return new HirerChangeRequestSignature(hirerChangeReqSignature.get({ plain: true })); } else { throw new general_1.ClassError('HirerChangeRequestSignature', 'HirerChangeRequestSignatureErrMsg00', 'HirerChangeRequestSignature not found'); } } return new HirerChangeRequestSignature(); } catch (error) { throw error; } }); } toJSON() { return { SignatureId: this.SignatureId, RequestId: this.RequestId, CustomerId: this.CustomerId, JointHirerId: this.JointHirerId, HirerType: this.HirerType, SignedAt: this.SignedAt, Method: this.Method, Remarks: this.Remarks, CreatedAt: this.CreatedAt, UpdatedAt: this.UpdatedAt, UpdatedById: this.UpdatedById, }; } create(loginUser, dbTransaction) { return __awaiter(this, void 0, void 0, function* () { try { this.ObjectId = this.createId(); this.CreatedAt = new Date(); this.UpdatedById = loginUser.ObjectId; this.UpdatedAt = new Date(); const entityValueAfter = { SignatureId: this.SignatureId, RequestId: this.RequestId, CustomerId: this.CustomerId, JointHirerId: this.JointHirerId, HirerType: this.HirerType, SignedAt: this.SignedAt, Method: this.Method, Remarks: this.Remarks, CreatedAt: this.CreatedAt, UpdatedAt: this.UpdatedAt, UpdatedById: this.UpdatedById, }; yield HirerChangeRequestSignature._Repository.create(entityValueAfter, { transaction: dbTransaction, }); const activity = new activity_history_1.Activity(); activity.ObjectId = this._createId(); activity.Action = activity_history_1.ActionEnum.CREATE; activity.Description = 'Add Hirer Change Request Signature'; activity.EntityId = this.ObjectId; activity.EntityType = this.ObjectType; activity.EntityValueBefore = JSON.stringify({}); activity.EntityValueAfter = JSON.stringify(entityValueAfter); yield activity.create(loginUser.ObjectId, dbTransaction); return this; } catch (error) { throw error; } }); } update(loginUser, dbTransaction) { return __awaiter(this, void 0, void 0, function* () { try { const entityValueBefore = { SignatureId: this.SignatureId, RequestId: this.RequestId, CustomerId: this.CustomerId, JointHirerId: this.JointHirerId, HirerType: this.HirerType, SignedAt: this.SignedAt, Method: this.Method, Remarks: this.Remarks, CreatedAt: this.CreatedAt, UpdatedAt: this.UpdatedAt, UpdatedById: this.UpdatedById, }; this.SignedAt = new Date(); this.UpdatedById = loginUser.ObjectId; this.UpdatedAt = new Date(); const entityValueAfter = { SignatureId: this.SignatureId, RequestId: this.RequestId, CustomerId: this.CustomerId, JointHirerId: this.JointHirerId, HirerType: this.HirerType, SignedAt: this.SignedAt, Method: this.Method, Remarks: this.Remarks, CreatedAt: this.CreatedAt, UpdatedAt: this.UpdatedAt, UpdatedById: this.UpdatedById, }; yield HirerChangeRequestSignature._Repository.update(entityValueAfter, { where: { SignatureId: this.SignatureId, }, transaction: dbTransaction, }); const activity = new activity_history_1.Activity(); activity.ObjectId = this._createId(); activity.Action = activity_history_1.ActionEnum.UPDATE; activity.Description = 'Update Hirer Change Request Signature'; activity.EntityId = this.ObjectId; activity.EntityType = this.ObjectType; activity.EntityValueBefore = JSON.stringify(entityValueBefore); activity.EntityValueAfter = JSON.stringify(entityValueAfter); yield activity.create(loginUser.ObjectId, dbTransaction); return this; } catch (error) { throw error; } }); } markSigned(loginUser, dbTransaction) { return __awaiter(this, void 0, void 0, function* () { try { const entityValueBefore = { SignatureId: this.SignatureId, RequestId: this.RequestId, CustomerId: this.CustomerId, JointHirerId: this.JointHirerId, HirerType: this.HirerType, SignedAt: this.SignedAt, Method: this.Method, Remarks: this.Remarks, CreatedAt: this.CreatedAt, UpdatedAt: this.UpdatedAt, UpdatedById: this.UpdatedById, }; this.SignedAt = new Date(); this.UpdatedById = loginUser.ObjectId; this.UpdatedAt = new Date(); const entityValueAfter = { SignatureId: this.SignatureId, RequestId: this.RequestId, CustomerId: this.CustomerId, JointHirerId: this.JointHirerId, HirerType: this.HirerType, SignedAt: this.SignedAt, Method: this.Method, Remarks: this.Remarks, CreatedAt: this.CreatedAt, UpdatedAt: this.UpdatedAt, UpdatedById: this.UpdatedById, }; yield HirerChangeRequestSignature._Repository.update(entityValueAfter, { where: { SignatureId: this.SignatureId, }, transaction: dbTransaction, }); const activity = new activity_history_1.Activity(); activity.ObjectId = this._createId(); activity.Action = activity_history_1.ActionEnum.UPDATE; activity.Description = 'Mark Hirer Change Request Signature as Signed'; activity.EntityId = this.ObjectId; activity.EntityType = this.ObjectType; activity.EntityValueBefore = JSON.stringify(entityValueBefore); activity.EntityValueAfter = JSON.stringify(entityValueAfter); yield activity.create(loginUser.ObjectId, dbTransaction); return this; } catch (error) { throw error; } }); } } exports.HirerChangeRequestSignature = HirerChangeRequestSignature; HirerChangeRequestSignature._Repository = new hirer_change_request_signature_repository_1.HirerChangeRequestSignatureRepository(); //# sourceMappingURL=hirer-change-request-signature.js.map