@tomei/rental 0.17.4-dev.1 → 0.17.4-dev.11
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/src/components/joint-hirer/joint-hirer.d.ts +2 -0
- package/dist/src/components/joint-hirer/joint-hirer.js +37 -0
- package/dist/src/components/joint-hirer/joint-hirer.js.map +1 -1
- package/dist/src/components/rental/rental.js +2 -1
- package/dist/src/components/rental/rental.js.map +1 -1
- package/dist/src/components/rental-hirer-change-request/rental-hirer-change-request.js +20 -23
- package/dist/src/components/rental-hirer-change-request/rental-hirer-change-request.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/joint-hirer/joint-hirer.ts +63 -0
- package/src/components/rental/rental.ts +2 -1
- package/src/components/rental-hirer-change-request/rental-hirer-change-request.ts +44 -26
package/package.json
CHANGED
|
@@ -4,6 +4,8 @@ import { IJointHirerAttr } from '../../interfaces/joint-hirer-attr.interface';
|
|
|
4
4
|
import { ApplicationConfig } from '@tomei/config';
|
|
5
5
|
import { LoginUser } from '@tomei/sso';
|
|
6
6
|
import { ActionEnum, Activity } from '@tomei/activity-history';
|
|
7
|
+
import { Rental } from '../rental/rental';
|
|
8
|
+
import { RentalAccountTypeEnum } from '../../enum/account-type.enum';
|
|
7
9
|
|
|
8
10
|
export class JointHirer extends ObjectBase {
|
|
9
11
|
ObjectId: string;
|
|
@@ -18,6 +20,7 @@ export class JointHirer extends ObjectBase {
|
|
|
18
20
|
CreatedAt: Date;
|
|
19
21
|
UpdatedById: string;
|
|
20
22
|
UpdatedAt: Date;
|
|
23
|
+
private _Rental: Rental;
|
|
21
24
|
|
|
22
25
|
get HirerId(): string {
|
|
23
26
|
return this.ObjectId;
|
|
@@ -146,6 +149,16 @@ export class JointHirer extends ObjectBase {
|
|
|
146
149
|
|
|
147
150
|
await activity.create(loginUser.ObjectId, dbTransaction);
|
|
148
151
|
|
|
152
|
+
//update the AccountType
|
|
153
|
+
const rental = await this.getRental(dbTransaction);
|
|
154
|
+
const totalIds = await rental.getCustomerIds(loginUser, dbTransaction);
|
|
155
|
+
|
|
156
|
+
if (totalIds.length > 1 && rental.AccountType === 'Single') {
|
|
157
|
+
await rental.update(loginUser, dbTransaction, {
|
|
158
|
+
AccountType: RentalAccountTypeEnum.JOINT,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
149
162
|
return this;
|
|
150
163
|
} catch (error) {
|
|
151
164
|
throw error;
|
|
@@ -154,6 +167,20 @@ export class JointHirer extends ObjectBase {
|
|
|
154
167
|
|
|
155
168
|
public async remove(loginUser: LoginUser, dbTransaction?: any) {
|
|
156
169
|
try {
|
|
170
|
+
//Make sure this.HirerId exists
|
|
171
|
+
if (!this.HirerId) {
|
|
172
|
+
throw new ClassError(
|
|
173
|
+
'JointHirer',
|
|
174
|
+
'JointHirerErrMsg02',
|
|
175
|
+
'HirerId is required to remove Joint Hirer.',
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
//Make sure this.Status is not "Inactive"
|
|
180
|
+
if (this.Status === 'Inactive') {
|
|
181
|
+
return this;
|
|
182
|
+
}
|
|
183
|
+
|
|
157
184
|
//Mark Joint Hirer as Inactive
|
|
158
185
|
const entityValueBefore: IJointHirerAttr = this.toJSON();
|
|
159
186
|
this.Status = 'Inactive'; // Set status to 'Inactive' instead of deleting the record
|
|
@@ -181,9 +208,45 @@ export class JointHirer extends ObjectBase {
|
|
|
181
208
|
|
|
182
209
|
await activity.create(loginUser.ObjectId, dbTransaction);
|
|
183
210
|
|
|
211
|
+
//update the AccountType
|
|
212
|
+
const rental = await this.getRental(dbTransaction);
|
|
213
|
+
const totalIds = await rental.getCustomerIds(loginUser, dbTransaction);
|
|
214
|
+
|
|
215
|
+
if (totalIds.length === 1 && rental.AccountType === 'Joint') {
|
|
216
|
+
await rental.update(loginUser, dbTransaction, {
|
|
217
|
+
AccountType: RentalAccountTypeEnum.SINGLE,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
184
221
|
return this;
|
|
185
222
|
} catch (error) {
|
|
186
223
|
throw error;
|
|
187
224
|
}
|
|
188
225
|
}
|
|
226
|
+
|
|
227
|
+
private async getRental(dbTransaction?: any) {
|
|
228
|
+
if (this._Rental) {
|
|
229
|
+
return this._Rental;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (!this.RentalId) {
|
|
233
|
+
throw new ClassError(
|
|
234
|
+
'JointHirer',
|
|
235
|
+
'JointHirerErrMsg04',
|
|
236
|
+
'RentalId is empty.',
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
this._Rental = await Rental.init(dbTransaction, this.RentalId);
|
|
241
|
+
|
|
242
|
+
if (!this._Rental) {
|
|
243
|
+
throw new ClassError(
|
|
244
|
+
'JointHirer',
|
|
245
|
+
'JointHirerErrMsg05',
|
|
246
|
+
'Rental not found.',
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return this._Rental;
|
|
251
|
+
}
|
|
189
252
|
}
|
|
@@ -131,7 +131,7 @@ export class Rental extends ObjectBase {
|
|
|
131
131
|
throw new ClassError(
|
|
132
132
|
'Rental',
|
|
133
133
|
'RentalErrMsg00',
|
|
134
|
-
'Failed To Initialize
|
|
134
|
+
'Failed To Initialize Rental',
|
|
135
135
|
);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
@@ -796,6 +796,7 @@ export class Rental extends ObjectBase {
|
|
|
796
796
|
const options: any = {
|
|
797
797
|
where: {
|
|
798
798
|
RentalId: this.RentalId,
|
|
799
|
+
Status: 'Active',
|
|
799
800
|
},
|
|
800
801
|
transaction: dbTransaction,
|
|
801
802
|
};
|
|
@@ -228,6 +228,7 @@ export class RentalHirerChangeRequest
|
|
|
228
228
|
const rental = await Rental.init(dbTransaction, this.RentalId);
|
|
229
229
|
|
|
230
230
|
// 2.3 only allow for rental account where its joint hirer not maximum yet (at this step you've retrieve the number of joint hirer)
|
|
231
|
+
rental.AccountType = RentalAccountTypeEnum.JOINT;
|
|
231
232
|
const jointHirers = await rental.getJointHirers(dbTransaction);
|
|
232
233
|
|
|
233
234
|
if (this.Type === HirerChangeRequestTypeEnum.ADD) {
|
|
@@ -444,6 +445,7 @@ export class RentalHirerChangeRequest
|
|
|
444
445
|
}
|
|
445
446
|
|
|
446
447
|
// 2. Prepare all signature data (main + joint) in one go
|
|
448
|
+
this.Rental.AccountType = RentalAccountTypeEnum.JOINT;
|
|
447
449
|
const jointHirers = await this.Rental.getJointHirers(dbTransaction);
|
|
448
450
|
|
|
449
451
|
// Main hirer signature
|
|
@@ -453,23 +455,32 @@ export class RentalHirerChangeRequest
|
|
|
453
455
|
mainSignature.HirerType = HirerChangeRequestHirerRoleEnum.MAIN;
|
|
454
456
|
mainSignature.Method = 'Upload';
|
|
455
457
|
|
|
456
|
-
// Joint hirer signatures
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
458
|
+
// Joint hirer signatures - only if there are joint hirers
|
|
459
|
+
let jointSignatures = [];
|
|
460
|
+
if (jointHirers.length > 0) {
|
|
461
|
+
const jointSignaturePromises = jointHirers.map(async (jointHirer) => {
|
|
462
|
+
const signature = await HirerChangeRequestSignature.init();
|
|
463
|
+
signature.RequestId = this.RequestId;
|
|
464
|
+
signature.JointHirerId = jointHirer.HirerId;
|
|
465
|
+
signature.HirerType = HirerChangeRequestHirerRoleEnum.JOINT;
|
|
466
|
+
signature.Method = 'Upload';
|
|
467
|
+
return signature;
|
|
468
|
+
});
|
|
465
469
|
|
|
466
|
-
|
|
470
|
+
jointSignatures = await Promise.all(jointSignaturePromises);
|
|
471
|
+
}
|
|
467
472
|
|
|
468
473
|
// 3. Create all signatures in parallel
|
|
469
|
-
|
|
474
|
+
const signaturesToCreate = [
|
|
470
475
|
mainSignature.create(loginUser, dbTransaction),
|
|
471
|
-
|
|
472
|
-
|
|
476
|
+
];
|
|
477
|
+
if (jointSignatures.length > 0) {
|
|
478
|
+
signaturesToCreate.push(
|
|
479
|
+
...jointSignatures.map((sig) => sig.create(loginUser, dbTransaction)),
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
await Promise.all(signaturesToCreate);
|
|
473
484
|
|
|
474
485
|
this.Signatures = [mainSignature, ...jointSignatures];
|
|
475
486
|
} catch (error) {
|
|
@@ -799,10 +810,10 @@ export class RentalHirerChangeRequest
|
|
|
799
810
|
await jointHirer.create(loginUser, dbTransaction);
|
|
800
811
|
|
|
801
812
|
//d. Set the AccountType to "Joint" for the rental
|
|
802
|
-
const rental = await Rental.init(dbTransaction, this.RentalId);
|
|
803
|
-
await rental.update(loginUser, dbTransaction, {
|
|
804
|
-
|
|
805
|
-
});
|
|
813
|
+
// const rental = await Rental.init(dbTransaction, this.RentalId);
|
|
814
|
+
// await rental.update(loginUser, dbTransaction, {
|
|
815
|
+
// AccountType: RentalAccountTypeEnum.JOINT,
|
|
816
|
+
// });
|
|
806
817
|
} else if (this.Type === HirerChangeRequestTypeEnum.REMOVE) {
|
|
807
818
|
// a. Get joint hirer from remove hirer request
|
|
808
819
|
const removeHirer = await this.getRemoveHirer(dbTransaction);
|
|
@@ -814,15 +825,22 @@ export class RentalHirerChangeRequest
|
|
|
814
825
|
//Call jointHirer.remove() method by passing loginUser and dbTransaction
|
|
815
826
|
await jointHirer.remove(loginUser, dbTransaction);
|
|
816
827
|
|
|
817
|
-
//find the number of joint hirers after removal
|
|
818
|
-
const rental = await Rental.init(dbTransaction, this.RentalId);
|
|
819
|
-
|
|
820
|
-
//
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
828
|
+
// //find the number of joint hirers after removal
|
|
829
|
+
// const rental = await Rental.init(dbTransaction, this.RentalId);
|
|
830
|
+
// rental.AccountType = RentalAccountTypeEnum.JOINT;
|
|
831
|
+
// const jointHirers = await rental.getJointHirers(dbTransaction);
|
|
832
|
+
|
|
833
|
+
// //filter out the active joint hirers
|
|
834
|
+
// const activeJointHirers = jointHirers.filter(
|
|
835
|
+
// (hirer) => hirer.Status === 'Active',
|
|
836
|
+
// );
|
|
837
|
+
|
|
838
|
+
// //if jointHirers is empty, set rental.AccountType to "Single"
|
|
839
|
+
// if (activeJointHirers.length === 0) {
|
|
840
|
+
// await rental.update(loginUser, dbTransaction, {
|
|
841
|
+
// AccountType: RentalAccountTypeEnum.SINGLE,
|
|
842
|
+
// });
|
|
843
|
+
// }
|
|
826
844
|
}
|
|
827
845
|
|
|
828
846
|
// 3. Call _Repo update method
|