@tomei/rental
Version:
Tomei Rental Package
208 lines • 8.63 kB
JavaScript
"use strict";
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 async init(signatureId, dbTransaction) {
try {
if (signatureId) {
const hirerChangeReqSignature = await 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,
};
}
async create(loginUser, dbTransaction) {
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,
};
await 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);
await activity.create(loginUser.ObjectId, dbTransaction);
return this;
}
catch (error) {
throw error;
}
}
async update(loginUser, dbTransaction) {
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,
};
await 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);
await activity.create(loginUser.ObjectId, dbTransaction);
return this;
}
catch (error) {
throw error;
}
}
async markSigned(loginUser, dbTransaction) {
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,
};
await 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);
await 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