@tomei/rental 0.17.4-dev.11 → 0.17.4-dev.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/rental",
3
- "version": "0.17.4-dev.11",
3
+ "version": "0.17.4-dev.3",
4
4
  "description": "Tomei Rental Package",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -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 Rental',
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
  };
@@ -810,10 +810,10 @@ export class RentalHirerChangeRequest
810
810
  await jointHirer.create(loginUser, dbTransaction);
811
811
 
812
812
  //d. Set the AccountType to "Joint" for the rental
813
- // const rental = await Rental.init(dbTransaction, this.RentalId);
814
- // await rental.update(loginUser, dbTransaction, {
815
- // AccountType: RentalAccountTypeEnum.JOINT,
816
- // });
813
+ const rental = await Rental.init(dbTransaction, this.RentalId);
814
+ await rental.update(loginUser, dbTransaction, {
815
+ AccountType: RentalAccountTypeEnum.JOINT,
816
+ });
817
817
  } else if (this.Type === HirerChangeRequestTypeEnum.REMOVE) {
818
818
  // a. Get joint hirer from remove hirer request
819
819
  const removeHirer = await this.getRemoveHirer(dbTransaction);
@@ -825,22 +825,15 @@ export class RentalHirerChangeRequest
825
825
  //Call jointHirer.remove() method by passing loginUser and dbTransaction
826
826
  await jointHirer.remove(loginUser, dbTransaction);
827
827
 
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
- // }
828
+ //find the number of joint hirers after removal
829
+ const rental = await Rental.init(dbTransaction, this.RentalId);
830
+ const jointHirers = await rental.getJointHirers(dbTransaction);
831
+ //if jointHirers is empty, set rental.AccountType to "Single"
832
+ if (jointHirers.length === 0) {
833
+ await rental.update(loginUser, dbTransaction, {
834
+ AccountType: RentalAccountTypeEnum.SINGLE,
835
+ });
836
+ }
844
837
  }
845
838
 
846
839
  // 3. Call _Repo update method