UNPKG

@tomei/rental

Version:
120 lines 6.14 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.AgreementSignature = void 0; const general_1 = require("@tomei/general"); const agreement_signature_repository_1 = require("./agreement-signature.repository"); const config_1 = require("@tomei/config"); const activity_history_1 = require("@tomei/activity-history"); class AgreementSignature extends general_1.ObjectBase { get SignatureId() { return this.ObjectId; } set SignatureId(value) { this.ObjectId = value; } constructor(AgreementSignatureAttr) { super(); this.ObjectType = 'AgreementSignature'; this.TableName = 'rental_AgreementSignature'; if (AgreementSignatureAttr) { this.SignatureId = AgreementSignatureAttr.SignatureId; this.AgreementNo = AgreementSignatureAttr.AgreementNo; this.Party = AgreementSignatureAttr.Party; this.PartyId = AgreementSignatureAttr.PartyId; this.PartyType = AgreementSignatureAttr.PartyType; this.SignatureStatus = AgreementSignatureAttr.SignatureStatus; this.SignedAt = AgreementSignatureAttr.SignedAt; this.VerificationMethod = AgreementSignatureAttr.VerificationMethod; this.VerificationJustification = AgreementSignatureAttr.VerificationJustification; this.VerifiedById = AgreementSignatureAttr.VerifiedById; this.CreatedById = AgreementSignatureAttr.CreatedById; this.CreatedAt = AgreementSignatureAttr.CreatedAt; this.UpdatedById = AgreementSignatureAttr.UpdatedById; this.UpdatedAt = AgreementSignatureAttr.UpdatedAt; } } static init(AgreementSignatureId, dbTransaction) { return __awaiter(this, void 0, void 0, function* () { try { if (AgreementSignatureId) { const hs = yield AgreementSignature._Repository.findByPk(AgreementSignatureId, dbTransaction); if (hs) { return new AgreementSignature(hs.get({ plain: true })); } else { throw new general_1.ClassError('AgreementSignature', 'AgreementSignatureErrMsg01', 'AgreementSignature not found'); } } return new AgreementSignature(); } catch (error) { throw error; } }); } create(loginUser, dbTransaction) { return __awaiter(this, void 0, void 0, function* () { try { const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code'); const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'AgreementSignature - Create'); if (!isPrivileged) { throw new general_1.ClassError('AgreementSignature', 'AgreementSignatureErrMsg00', "You do not have 'AgreementSignature - Create' privilege."); } if (!this.AgreementNo || !this.PartyId || !this.PartyType) { throw new general_1.ClassError('AgreementSignature', 'AgreementSignatureErrMsg03', 'AgreementNo, PartyId and PartyType are required.'); } this.ObjectId = this.createId(); this.VerifiedById = loginUser.ObjectId; this.CreatedById = loginUser.ObjectId; this.CreatedAt = new Date(); this.UpdatedById = loginUser.ObjectId; this.UpdatedAt = new Date(); const entityValueAfter = { SignatureId: this.SignatureId, AgreementNo: this.AgreementNo, Party: this.Party, PartyId: this.PartyId, PartyType: this.PartyType, SignatureStatus: this.SignatureStatus, SignedAt: this.SignedAt, VerificationMethod: this.VerificationMethod, VerificationJustification: this.VerificationJustification, VerifiedById: this.VerifiedById, CreatedById: this.CreatedById, CreatedAt: this.CreatedAt, UpdatedById: this.UpdatedById, UpdatedAt: this.UpdatedAt, }; yield AgreementSignature._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 Joint Hirer 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; } }); } } exports.AgreementSignature = AgreementSignature; AgreementSignature._Repository = new agreement_signature_repository_1.AgreementSignatureRepository(); //# sourceMappingURL=agreement-signature.js.map