@tomei/rental 0.17.4-dev.11 → 0.17.4-dev.2
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 +0 -2
- package/dist/src/components/joint-hirer/joint-hirer.js +0 -37
- package/dist/src/components/joint-hirer/joint-hirer.js.map +1 -1
- package/dist/src/components/rental/rental.js +1 -2
- package/dist/src/components/rental/rental.js.map +1 -1
- package/dist/src/components/rental-hirer-change-request/rental-hirer-change-request.js +23 -19
- 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 +0 -63
- package/src/components/rental/rental.ts +1 -2
- package/src/components/rental-hirer-change-request/rental-hirer-change-request.ts +26 -43
package/package.json
CHANGED
|
@@ -4,8 +4,6 @@ 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';
|
|
9
7
|
|
|
10
8
|
export class JointHirer extends ObjectBase {
|
|
11
9
|
ObjectId: string;
|
|
@@ -20,7 +18,6 @@ export class JointHirer extends ObjectBase {
|
|
|
20
18
|
CreatedAt: Date;
|
|
21
19
|
UpdatedById: string;
|
|
22
20
|
UpdatedAt: Date;
|
|
23
|
-
private _Rental: Rental;
|
|
24
21
|
|
|
25
22
|
get HirerId(): string {
|
|
26
23
|
return this.ObjectId;
|
|
@@ -149,16 +146,6 @@ export class JointHirer extends ObjectBase {
|
|
|
149
146
|
|
|
150
147
|
await activity.create(loginUser.ObjectId, dbTransaction);
|
|
151
148
|
|
|
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
|
-
|
|
162
149
|
return this;
|
|
163
150
|
} catch (error) {
|
|
164
151
|
throw error;
|
|
@@ -167,20 +154,6 @@ export class JointHirer extends ObjectBase {
|
|
|
167
154
|
|
|
168
155
|
public async remove(loginUser: LoginUser, dbTransaction?: any) {
|
|
169
156
|
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
|
-
|
|
184
157
|
//Mark Joint Hirer as Inactive
|
|
185
158
|
const entityValueBefore: IJointHirerAttr = this.toJSON();
|
|
186
159
|
this.Status = 'Inactive'; // Set status to 'Inactive' instead of deleting the record
|
|
@@ -208,45 +181,9 @@ export class JointHirer extends ObjectBase {
|
|
|
208
181
|
|
|
209
182
|
await activity.create(loginUser.ObjectId, dbTransaction);
|
|
210
183
|
|
|
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
|
-
|
|
221
184
|
return this;
|
|
222
185
|
} catch (error) {
|
|
223
186
|
throw error;
|
|
224
187
|
}
|
|
225
188
|
}
|
|
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
|
-
}
|
|
252
189
|
}
|
|
@@ -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 Price',
|
|
135
135
|
);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
@@ -796,7 +796,6 @@ export class Rental extends ObjectBase {
|
|
|
796
796
|
const options: any = {
|
|
797
797
|
where: {
|
|
798
798
|
RentalId: this.RentalId,
|
|
799
|
-
Status: 'Active',
|
|
800
799
|
},
|
|
801
800
|
transaction: dbTransaction,
|
|
802
801
|
};
|
|
@@ -445,7 +445,6 @@ export class RentalHirerChangeRequest
|
|
|
445
445
|
}
|
|
446
446
|
|
|
447
447
|
// 2. Prepare all signature data (main + joint) in one go
|
|
448
|
-
this.Rental.AccountType = RentalAccountTypeEnum.JOINT;
|
|
449
448
|
const jointHirers = await this.Rental.getJointHirers(dbTransaction);
|
|
450
449
|
|
|
451
450
|
// Main hirer signature
|
|
@@ -455,32 +454,23 @@ export class RentalHirerChangeRequest
|
|
|
455
454
|
mainSignature.HirerType = HirerChangeRequestHirerRoleEnum.MAIN;
|
|
456
455
|
mainSignature.Method = 'Upload';
|
|
457
456
|
|
|
458
|
-
// Joint hirer signatures
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
return signature;
|
|
468
|
-
});
|
|
457
|
+
// Joint hirer signatures
|
|
458
|
+
const jointSignaturePromises = jointHirers.map(async (jointHirer) => {
|
|
459
|
+
const signature = await HirerChangeRequestSignature.init();
|
|
460
|
+
signature.RequestId = this.RequestId;
|
|
461
|
+
signature.JointHirerId = jointHirer.HirerId;
|
|
462
|
+
signature.HirerType = HirerChangeRequestHirerRoleEnum.JOINT;
|
|
463
|
+
signature.Method = 'Upload';
|
|
464
|
+
return signature;
|
|
465
|
+
});
|
|
469
466
|
|
|
470
|
-
|
|
471
|
-
}
|
|
467
|
+
const jointSignatures = await Promise.all(jointSignaturePromises);
|
|
472
468
|
|
|
473
469
|
// 3. Create all signatures in parallel
|
|
474
|
-
|
|
470
|
+
await Promise.all([
|
|
475
471
|
mainSignature.create(loginUser, dbTransaction),
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
signaturesToCreate.push(
|
|
479
|
-
...jointSignatures.map((sig) => sig.create(loginUser, dbTransaction)),
|
|
480
|
-
);
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
await Promise.all(signaturesToCreate);
|
|
472
|
+
...jointSignatures.map((sig) => sig.create(loginUser, dbTransaction)),
|
|
473
|
+
]);
|
|
484
474
|
|
|
485
475
|
this.Signatures = [mainSignature, ...jointSignatures];
|
|
486
476
|
} catch (error) {
|
|
@@ -810,10 +800,10 @@ export class RentalHirerChangeRequest
|
|
|
810
800
|
await jointHirer.create(loginUser, dbTransaction);
|
|
811
801
|
|
|
812
802
|
//d. Set the AccountType to "Joint" for the rental
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
803
|
+
const rental = await Rental.init(dbTransaction, this.RentalId);
|
|
804
|
+
await rental.update(loginUser, dbTransaction, {
|
|
805
|
+
AccountType: RentalAccountTypeEnum.JOINT,
|
|
806
|
+
});
|
|
817
807
|
} else if (this.Type === HirerChangeRequestTypeEnum.REMOVE) {
|
|
818
808
|
// a. Get joint hirer from remove hirer request
|
|
819
809
|
const removeHirer = await this.getRemoveHirer(dbTransaction);
|
|
@@ -825,22 +815,15 @@ export class RentalHirerChangeRequest
|
|
|
825
815
|
//Call jointHirer.remove() method by passing loginUser and dbTransaction
|
|
826
816
|
await jointHirer.remove(loginUser, dbTransaction);
|
|
827
817
|
|
|
828
|
-
//
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
//
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
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
|
-
// }
|
|
818
|
+
//find the number of joint hirers after removal
|
|
819
|
+
const rental = await Rental.init(dbTransaction, this.RentalId);
|
|
820
|
+
const jointHirers = await rental.getJointHirers(dbTransaction);
|
|
821
|
+
//if jointHirers is empty, set rental.AccountType to "Single"
|
|
822
|
+
if (jointHirers.length === 0) {
|
|
823
|
+
await rental.update(loginUser, dbTransaction, {
|
|
824
|
+
AccountType: RentalAccountTypeEnum.SINGLE,
|
|
825
|
+
});
|
|
826
|
+
}
|
|
844
827
|
}
|
|
845
828
|
|
|
846
829
|
// 3. Call _Repo update method
|