@tomei/rental 0.17.3-dev.6 → 0.17.3-dev.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/agreement-signature/agreement-signature.d.ts +4 -0
- package/dist/components/agreement-signature/agreement-signature.js +8 -0
- package/dist/components/agreement-signature/agreement-signature.js.map +1 -1
- package/dist/components/rental/rental.d.ts +2 -1
- package/dist/components/rental/rental.js +4 -1
- package/dist/components/rental/rental.js.map +1 -1
- package/dist/enum/agreement-signature-verification-method.enum.d.ts +4 -0
- package/dist/enum/agreement-signature-verification-method.enum.js +9 -0
- package/dist/enum/agreement-signature-verification-method.enum.js.map +1 -0
- package/dist/enum/index.d.ts +2 -1
- package/dist/enum/index.js +3 -1
- package/dist/enum/index.js.map +1 -1
- package/dist/interfaces/agreemeent-signature-attr.interface.d.ts +4 -0
- package/dist/models/agreement-signature.entity.d.ts +4 -0
- package/dist/models/agreement-signature.entity.js +22 -0
- package/dist/models/agreement-signature.entity.js.map +1 -1
- package/dist/src/ClassMappings/ItemClassMap.d.ts +4 -0
- package/dist/src/ClassMappings/ItemClassMap.js +8 -0
- package/dist/src/ClassMappings/ItemClassMap.js.map +1 -0
- package/dist/src/ClassMappings/index.d.ts +2 -0
- package/dist/src/ClassMappings/index.js +6 -0
- package/dist/src/ClassMappings/index.js.map +1 -0
- package/dist/src/components/agreement/agreement.js +91 -72
- package/dist/src/components/agreement/agreement.js.map +1 -1
- package/dist/src/components/agreement/agreement.repository.js +50 -35
- package/dist/src/components/agreement/agreement.repository.js.map +1 -1
- package/dist/src/components/agreement-history/agreement-history.js +21 -10
- package/dist/src/components/agreement-history/agreement-history.js.map +1 -1
- package/dist/src/components/agreement-history/agreement-history.repository.js +50 -35
- package/dist/src/components/agreement-history/agreement-history.repository.js.map +1 -1
- package/dist/src/components/agreement-signature/agreement-signature.js +70 -57
- package/dist/src/components/agreement-signature/agreement-signature.js.map +1 -1
- package/dist/src/components/agreement-signature/agreement-signature.repository.js +51 -36
- package/dist/src/components/agreement-signature/agreement-signature.repository.js.map +1 -1
- package/dist/src/components/booking/booking.js +231 -206
- package/dist/src/components/booking/booking.js.map +1 -1
- package/dist/src/components/booking/booking.repository.js +50 -35
- package/dist/src/components/booking/booking.repository.js.map +1 -1
- package/dist/src/components/hirer-change-request-new-hirer/hirer-change-request-new-hirer.js +62 -47
- package/dist/src/components/hirer-change-request-new-hirer/hirer-change-request-new-hirer.js.map +1 -1
- package/dist/src/components/hirer-change-request-new-hirer/hirer-change-request-new-hirer.repository.js +63 -46
- package/dist/src/components/hirer-change-request-new-hirer/hirer-change-request-new-hirer.repository.js.map +1 -1
- package/dist/src/components/hirer-change-request-remove-hirer/hirer-change-request-remove-hirer.js +64 -49
- package/dist/src/components/hirer-change-request-remove-hirer/hirer-change-request-remove-hirer.js.map +1 -1
- package/dist/src/components/hirer-change-request-remove-hirer/hirer-change-request-remove-hirer.repository.js +64 -47
- package/dist/src/components/hirer-change-request-remove-hirer/hirer-change-request-remove-hirer.repository.js.map +1 -1
- package/dist/src/components/hirer-change-request-signature/hirer-change-request-signature.js +167 -150
- package/dist/src/components/hirer-change-request-signature/hirer-change-request-signature.js.map +1 -1
- package/dist/src/components/hirer-change-request-signature/hirer-change-request-signature.repository.js +64 -47
- package/dist/src/components/hirer-change-request-signature/hirer-change-request-signature.repository.js.map +1 -1
- package/dist/src/components/joint-hirer/joint-hirer.d.ts +2 -0
- package/dist/src/components/joint-hirer/joint-hirer.js +133 -81
- package/dist/src/components/joint-hirer/joint-hirer.js.map +1 -1
- package/dist/src/components/joint-hirer/joint-hirer.repository.js +50 -35
- package/dist/src/components/joint-hirer/joint-hirer.repository.js.map +1 -1
- package/dist/src/components/rental/rental.d.ts +12 -3
- package/dist/src/components/rental/rental.js +755 -549
- package/dist/src/components/rental/rental.js.map +1 -1
- package/dist/src/components/rental/rental.repository.js +50 -35
- package/dist/src/components/rental/rental.repository.js.map +1 -1
- package/dist/src/components/rental-hirer-change-request/rental-hirer-change-request.js +456 -416
- package/dist/src/components/rental-hirer-change-request/rental-hirer-change-request.js.map +1 -1
- package/dist/src/components/rental-hirer-change-request/rental-hirer-change-request.repository.js +63 -46
- package/dist/src/components/rental-hirer-change-request/rental-hirer-change-request.repository.js.map +1 -1
- package/dist/src/components/rental-price/rental-price.js +46 -33
- package/dist/src/components/rental-price/rental-price.js.map +1 -1
- package/dist/src/components/rental-price/rental-price.repository.js +50 -35
- package/dist/src/components/rental-price/rental-price.repository.js.map +1 -1
- package/dist/src/enum/agreement-signature-verification-method.enum.d.ts +4 -0
- package/dist/src/enum/agreement-signature-verification-method.enum.js +9 -0
- package/dist/src/enum/agreement-signature-verification-method.enum.js.map +1 -0
- package/dist/src/enum/index.d.ts +2 -1
- package/dist/src/enum/index.js +3 -1
- package/dist/src/enum/index.js.map +1 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +3 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/models/agreement-signature.entity.d.ts +4 -0
- package/dist/src/models/agreement-signature.entity.js +22 -0
- package/dist/src/models/agreement-signature.entity.js.map +1 -1
- package/dist/src/models/hirer-change-request-new-hirer.entity.d.ts +1 -1
- package/dist/src/models/hirer-change-request-remove-hirer.entity.d.ts +1 -1
- package/dist/src/models/hirer-change-request-signature.entity.d.ts +1 -1
- package/dist/src/models/joint-hirer.entity.js +0 -4
- package/dist/src/models/joint-hirer.entity.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/migrations/agreement-signature-table-migration.js +12 -0
- package/package.json +1 -1
- package/src/components/agreement-signature/agreement-signature.ts +12 -0
- package/src/components/rental/rental.ts +7 -1
- package/src/enum/agreement-signature-verification-method.enum.ts +4 -0
- package/src/enum/index.ts +2 -0
- package/src/interfaces/agreemeent-signature-attr.interface.ts +4 -0
- package/src/models/agreement-signature.entity.ts +19 -0
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.RentalHirerChangeRequest = void 0;
|
|
4
13
|
const general_1 = require("@tomei/general");
|
|
@@ -58,470 +67,501 @@ class RentalHirerChangeRequest extends general_1.ObjectBase {
|
|
|
58
67
|
UpdatedById: this.UpdatedById,
|
|
59
68
|
};
|
|
60
69
|
}
|
|
61
|
-
static
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
static init(requestId, dbTransaction) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
try {
|
|
73
|
+
if (requestId) {
|
|
74
|
+
const hirerChangeReq = yield RentalHirerChangeRequest._Repository.findByPk(requestId, dbTransaction);
|
|
75
|
+
if (hirerChangeReq) {
|
|
76
|
+
return new RentalHirerChangeRequest(hirerChangeReq.get({ plain: true }));
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg00', 'HirerChangeRequest not found');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return new RentalHirerChangeRequest();
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
console.error('Error initializing RentalHirerChangeRequest:', error);
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
checkForDuplicate(dbTransaction) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
try {
|
|
93
|
+
if (!this.RentalId) {
|
|
94
|
+
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg08', 'RentalId is required to check for duplicate requests.');
|
|
95
|
+
}
|
|
96
|
+
const isDuplicate = yield RentalHirerChangeRequest._Repository.findAll({
|
|
97
|
+
where: {
|
|
98
|
+
RentalId: this.RentalId,
|
|
99
|
+
Type: this.Type,
|
|
100
|
+
Status: {
|
|
101
|
+
[sequelize_1.Op.notIn]: [
|
|
102
|
+
rental_hirer_change_request_status_1.HirerChangeRequestStatusEnum.COMPLETED,
|
|
103
|
+
rental_hirer_change_request_status_1.HirerChangeRequestStatusEnum.CANCELLED,
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
transaction: dbTransaction,
|
|
108
|
+
});
|
|
109
|
+
if (isDuplicate.length > 0) {
|
|
110
|
+
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg04', 'Duplicate record detected.');
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
getSignatures(dbTransaction) {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
try {
|
|
121
|
+
if (this.Signatures.length > 0) {
|
|
122
|
+
return this.Signatures;
|
|
123
|
+
}
|
|
124
|
+
const hirers = yield RentalHirerChangeRequest._HirerSignatureRepository.findAll({
|
|
125
|
+
where: {
|
|
126
|
+
RequestId: this.RequestId,
|
|
127
|
+
},
|
|
128
|
+
transaction: dbTransaction,
|
|
129
|
+
});
|
|
130
|
+
this.Signatures = yield Promise.all(hirers.map((hirer) => __awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
return yield hirer_change_request_signature_1.HirerChangeRequestSignature.init(hirer.SignatureId, dbTransaction);
|
|
132
|
+
})));
|
|
133
|
+
return this.Signatures;
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
throw error;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
checkIsAllSigned(dbTransaction) {
|
|
141
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
try {
|
|
143
|
+
const listUpdatedHirer = yield this.getSignatures(dbTransaction);
|
|
144
|
+
if (listUpdatedHirer.length > 0) {
|
|
145
|
+
return listUpdatedHirer.every((record) => record.SignedAt !== null);
|
|
67
146
|
}
|
|
68
147
|
else {
|
|
69
|
-
|
|
148
|
+
return false;
|
|
70
149
|
}
|
|
71
150
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
throw error;
|
|
77
|
-
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
78
155
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
156
|
+
create(loginUser, dbTransaction) {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
+
try {
|
|
159
|
+
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
160
|
+
const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'HIRER_CHANGE_REQUEST');
|
|
161
|
+
if (!isPrivileged) {
|
|
162
|
+
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg01', "You do not have 'HIRER_CHANGE_REQUEST' privilege.");
|
|
163
|
+
}
|
|
164
|
+
if (!this.RentalId || !this.RequestingHirerId) {
|
|
165
|
+
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg02', 'RentalId and RequestingHirerId are required.');
|
|
166
|
+
}
|
|
167
|
+
const rental = yield rental_1.Rental.init(dbTransaction, this.RentalId);
|
|
168
|
+
rental.AccountType = enum_1.RentalAccountTypeEnum.JOINT;
|
|
169
|
+
const jointHirers = yield rental.getJointHirers(dbTransaction);
|
|
170
|
+
if (this.Type === rental_hirer_change_request_type_1.HirerChangeRequestTypeEnum.ADD) {
|
|
171
|
+
const maxJointHirer = config_1.ComponentConfig.getComponentConfigValue('@tomei/rental', 'maxJointHirerLength');
|
|
172
|
+
if ((jointHirers === null || jointHirers === void 0 ? void 0 : jointHirers.length) >= maxJointHirer) {
|
|
173
|
+
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg05', 'Joint Hirer exceed max joint hirer length.');
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
yield this.checkForDuplicate(dbTransaction);
|
|
177
|
+
this.ObjectId = this.createId();
|
|
178
|
+
this.RequestedById = loginUser.ObjectId;
|
|
179
|
+
this.RequestedAt = new Date();
|
|
180
|
+
this.UpdatedById = loginUser.ObjectId;
|
|
181
|
+
this.UpdatedAt = new Date();
|
|
182
|
+
this.Status = rental_hirer_change_request_status_1.HirerChangeRequestStatusEnum.PENDINGSIGNATURES;
|
|
183
|
+
this.RequestingHirerType =
|
|
184
|
+
rental.CustomerId === this.RequestingHirerId
|
|
185
|
+
? enum_1.HirerChangeRequestHirerRoleEnum.MAIN
|
|
186
|
+
: enum_1.HirerChangeRequestHirerRoleEnum.JOINT;
|
|
187
|
+
const entityValueAfter = {
|
|
188
|
+
RequestId: this.RequestId,
|
|
189
|
+
RentalId: this.RentalId,
|
|
190
|
+
Type: this.Type,
|
|
191
|
+
Status: this.Status,
|
|
192
|
+
RequestedById: this.RequestedById,
|
|
193
|
+
RequestedAt: this.RequestedAt,
|
|
194
|
+
RequestingHirerId: this.RequestingHirerId,
|
|
195
|
+
RequestingHirerType: this.RequestingHirerType,
|
|
196
|
+
CancelRemarks: this.CancelRemarks,
|
|
197
|
+
UpdatedById: this.UpdatedById,
|
|
198
|
+
UpdatedAt: this.UpdatedAt,
|
|
199
|
+
};
|
|
200
|
+
yield RentalHirerChangeRequest._Repository.create(entityValueAfter, {
|
|
201
|
+
transaction: dbTransaction,
|
|
202
|
+
});
|
|
203
|
+
yield this.generateSignatures(loginUser, dbTransaction);
|
|
204
|
+
const activity = new activity_history_1.Activity();
|
|
205
|
+
activity.ObjectId = this._createId();
|
|
206
|
+
activity.Action = activity_history_1.ActionEnum.CREATE;
|
|
207
|
+
activity.Description =
|
|
208
|
+
this.Type === rental_hirer_change_request_type_1.HirerChangeRequestTypeEnum.ADD
|
|
209
|
+
? 'Add New Hirer'
|
|
210
|
+
: 'Remove Hirer';
|
|
211
|
+
activity.EntityId = this.ObjectId;
|
|
212
|
+
activity.EntityType = this.ObjectType;
|
|
213
|
+
activity.EntityValueBefore = JSON.stringify({});
|
|
214
|
+
activity.EntityValueAfter = JSON.stringify(entityValueAfter);
|
|
215
|
+
yield activity.create(loginUser.ObjectId, dbTransaction);
|
|
216
|
+
return this;
|
|
83
217
|
}
|
|
84
|
-
|
|
85
|
-
|
|
218
|
+
catch (error) {
|
|
219
|
+
throw error;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
update(loginUser, dbTransaction, params) {
|
|
224
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
225
|
+
try {
|
|
226
|
+
if (!this.RequestId) {
|
|
227
|
+
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg06', 'RequestId are required.');
|
|
228
|
+
}
|
|
229
|
+
const entityValueBefore = {
|
|
230
|
+
RequestId: this.RequestId,
|
|
231
|
+
RentalId: this.RentalId,
|
|
232
|
+
Type: this.Type,
|
|
233
|
+
Status: this.Status,
|
|
234
|
+
RequestedById: this.RequestedById,
|
|
235
|
+
RequestedAt: this.RequestedAt,
|
|
236
|
+
RequestingHirerId: this.RequestingHirerId,
|
|
237
|
+
RequestingHirerType: this.RequestingHirerType,
|
|
238
|
+
CancelRemarks: this.CancelRemarks,
|
|
239
|
+
UpdatedById: this.UpdatedById,
|
|
240
|
+
UpdatedAt: this.UpdatedAt,
|
|
241
|
+
};
|
|
242
|
+
let { jointHirerId, customerId } = params;
|
|
243
|
+
if (!customerId && !jointHirerId) {
|
|
244
|
+
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg07', 'At least one of customerId or jointHirerId must be provided.');
|
|
245
|
+
}
|
|
246
|
+
const listHirer = yield this.getSignatures(dbTransaction);
|
|
247
|
+
if ((listHirer === null || listHirer === void 0 ? void 0 : listHirer.length) > 0) {
|
|
248
|
+
let foundHirer = listHirer === null || listHirer === void 0 ? void 0 : listHirer.find((record) => {
|
|
249
|
+
record.CustomerId === customerId;
|
|
250
|
+
});
|
|
251
|
+
let hirer = yield hirer_change_request_signature_1.HirerChangeRequestSignature.init(foundHirer.SignatureId, dbTransaction);
|
|
252
|
+
yield hirer.update(loginUser, dbTransaction);
|
|
253
|
+
}
|
|
254
|
+
const isSigned = yield this.checkIsAllSigned(dbTransaction);
|
|
255
|
+
if (isSigned) {
|
|
256
|
+
if (this.Type === rental_hirer_change_request_type_1.HirerChangeRequestTypeEnum.ADD) {
|
|
257
|
+
this.Status = rental_hirer_change_request_status_1.HirerChangeRequestStatusEnum.AWAITINGNEWHIRER;
|
|
258
|
+
}
|
|
259
|
+
else if (this.Type === rental_hirer_change_request_type_1.HirerChangeRequestTypeEnum.REMOVE) {
|
|
260
|
+
yield RentalHirerChangeRequest._JointHirerRepository.update({ Status: 'Inactive' }, {
|
|
261
|
+
where: {
|
|
262
|
+
HirerId: this.RequestId,
|
|
263
|
+
},
|
|
264
|
+
transaction: dbTransaction,
|
|
265
|
+
});
|
|
266
|
+
this.Status = rental_hirer_change_request_status_1.HirerChangeRequestStatusEnum.COMPLETED;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
const entityValueAfter = {
|
|
270
|
+
RequestId: this.RequestId,
|
|
86
271
|
RentalId: this.RentalId,
|
|
87
272
|
Type: this.Type,
|
|
88
|
-
Status:
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
273
|
+
Status: this.Status,
|
|
274
|
+
RequestedById: this.RequestedById,
|
|
275
|
+
RequestedAt: this.RequestedAt,
|
|
276
|
+
RequestingHirerId: this.RequestingHirerId,
|
|
277
|
+
RequestingHirerType: this.RequestingHirerType,
|
|
278
|
+
CancelRemarks: this.CancelRemarks,
|
|
279
|
+
UpdatedById: this.UpdatedById,
|
|
280
|
+
UpdatedAt: this.UpdatedAt,
|
|
281
|
+
};
|
|
282
|
+
yield RentalHirerChangeRequest._Repository.update(entityValueAfter, {
|
|
283
|
+
where: {
|
|
284
|
+
RequestId: this.RequestId,
|
|
93
285
|
},
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
286
|
+
transaction: dbTransaction,
|
|
287
|
+
});
|
|
288
|
+
const activity = new activity_history_1.Activity();
|
|
289
|
+
activity.ObjectId = this._createId();
|
|
290
|
+
activity.Action = activity_history_1.ActionEnum.UPDATE;
|
|
291
|
+
activity.Description = 'Update Hirer Change Request';
|
|
292
|
+
activity.EntityId = this.ObjectId;
|
|
293
|
+
activity.EntityType = this.ObjectType;
|
|
294
|
+
activity.EntityValueBefore = JSON.stringify(entityValueBefore);
|
|
295
|
+
activity.EntityValueAfter = JSON.stringify(entityValueAfter);
|
|
296
|
+
yield activity.create(loginUser.ObjectId, dbTransaction);
|
|
297
|
+
return this;
|
|
99
298
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
throw error;
|
|
301
|
+
}
|
|
302
|
+
});
|
|
104
303
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
304
|
+
generateSignatures(loginUser, dbTransaction) {
|
|
305
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
306
|
+
try {
|
|
307
|
+
if (!this.RentalId) {
|
|
308
|
+
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg09', 'RentalId is required to create signatures.');
|
|
309
|
+
}
|
|
310
|
+
if (!this.Rental) {
|
|
311
|
+
this.Rental = yield rental_1.Rental.init(dbTransaction, this.RentalId);
|
|
312
|
+
}
|
|
313
|
+
this.Rental.AccountType = enum_1.RentalAccountTypeEnum.JOINT;
|
|
314
|
+
const jointHirers = yield this.Rental.getJointHirers(dbTransaction);
|
|
315
|
+
const mainSignature = yield hirer_change_request_signature_1.HirerChangeRequestSignature.init();
|
|
316
|
+
mainSignature.RequestId = this.RequestId;
|
|
317
|
+
mainSignature.CustomerId = this.Rental.CustomerId;
|
|
318
|
+
mainSignature.HirerType = enum_1.HirerChangeRequestHirerRoleEnum.MAIN;
|
|
319
|
+
mainSignature.Method = 'Upload';
|
|
320
|
+
let jointSignatures = [];
|
|
321
|
+
if (jointHirers.length > 0) {
|
|
322
|
+
const jointSignaturePromises = jointHirers.map((jointHirer) => __awaiter(this, void 0, void 0, function* () {
|
|
323
|
+
const signature = yield hirer_change_request_signature_1.HirerChangeRequestSignature.init();
|
|
324
|
+
signature.RequestId = this.RequestId;
|
|
325
|
+
signature.JointHirerId = jointHirer.HirerId;
|
|
326
|
+
signature.HirerType = enum_1.HirerChangeRequestHirerRoleEnum.JOINT;
|
|
327
|
+
signature.Method = 'Upload';
|
|
328
|
+
return signature;
|
|
329
|
+
}));
|
|
330
|
+
jointSignatures = yield Promise.all(jointSignaturePromises);
|
|
331
|
+
}
|
|
332
|
+
const signaturesToCreate = [
|
|
333
|
+
mainSignature.create(loginUser, dbTransaction),
|
|
334
|
+
];
|
|
335
|
+
if (jointSignatures.length > 0) {
|
|
336
|
+
signaturesToCreate.push(...jointSignatures.map((sig) => sig.create(loginUser, dbTransaction)));
|
|
337
|
+
}
|
|
338
|
+
yield Promise.all(signaturesToCreate);
|
|
339
|
+
this.Signatures = [mainSignature, ...jointSignatures];
|
|
340
|
+
}
|
|
341
|
+
catch (error) {
|
|
342
|
+
console.error('Error creating signatures:', error);
|
|
343
|
+
throw error;
|
|
109
344
|
}
|
|
110
|
-
|
|
111
|
-
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
createAddRequest(newHirer, loginUser, dbTransaction) {
|
|
348
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
349
|
+
try {
|
|
350
|
+
if (!newHirer.FullName ||
|
|
351
|
+
!newHirer.IdNo ||
|
|
352
|
+
!newHirer.IdType ||
|
|
353
|
+
!newHirer.ContactNo ||
|
|
354
|
+
!newHirer.Address ||
|
|
355
|
+
!newHirer.City ||
|
|
356
|
+
!newHirer.State ||
|
|
357
|
+
!newHirer.Postcode ||
|
|
358
|
+
!newHirer.Country) {
|
|
359
|
+
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg10', 'FullName, IdNo, IdType, ContactNo, and Address are required.');
|
|
360
|
+
}
|
|
361
|
+
this.Type = rental_hirer_change_request_type_1.HirerChangeRequestTypeEnum.ADD;
|
|
362
|
+
yield this.create(loginUser, dbTransaction);
|
|
363
|
+
const nh = yield hirer_change_request_new_hirer_1.HirerChangeRequestNewHirer.init();
|
|
364
|
+
nh.RequestId = this.RequestId;
|
|
365
|
+
nh.FullName = newHirer.FullName;
|
|
366
|
+
nh.Email = newHirer.Email;
|
|
367
|
+
nh.IdType = newHirer.IdType;
|
|
368
|
+
nh.IdNo = newHirer.IdNo;
|
|
369
|
+
nh.ContactNo = newHirer.ContactNo;
|
|
370
|
+
nh.Relationship = newHirer.Relationship;
|
|
371
|
+
nh.Address = newHirer.Address;
|
|
372
|
+
nh.City = newHirer.City;
|
|
373
|
+
nh.State = newHirer.State;
|
|
374
|
+
nh.Postcode = newHirer.Postcode;
|
|
375
|
+
nh.Country = newHirer.Country;
|
|
376
|
+
yield nh.create(loginUser, dbTransaction);
|
|
377
|
+
return {
|
|
378
|
+
hirerChangeRequest: this,
|
|
379
|
+
NewHirer: nh,
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
catch (error) {
|
|
383
|
+
console.error('Error creating add request:', error);
|
|
384
|
+
throw error;
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
createRemoveRequest(loginUser, dbTransaction, targetHirerId) {
|
|
389
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
390
|
+
try {
|
|
391
|
+
yield joint_hirer_1.JointHirer.init(targetHirerId, dbTransaction);
|
|
392
|
+
this.Type = rental_hirer_change_request_type_1.HirerChangeRequestTypeEnum.REMOVE;
|
|
393
|
+
yield this.create(loginUser, dbTransaction);
|
|
394
|
+
const removeHirer = yield hirer_change_request_remove_hirer_1.HirerChangeRequestRemoveHirer.init();
|
|
395
|
+
removeHirer.RequestId = this.RequestId;
|
|
396
|
+
removeHirer.TargetHirerId = targetHirerId;
|
|
397
|
+
yield removeHirer.create(loginUser, dbTransaction);
|
|
398
|
+
return {
|
|
399
|
+
hirerChangeRequest: this,
|
|
400
|
+
RemoveHirer: removeHirer,
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
catch (error) {
|
|
404
|
+
console.error('Error creating remove request:', error);
|
|
405
|
+
throw error;
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
static findAll(loginUser, dbTransaction, rentalId) {
|
|
410
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
411
|
+
try {
|
|
412
|
+
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
413
|
+
const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'HIRER_CHANGE_REQUEST');
|
|
414
|
+
if (!isPrivileged) {
|
|
415
|
+
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg01', "You do not have 'HIRER_CHANGE_REQUEST' privilege.");
|
|
416
|
+
}
|
|
417
|
+
if (!rentalId) {
|
|
418
|
+
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg12', 'rentalId is required.');
|
|
419
|
+
}
|
|
420
|
+
yield rental_1.Rental.init(dbTransaction, rentalId);
|
|
421
|
+
const records = yield RentalHirerChangeRequest._Repository.findAll({
|
|
422
|
+
where: { RentalId: rentalId },
|
|
423
|
+
transaction: dbTransaction,
|
|
424
|
+
});
|
|
425
|
+
const result = (records || []).map((rec) => new RentalHirerChangeRequest(rec.get({ plain: true })));
|
|
426
|
+
return result;
|
|
427
|
+
}
|
|
428
|
+
catch (error) {
|
|
429
|
+
console.error('Error finding all RentalHirerChangeRequest:', error);
|
|
430
|
+
throw error;
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
getNewHirer(dbTransaction) {
|
|
435
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
436
|
+
try {
|
|
437
|
+
if (!this.RequestId) {
|
|
438
|
+
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg13', 'RequestId is required to get new hirer.');
|
|
439
|
+
}
|
|
440
|
+
const newHirerRecords = yield hirer_change_request_new_hirer_1.HirerChangeRequestNewHirer.findAll({
|
|
112
441
|
RequestId: this.RequestId,
|
|
113
|
-
},
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
throw error;
|
|
123
|
-
}
|
|
442
|
+
}, dbTransaction);
|
|
443
|
+
return newHirerRecords[0] || null;
|
|
444
|
+
}
|
|
445
|
+
catch (error) {
|
|
446
|
+
console.error('Error getting new hirer:', error);
|
|
447
|
+
throw error;
|
|
448
|
+
}
|
|
449
|
+
});
|
|
124
450
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
451
|
+
getRemoveHirer(dbTransaction) {
|
|
452
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
453
|
+
try {
|
|
454
|
+
if (!this.RequestId) {
|
|
455
|
+
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg13', 'RequestId is required to get remove hirer.');
|
|
456
|
+
}
|
|
457
|
+
const removeHirerRecords = yield hirer_change_request_remove_hirer_1.HirerChangeRequestRemoveHirer.findAll({
|
|
458
|
+
RequestId: this.RequestId,
|
|
459
|
+
}, dbTransaction);
|
|
460
|
+
return removeHirerRecords[0] || null;
|
|
130
461
|
}
|
|
131
|
-
|
|
132
|
-
|
|
462
|
+
catch (error) {
|
|
463
|
+
console.error('Error getting remove hirer:', error);
|
|
464
|
+
throw error;
|
|
133
465
|
}
|
|
134
|
-
}
|
|
135
|
-
catch (error) {
|
|
136
|
-
throw error;
|
|
137
|
-
}
|
|
466
|
+
});
|
|
138
467
|
}
|
|
139
|
-
|
|
140
|
-
|
|
468
|
+
sign(loginUser, dbTransaction, signatureId) {
|
|
469
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
470
|
+
try {
|
|
471
|
+
if (!this.RequestId) {
|
|
472
|
+
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg13', 'RequestId is required to sign signature.');
|
|
473
|
+
}
|
|
474
|
+
const hcrSignature = yield hirer_change_request_signature_1.HirerChangeRequestSignature.init(signatureId, dbTransaction);
|
|
475
|
+
yield hcrSignature.markSigned(loginUser, dbTransaction);
|
|
476
|
+
return hcrSignature;
|
|
477
|
+
}
|
|
478
|
+
catch (error) {
|
|
479
|
+
throw error;
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
complete(loginUser, dbTransaction, customerId, customerType) {
|
|
484
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
141
485
|
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
142
|
-
const isPrivileged =
|
|
486
|
+
const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'HIRER_CHANGE_REQUEST');
|
|
143
487
|
if (!isPrivileged) {
|
|
144
488
|
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg01', "You do not have 'HIRER_CHANGE_REQUEST' privilege.");
|
|
145
489
|
}
|
|
146
|
-
if (!this.
|
|
147
|
-
throw new general_1.ClassError('HirerChangeRequest', '
|
|
490
|
+
if (!this.RequestId) {
|
|
491
|
+
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg06', 'RequestId is required.');
|
|
148
492
|
}
|
|
149
|
-
const
|
|
150
|
-
if (
|
|
151
|
-
throw new general_1.ClassError('HirerChangeRequest', '
|
|
493
|
+
const signatures = yield this.getSignatures(dbTransaction);
|
|
494
|
+
if (!signatures.length || !signatures.every((sig) => sig.SignedAt)) {
|
|
495
|
+
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg14', 'All signatures must be signed before completing the request.');
|
|
152
496
|
}
|
|
153
|
-
const jointHirers = await rental.getJointHirers(dbTransaction);
|
|
154
497
|
if (this.Type === rental_hirer_change_request_type_1.HirerChangeRequestTypeEnum.ADD) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg05', 'Joint Hirer exceed max joint hirer length.');
|
|
498
|
+
if (!customerId || !customerType) {
|
|
499
|
+
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg15', 'CustomerId and CustomerType are required for new hirer.');
|
|
158
500
|
}
|
|
501
|
+
const jointHirer = yield joint_hirer_1.JointHirer.init();
|
|
502
|
+
jointHirer.RentalId = this.RentalId;
|
|
503
|
+
jointHirer.CustomerId = customerId;
|
|
504
|
+
jointHirer.CustomerType = customerType;
|
|
505
|
+
yield jointHirer.create(loginUser, dbTransaction);
|
|
159
506
|
}
|
|
160
|
-
if (this.Type
|
|
161
|
-
|
|
162
|
-
|
|
507
|
+
else if (this.Type === rental_hirer_change_request_type_1.HirerChangeRequestTypeEnum.REMOVE) {
|
|
508
|
+
const removeHirer = yield this.getRemoveHirer(dbTransaction);
|
|
509
|
+
const jointHirer = yield joint_hirer_1.JointHirer.init(removeHirer.TargetHirerId, dbTransaction);
|
|
510
|
+
yield jointHirer.remove(loginUser, dbTransaction);
|
|
163
511
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
this.
|
|
167
|
-
this.RequestedAt = new Date();
|
|
168
|
-
this.UpdatedById = loginUser.ObjectId;
|
|
512
|
+
const now = new Date();
|
|
513
|
+
const entityValueBefore = this.toJSON();
|
|
514
|
+
this.Status = rental_hirer_change_request_status_1.HirerChangeRequestStatusEnum.COMPLETED;
|
|
169
515
|
this.UpdatedAt = new Date();
|
|
170
|
-
this.
|
|
171
|
-
this.
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
: enum_1.HirerChangeRequestHirerRoleEnum.JOINT;
|
|
175
|
-
const entityValueAfter = {
|
|
176
|
-
RequestId: this.RequestId,
|
|
177
|
-
RentalId: this.RentalId,
|
|
178
|
-
Type: this.Type,
|
|
179
|
-
Status: this.Status,
|
|
180
|
-
RequestedById: this.RequestedById,
|
|
181
|
-
RequestedAt: this.RequestedAt,
|
|
182
|
-
RequestingHirerId: this.RequestingHirerId,
|
|
183
|
-
RequestingHirerType: this.RequestingHirerType,
|
|
184
|
-
CancelRemarks: this.CancelRemarks,
|
|
185
|
-
UpdatedById: this.UpdatedById,
|
|
186
|
-
UpdatedAt: this.UpdatedAt,
|
|
187
|
-
};
|
|
188
|
-
await RentalHirerChangeRequest._Repository.create(entityValueAfter, {
|
|
516
|
+
this.UpdatedById = loginUser.ObjectId;
|
|
517
|
+
const entityValueAfter = this.toJSON();
|
|
518
|
+
yield RentalHirerChangeRequest._Repository.update(entityValueAfter, {
|
|
519
|
+
where: { RequestId: this.RequestId },
|
|
189
520
|
transaction: dbTransaction,
|
|
190
521
|
});
|
|
191
|
-
await this.generateSignatures(loginUser, dbTransaction);
|
|
192
522
|
const activity = new activity_history_1.Activity();
|
|
193
523
|
activity.ObjectId = this._createId();
|
|
194
|
-
activity.Action = activity_history_1.ActionEnum.
|
|
195
|
-
activity.Description =
|
|
196
|
-
|
|
197
|
-
? 'Add New Hirer'
|
|
198
|
-
: 'Remove Hirer';
|
|
199
|
-
activity.EntityId = this.ObjectId;
|
|
524
|
+
activity.Action = activity_history_1.ActionEnum.UPDATE;
|
|
525
|
+
activity.Description = `Mark request as completed.`;
|
|
526
|
+
activity.EntityId = this.RequestId;
|
|
200
527
|
activity.EntityType = this.ObjectType;
|
|
201
|
-
activity.EntityValueBefore = JSON.stringify(
|
|
528
|
+
activity.EntityValueBefore = JSON.stringify(entityValueBefore);
|
|
202
529
|
activity.EntityValueAfter = JSON.stringify(entityValueAfter);
|
|
203
|
-
|
|
530
|
+
yield activity.create(loginUser.ObjectId, dbTransaction);
|
|
204
531
|
return this;
|
|
205
|
-
}
|
|
206
|
-
catch (error) {
|
|
207
|
-
throw error;
|
|
208
|
-
}
|
|
532
|
+
});
|
|
209
533
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
RequestId: this.RequestId,
|
|
217
|
-
RentalId: this.RentalId,
|
|
218
|
-
Type: this.Type,
|
|
219
|
-
Status: this.Status,
|
|
220
|
-
RequestedById: this.RequestedById,
|
|
221
|
-
RequestedAt: this.RequestedAt,
|
|
222
|
-
RequestingHirerId: this.RequestingHirerId,
|
|
223
|
-
RequestingHirerType: this.RequestingHirerType,
|
|
224
|
-
CancelRemarks: this.CancelRemarks,
|
|
225
|
-
UpdatedById: this.UpdatedById,
|
|
226
|
-
UpdatedAt: this.UpdatedAt,
|
|
227
|
-
};
|
|
228
|
-
let { jointHirerId, customerId } = params;
|
|
229
|
-
if (!customerId && !jointHirerId) {
|
|
230
|
-
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg07', 'At least one of customerId or jointHirerId must be provided.');
|
|
231
|
-
}
|
|
232
|
-
const listHirer = await this.getSignatures(dbTransaction);
|
|
233
|
-
if ((listHirer === null || listHirer === void 0 ? void 0 : listHirer.length) > 0) {
|
|
234
|
-
let foundHirer = listHirer === null || listHirer === void 0 ? void 0 : listHirer.find((record) => {
|
|
235
|
-
record.CustomerId === customerId;
|
|
236
|
-
});
|
|
237
|
-
let hirer = await hirer_change_request_signature_1.HirerChangeRequestSignature.init(foundHirer.SignatureId, dbTransaction);
|
|
238
|
-
await hirer.update(loginUser, dbTransaction);
|
|
534
|
+
cancel(loginUser, dbTransaction, cancelRemarks) {
|
|
535
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
536
|
+
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
537
|
+
const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'HIRER_CHANGE_REQUEST');
|
|
538
|
+
if (!isPrivileged) {
|
|
539
|
+
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg01', "You do not have 'HIRER_CHANGE_REQUEST' privilege.");
|
|
239
540
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
if (this.Type === rental_hirer_change_request_type_1.HirerChangeRequestTypeEnum.ADD) {
|
|
243
|
-
this.Status = rental_hirer_change_request_status_1.HirerChangeRequestStatusEnum.AWAITINGNEWHIRER;
|
|
244
|
-
}
|
|
245
|
-
else if (this.Type === rental_hirer_change_request_type_1.HirerChangeRequestTypeEnum.REMOVE) {
|
|
246
|
-
await RentalHirerChangeRequest._JointHirerRepository.update({ Status: 'Inactive' }, {
|
|
247
|
-
where: {
|
|
248
|
-
HirerId: this.RequestId,
|
|
249
|
-
},
|
|
250
|
-
transaction: dbTransaction,
|
|
251
|
-
});
|
|
252
|
-
this.Status = rental_hirer_change_request_status_1.HirerChangeRequestStatusEnum.COMPLETED;
|
|
253
|
-
}
|
|
541
|
+
if (!this.RequestId) {
|
|
542
|
+
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg06', 'RequestId is required.');
|
|
254
543
|
}
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
RequestingHirerType: this.RequestingHirerType,
|
|
264
|
-
CancelRemarks: this.CancelRemarks,
|
|
265
|
-
UpdatedById: this.UpdatedById,
|
|
266
|
-
UpdatedAt: this.UpdatedAt,
|
|
267
|
-
};
|
|
268
|
-
await RentalHirerChangeRequest._Repository.update(entityValueAfter, {
|
|
269
|
-
where: {
|
|
270
|
-
RequestId: this.RequestId,
|
|
271
|
-
},
|
|
544
|
+
const entityValueBefore = this.toJSON();
|
|
545
|
+
this.Status = rental_hirer_change_request_status_1.HirerChangeRequestStatusEnum.CANCELLED;
|
|
546
|
+
this.CancelRemarks = cancelRemarks;
|
|
547
|
+
this.UpdatedAt = new Date();
|
|
548
|
+
this.UpdatedById = loginUser.ObjectId;
|
|
549
|
+
const entityValueAfter = this.toJSON();
|
|
550
|
+
yield RentalHirerChangeRequest._Repository.update(entityValueAfter, {
|
|
551
|
+
where: { RequestId: this.RequestId },
|
|
272
552
|
transaction: dbTransaction,
|
|
273
553
|
});
|
|
274
554
|
const activity = new activity_history_1.Activity();
|
|
275
555
|
activity.ObjectId = this._createId();
|
|
276
556
|
activity.Action = activity_history_1.ActionEnum.UPDATE;
|
|
277
|
-
activity.Description =
|
|
278
|
-
activity.EntityId = this.
|
|
557
|
+
activity.Description = `Cancel hirer change request.`;
|
|
558
|
+
activity.EntityId = this.RequestId;
|
|
279
559
|
activity.EntityType = this.ObjectType;
|
|
280
560
|
activity.EntityValueBefore = JSON.stringify(entityValueBefore);
|
|
281
561
|
activity.EntityValueAfter = JSON.stringify(entityValueAfter);
|
|
282
|
-
|
|
562
|
+
yield activity.create(loginUser.ObjectId, dbTransaction);
|
|
283
563
|
return this;
|
|
284
|
-
}
|
|
285
|
-
catch (error) {
|
|
286
|
-
throw error;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
async generateSignatures(loginUser, dbTransaction) {
|
|
290
|
-
try {
|
|
291
|
-
if (!this.RentalId) {
|
|
292
|
-
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg09', 'RentalId is required to create signatures.');
|
|
293
|
-
}
|
|
294
|
-
if (!this.Rental) {
|
|
295
|
-
this.Rental = await rental_1.Rental.init(dbTransaction, this.RentalId);
|
|
296
|
-
}
|
|
297
|
-
const jointHirers = await this.Rental.getJointHirers(dbTransaction);
|
|
298
|
-
const mainSignature = await hirer_change_request_signature_1.HirerChangeRequestSignature.init();
|
|
299
|
-
mainSignature.RequestId = this.RequestId;
|
|
300
|
-
mainSignature.CustomerId = this.Rental.CustomerId;
|
|
301
|
-
mainSignature.HirerType = enum_1.HirerChangeRequestHirerRoleEnum.MAIN;
|
|
302
|
-
mainSignature.Method = 'Upload';
|
|
303
|
-
const jointSignaturePromises = jointHirers.map(async (jointHirer) => {
|
|
304
|
-
const signature = await hirer_change_request_signature_1.HirerChangeRequestSignature.init();
|
|
305
|
-
signature.RequestId = this.RequestId;
|
|
306
|
-
signature.JointHirerId = jointHirer.HirerId;
|
|
307
|
-
signature.HirerType = enum_1.HirerChangeRequestHirerRoleEnum.JOINT;
|
|
308
|
-
signature.Method = 'Upload';
|
|
309
|
-
return signature;
|
|
310
|
-
});
|
|
311
|
-
const jointSignatures = await Promise.all(jointSignaturePromises);
|
|
312
|
-
await Promise.all([
|
|
313
|
-
mainSignature.create(loginUser, dbTransaction),
|
|
314
|
-
...jointSignatures.map((sig) => sig.create(loginUser, dbTransaction)),
|
|
315
|
-
]);
|
|
316
|
-
this.Signatures = [mainSignature, ...jointSignatures];
|
|
317
|
-
}
|
|
318
|
-
catch (error) {
|
|
319
|
-
console.error('Error creating signatures:', error);
|
|
320
|
-
throw error;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
async createAddRequest(newHirer, loginUser, dbTransaction) {
|
|
324
|
-
try {
|
|
325
|
-
if (!newHirer.FullName ||
|
|
326
|
-
!newHirer.IdNo ||
|
|
327
|
-
!newHirer.IdType ||
|
|
328
|
-
!newHirer.ContactNo ||
|
|
329
|
-
!newHirer.Address ||
|
|
330
|
-
!newHirer.City ||
|
|
331
|
-
!newHirer.State ||
|
|
332
|
-
!newHirer.Postcode ||
|
|
333
|
-
!newHirer.Country) {
|
|
334
|
-
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg10', 'FullName, IdNo, IdType, ContactNo, and Address are required.');
|
|
335
|
-
}
|
|
336
|
-
this.Type = rental_hirer_change_request_type_1.HirerChangeRequestTypeEnum.ADD;
|
|
337
|
-
await this.create(loginUser, dbTransaction);
|
|
338
|
-
const nh = await hirer_change_request_new_hirer_1.HirerChangeRequestNewHirer.init();
|
|
339
|
-
nh.RequestId = this.RequestId;
|
|
340
|
-
nh.FullName = newHirer.FullName;
|
|
341
|
-
nh.Email = newHirer.Email;
|
|
342
|
-
nh.IdType = newHirer.IdType;
|
|
343
|
-
nh.IdNo = newHirer.IdNo;
|
|
344
|
-
nh.ContactNo = newHirer.ContactNo;
|
|
345
|
-
nh.Relationship = newHirer.Relationship;
|
|
346
|
-
nh.Address = newHirer.Address;
|
|
347
|
-
nh.City = newHirer.City;
|
|
348
|
-
nh.State = newHirer.State;
|
|
349
|
-
nh.Postcode = newHirer.Postcode;
|
|
350
|
-
nh.Country = newHirer.Country;
|
|
351
|
-
await nh.create(loginUser, dbTransaction);
|
|
352
|
-
return {
|
|
353
|
-
hirerChangeRequest: this,
|
|
354
|
-
NewHirer: nh,
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
catch (error) {
|
|
358
|
-
console.error('Error creating add request:', error);
|
|
359
|
-
throw error;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
async createRemoveRequest(loginUser, dbTransaction, targetHirerId) {
|
|
363
|
-
try {
|
|
364
|
-
await joint_hirer_1.JointHirer.init(targetHirerId, dbTransaction);
|
|
365
|
-
this.Type = rental_hirer_change_request_type_1.HirerChangeRequestTypeEnum.REMOVE;
|
|
366
|
-
await this.create(loginUser, dbTransaction);
|
|
367
|
-
const removeHirer = await hirer_change_request_remove_hirer_1.HirerChangeRequestRemoveHirer.init();
|
|
368
|
-
removeHirer.RequestId = this.RequestId;
|
|
369
|
-
removeHirer.TargetHirerId = targetHirerId;
|
|
370
|
-
await removeHirer.create(loginUser, dbTransaction);
|
|
371
|
-
return {
|
|
372
|
-
hirerChangeRequest: this,
|
|
373
|
-
RemoveHirer: removeHirer,
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
catch (error) {
|
|
377
|
-
console.error('Error creating remove request:', error);
|
|
378
|
-
throw error;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
static async findAll(loginUser, dbTransaction, rentalId) {
|
|
382
|
-
try {
|
|
383
|
-
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
384
|
-
const isPrivileged = await loginUser.checkPrivileges(systemCode, 'HIRER_CHANGE_REQUEST');
|
|
385
|
-
if (!isPrivileged) {
|
|
386
|
-
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg01', "You do not have 'HIRER_CHANGE_REQUEST' privilege.");
|
|
387
|
-
}
|
|
388
|
-
if (!rentalId) {
|
|
389
|
-
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg12', 'rentalId is required.');
|
|
390
|
-
}
|
|
391
|
-
await rental_1.Rental.init(dbTransaction, rentalId);
|
|
392
|
-
const records = await RentalHirerChangeRequest._Repository.findAll({
|
|
393
|
-
where: { RentalId: rentalId },
|
|
394
|
-
transaction: dbTransaction,
|
|
395
|
-
});
|
|
396
|
-
const result = (records || []).map((rec) => new RentalHirerChangeRequest(rec.get({ plain: true })));
|
|
397
|
-
return result;
|
|
398
|
-
}
|
|
399
|
-
catch (error) {
|
|
400
|
-
console.error('Error finding all RentalHirerChangeRequest:', error);
|
|
401
|
-
throw error;
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
async getNewHirer(dbTransaction) {
|
|
405
|
-
try {
|
|
406
|
-
if (!this.RequestId) {
|
|
407
|
-
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg13', 'RequestId is required to get new hirer.');
|
|
408
|
-
}
|
|
409
|
-
const newHirerRecords = await hirer_change_request_new_hirer_1.HirerChangeRequestNewHirer.findAll({
|
|
410
|
-
RequestId: this.RequestId,
|
|
411
|
-
}, dbTransaction);
|
|
412
|
-
return newHirerRecords[0] || null;
|
|
413
|
-
}
|
|
414
|
-
catch (error) {
|
|
415
|
-
console.error('Error getting new hirer:', error);
|
|
416
|
-
throw error;
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
async getRemoveHirer(dbTransaction) {
|
|
420
|
-
try {
|
|
421
|
-
if (!this.RequestId) {
|
|
422
|
-
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg13', 'RequestId is required to get remove hirer.');
|
|
423
|
-
}
|
|
424
|
-
const removeHirerRecords = await hirer_change_request_remove_hirer_1.HirerChangeRequestRemoveHirer.findAll({
|
|
425
|
-
RequestId: this.RequestId,
|
|
426
|
-
}, dbTransaction);
|
|
427
|
-
return removeHirerRecords[0] || null;
|
|
428
|
-
}
|
|
429
|
-
catch (error) {
|
|
430
|
-
console.error('Error getting remove hirer:', error);
|
|
431
|
-
throw error;
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
async sign(loginUser, dbTransaction, signatureId) {
|
|
435
|
-
try {
|
|
436
|
-
if (!this.RequestId) {
|
|
437
|
-
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg13', 'RequestId is required to sign signature.');
|
|
438
|
-
}
|
|
439
|
-
const hcrSignature = await hirer_change_request_signature_1.HirerChangeRequestSignature.init(signatureId, dbTransaction);
|
|
440
|
-
await hcrSignature.markSigned(loginUser, dbTransaction);
|
|
441
|
-
return hcrSignature;
|
|
442
|
-
}
|
|
443
|
-
catch (error) {
|
|
444
|
-
throw error;
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
async complete(loginUser, dbTransaction, customerId, customerType) {
|
|
448
|
-
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
449
|
-
const isPrivileged = await loginUser.checkPrivileges(systemCode, 'HIRER_CHANGE_REQUEST');
|
|
450
|
-
if (!isPrivileged) {
|
|
451
|
-
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg01', "You do not have 'HIRER_CHANGE_REQUEST' privilege.");
|
|
452
|
-
}
|
|
453
|
-
if (!this.RequestId) {
|
|
454
|
-
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg06', 'RequestId is required.');
|
|
455
|
-
}
|
|
456
|
-
const signatures = await this.getSignatures(dbTransaction);
|
|
457
|
-
if (!signatures.length || !signatures.every((sig) => sig.SignedAt)) {
|
|
458
|
-
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg14', 'All signatures must be signed before completing the request.');
|
|
459
|
-
}
|
|
460
|
-
if (this.Type === rental_hirer_change_request_type_1.HirerChangeRequestTypeEnum.ADD) {
|
|
461
|
-
if (!customerId || !customerType) {
|
|
462
|
-
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg15', 'CustomerId and CustomerType are required for new hirer.');
|
|
463
|
-
}
|
|
464
|
-
const jointHirer = await joint_hirer_1.JointHirer.init();
|
|
465
|
-
jointHirer.RentalId = this.RentalId;
|
|
466
|
-
jointHirer.CustomerId = customerId;
|
|
467
|
-
jointHirer.CustomerType = customerType;
|
|
468
|
-
await jointHirer.create(loginUser, dbTransaction);
|
|
469
|
-
}
|
|
470
|
-
else if (this.Type === rental_hirer_change_request_type_1.HirerChangeRequestTypeEnum.REMOVE) {
|
|
471
|
-
const removeHirer = await this.getRemoveHirer(dbTransaction);
|
|
472
|
-
const jointHirer = await joint_hirer_1.JointHirer.init(removeHirer.TargetHirerId, dbTransaction);
|
|
473
|
-
await jointHirer.remove(loginUser, dbTransaction);
|
|
474
|
-
}
|
|
475
|
-
const now = new Date();
|
|
476
|
-
const entityValueBefore = this.toJSON();
|
|
477
|
-
this.Status = rental_hirer_change_request_status_1.HirerChangeRequestStatusEnum.COMPLETED;
|
|
478
|
-
this.UpdatedAt = new Date();
|
|
479
|
-
this.UpdatedById = loginUser.ObjectId;
|
|
480
|
-
const entityValueAfter = this.toJSON();
|
|
481
|
-
await RentalHirerChangeRequest._Repository.update(entityValueAfter, {
|
|
482
|
-
where: { RequestId: this.RequestId },
|
|
483
|
-
transaction: dbTransaction,
|
|
484
|
-
});
|
|
485
|
-
const activity = new activity_history_1.Activity();
|
|
486
|
-
activity.ObjectId = this._createId();
|
|
487
|
-
activity.Action = activity_history_1.ActionEnum.UPDATE;
|
|
488
|
-
activity.Description = `Mark request as completed.`;
|
|
489
|
-
activity.EntityId = this.RequestId;
|
|
490
|
-
activity.EntityType = this.ObjectType;
|
|
491
|
-
activity.EntityValueBefore = JSON.stringify(entityValueBefore);
|
|
492
|
-
activity.EntityValueAfter = JSON.stringify(entityValueAfter);
|
|
493
|
-
await activity.create(loginUser.ObjectId, dbTransaction);
|
|
494
|
-
return this;
|
|
495
|
-
}
|
|
496
|
-
async cancel(loginUser, dbTransaction, cancelRemarks) {
|
|
497
|
-
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
498
|
-
const isPrivileged = await loginUser.checkPrivileges(systemCode, 'HIRER_CHANGE_REQUEST');
|
|
499
|
-
if (!isPrivileged) {
|
|
500
|
-
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg01', "You do not have 'HIRER_CHANGE_REQUEST' privilege.");
|
|
501
|
-
}
|
|
502
|
-
if (!this.RequestId) {
|
|
503
|
-
throw new general_1.ClassError('HirerChangeRequest', 'HirerChangeRequestErrMsg06', 'RequestId is required.');
|
|
504
|
-
}
|
|
505
|
-
const entityValueBefore = this.toJSON();
|
|
506
|
-
this.Status = rental_hirer_change_request_status_1.HirerChangeRequestStatusEnum.CANCELLED;
|
|
507
|
-
this.CancelRemarks = cancelRemarks;
|
|
508
|
-
this.UpdatedAt = new Date();
|
|
509
|
-
this.UpdatedById = loginUser.ObjectId;
|
|
510
|
-
const entityValueAfter = this.toJSON();
|
|
511
|
-
await RentalHirerChangeRequest._Repository.update(entityValueAfter, {
|
|
512
|
-
where: { RequestId: this.RequestId },
|
|
513
|
-
transaction: dbTransaction,
|
|
514
564
|
});
|
|
515
|
-
const activity = new activity_history_1.Activity();
|
|
516
|
-
activity.ObjectId = this._createId();
|
|
517
|
-
activity.Action = activity_history_1.ActionEnum.UPDATE;
|
|
518
|
-
activity.Description = `Cancel hirer change request.`;
|
|
519
|
-
activity.EntityId = this.RequestId;
|
|
520
|
-
activity.EntityType = this.ObjectType;
|
|
521
|
-
activity.EntityValueBefore = JSON.stringify(entityValueBefore);
|
|
522
|
-
activity.EntityValueAfter = JSON.stringify(entityValueAfter);
|
|
523
|
-
await activity.create(loginUser.ObjectId, dbTransaction);
|
|
524
|
-
return this;
|
|
525
565
|
}
|
|
526
566
|
}
|
|
527
567
|
exports.RentalHirerChangeRequest = RentalHirerChangeRequest;
|