@tomei/rental 0.6.3 → 0.7.0

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.
Files changed (43) hide show
  1. package/dist/src/components/agreement/agreement.d.ts +14 -0
  2. package/dist/src/components/agreement/agreement.js +48 -0
  3. package/dist/src/components/agreement/agreement.js.map +1 -0
  4. package/dist/src/components/agreement/agreement.repository.d.ts +8 -0
  5. package/dist/src/components/agreement/agreement.repository.js +67 -0
  6. package/dist/src/components/agreement/agreement.repository.js.map +1 -0
  7. package/dist/src/components/rental/rental.d.ts +2 -0
  8. package/dist/src/components/rental/rental.js +27 -1
  9. package/dist/src/components/rental/rental.js.map +1 -1
  10. package/dist/src/enum/rental-status.enum.d.ts +3 -1
  11. package/dist/src/enum/rental-status.enum.js +2 -0
  12. package/dist/src/enum/rental-status.enum.js.map +1 -1
  13. package/dist/src/index.d.ts +3 -1
  14. package/dist/src/index.js +5 -1
  15. package/dist/src/index.js.map +1 -1
  16. package/dist/src/interfaces/agreement-attr.interface.d.ts +4 -0
  17. package/dist/src/interfaces/agreement-attr.interface.js +3 -0
  18. package/dist/src/interfaces/agreement-attr.interface.js.map +1 -0
  19. package/dist/src/interfaces/index.d.ts +2 -1
  20. package/dist/src/models/agreement.entity.d.ts +7 -0
  21. package/dist/src/models/agreement.entity.js +45 -0
  22. package/dist/src/models/agreement.entity.js.map +1 -0
  23. package/dist/src/models/index.d.ts +2 -1
  24. package/dist/src/models/index.js +3 -1
  25. package/dist/src/models/index.js.map +1 -1
  26. package/dist/src/models/rental.entity.d.ts +2 -0
  27. package/dist/src/models/rental.entity.js +6 -0
  28. package/dist/src/models/rental.entity.js.map +1 -1
  29. package/dist/tsconfig.tsbuildinfo +1 -1
  30. package/migrations/rental-aggrement-table-migration.js +22 -0
  31. package/migrations/rental-table-migrations.js +6 -0
  32. package/package.json +1 -1
  33. package/src/components/agreement/agreement.repository.ts +54 -0
  34. package/src/components/agreement/agreement.ts +43 -0
  35. package/src/components/rental/rental.ts +38 -4
  36. package/src/enum/rental-status.enum.ts +10 -0
  37. package/src/index.ts +4 -0
  38. package/src/interfaces/agreement-attr.interface.ts +4 -0
  39. package/src/interfaces/index.ts +2 -0
  40. package/src/models/agreement.entity.ts +26 -0
  41. package/src/models/index.ts +8 -1
  42. package/src/models/rental.entity.ts +5 -0
  43. package/tsconfig.json +1 -1
@@ -0,0 +1,54 @@
1
+ import { RepositoryBase, IRepositoryBase } from '@tomei/general';
2
+ import { AgreementModel } from '../../models/agreement.entity';
3
+
4
+ export class AgreementRepository
5
+ extends RepositoryBase<AgreementModel>
6
+ implements IRepositoryBase<AgreementModel>
7
+ {
8
+ constructor() {
9
+ super(AgreementModel);
10
+ }
11
+
12
+ async findByPk(
13
+ id: string,
14
+ transaction?: any,
15
+ ): Promise<AgreementModel | null> {
16
+ try {
17
+ const result = await AgreementModel.findByPk(id, {
18
+ transaction: transaction,
19
+ });
20
+
21
+ return result;
22
+ } catch (error) {
23
+ throw new Error(`An Error occured when fetching : ${error.message}`);
24
+ }
25
+ }
26
+
27
+ async delete(AgreementNo: string, dbTransaction?: any) {
28
+ try {
29
+ const options = {
30
+ where: {
31
+ AgreementNo,
32
+ },
33
+ transaction: dbTransaction,
34
+ };
35
+ await AgreementModel.destroy(options);
36
+ } catch (error) {
37
+ throw new Error(`An Error occured when delete : ${error.message}`);
38
+ }
39
+ }
40
+
41
+ async findAndCountAll(options?: any) {
42
+ try {
43
+ let Agreements: any;
44
+ if (options) {
45
+ Agreements = await AgreementModel.findAndCountAll(options);
46
+ } else {
47
+ Agreements = await AgreementModel.findAndCountAll();
48
+ }
49
+ return Agreements;
50
+ } catch (error) {
51
+ throw new Error(`An Error occured when retriving : ${error.message}`);
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,43 @@
1
+ import { ObjectBase } from '@tomei/general';
2
+ import { IAgreementAttr } from '../../interfaces/agreement-attr.interface';
3
+ import { AgreementRepository } from './agreement.repository';
4
+
5
+ export class Agreement extends ObjectBase {
6
+ ObjectId: string;
7
+ ObjectName: string;
8
+ ObjectType: string = 'Agreement';
9
+ TableName = 'rental_Agreement';
10
+ Status: string;
11
+ private static _Repo = new AgreementRepository();
12
+
13
+ get AgreementNo(): string {
14
+ return this.ObjectId;
15
+ }
16
+
17
+ set AgreementNo(value: string) {
18
+ this.ObjectId = value;
19
+ }
20
+
21
+ protected constructor(agreementAttr?: IAgreementAttr) {
22
+ super();
23
+ if (agreementAttr) {
24
+ this.ObjectId = agreementAttr.AgreementNo;
25
+ this.Status = agreementAttr.Status;
26
+ }
27
+ }
28
+
29
+ public static async init(
30
+ agreementNo?: string,
31
+ dbTransaction?: any,
32
+ ): Promise<Agreement> {
33
+ try {
34
+ if (agreementNo) {
35
+ const agreement = await this._Repo.findByPk(agreementNo, dbTransaction);
36
+ return new Agreement(agreement?.get({ plain: true }));
37
+ }
38
+ return new Agreement();
39
+ } catch (error) {
40
+ throw error;
41
+ }
42
+ }
43
+ }
@@ -10,6 +10,8 @@ import { ActionEnum, Activity } from '@tomei/activity-history';
10
10
  import { IRentalFindAllSearchAttr } from '../../interfaces/rental-find-all-search-attr.interface';
11
11
  import { RentalAccountTypeEnum } from '../../enum/account-type.enum';
12
12
  import { JointHirer } from '../joint-hirer/joint-hirer';
13
+ import { JointHirerModel } from '../../models/joint-hirer.entity';
14
+ import { AgreementRepository } from '../agreement/agreement.repository';
13
15
 
14
16
  export class Rental extends ObjectBase {
15
17
  ObjectId: string;
@@ -35,6 +37,7 @@ export class Rental extends ObjectBase {
35
37
  protected _UpdatedById: string;
36
38
  protected _UpdatedAt: Date;
37
39
  protected static _Repo = new RentalRepository();
40
+ protected static _AgreementRepo = new AgreementRepository();
38
41
 
39
42
  get RentalId(): string {
40
43
  return this.ObjectId;
@@ -166,7 +169,22 @@ export class Rental extends ObjectBase {
166
169
  );
167
170
  }
168
171
 
169
- /*Part 3: Insert Rental & The Agreed Rental Price*/
172
+ // Part 3: Create Rental Agreement Record
173
+ // Call Rental._AgreementRepo create method by passing:
174
+ // AgreementNo: this.AgreementNo
175
+ // Status: "Not Generated"
176
+ // dbTransaction
177
+ await Rental._AgreementRepo.create(
178
+ {
179
+ AgreementNo: this.AgreementNo,
180
+ Status: 'Not Generated',
181
+ },
182
+ {
183
+ transaction: dbTransaction,
184
+ },
185
+ );
186
+
187
+ /*Part 4: Insert Rental & The Agreed Rental Price*/
170
188
  await rentalPrice.create(loginUser, dbTransaction);
171
189
 
172
190
  this.PriceId = rentalPrice.PriceId;
@@ -212,7 +230,7 @@ export class Rental extends ObjectBase {
212
230
  }
213
231
  }
214
232
 
215
- /*Part 4: Record Create Rental Activity*/
233
+ /*Part 5: Record Create Rental Activity*/
216
234
  const activity = new Activity();
217
235
  activity.ActivityId = activity.createId();
218
236
  activity.Action = ActionEnum.ADD;
@@ -223,7 +241,7 @@ export class Rental extends ObjectBase {
223
241
  activity.EntityValueAfter = JSON.stringify(data);
224
242
  await activity.create(loginUser.ObjectId, dbTransaction);
225
243
 
226
- /*Part 5: Return Result*/
244
+ /*Part 6: Return Result*/
227
245
  return this;
228
246
  } catch (error) {
229
247
  throw error;
@@ -291,6 +309,7 @@ export class Rental extends ObjectBase {
291
309
 
292
310
  let options: any = {
293
311
  transaction: dbTransaction,
312
+ order: [['CreatedAt', 'DESC']],
294
313
  };
295
314
 
296
315
  if (page && row) {
@@ -298,7 +317,6 @@ export class Rental extends ObjectBase {
298
317
  ...options,
299
318
  limit: row,
300
319
  offset: row * (page - 1),
301
- order: [['CreatedAt', 'DESC']],
302
320
  };
303
321
  }
304
322
 
@@ -312,6 +330,22 @@ export class Rental extends ObjectBase {
312
330
  queryObj[key] = {
313
331
  [Op.lte]: value,
314
332
  };
333
+ } else if (key === 'CustomerId') {
334
+ queryObj[key] = {
335
+ [Op.substring]: value,
336
+ };
337
+
338
+ options.include = [
339
+ {
340
+ model: JointHirerModel,
341
+ required: false,
342
+ where: {
343
+ CustomerId: {
344
+ [Op.substring]: value,
345
+ },
346
+ },
347
+ },
348
+ ];
315
349
  } else {
316
350
  queryObj[key] = {
317
351
  [Op.substring]: value,
@@ -26,4 +26,14 @@ export enum RentalStatusEnum {
26
26
  * Rental has been terminated by the customer.
27
27
  */
28
28
  TERMINATED = 'Terminated',
29
+
30
+ /**
31
+ * Customer is pending signing rental agreement
32
+ */
33
+ PENDING_SIGNING = 'Pending Signing',
34
+
35
+ /**
36
+ * Customer already signed and now needs to collect the rental key.
37
+ */
38
+ PENDING_KEY_COLLECTION = 'Pending Key Collection',
29
39
  }
package/src/index.ts CHANGED
@@ -6,6 +6,8 @@ import { Booking } from './components/booking/booking';
6
6
  import { BookingRepository } from './components/booking/booking.repository';
7
7
  import { JointHirer } from './components/joint-hirer/joint-hirer';
8
8
  import { JointHirerRepository } from './components/joint-hirer/joint-hirer.repository';
9
+ import { Agreement } from './components/agreement/agreement';
10
+ import { AgreementRepository } from './components/agreement/agreement.repository';
9
11
  import * as rentalDb from './database';
10
12
  export * from './interfaces';
11
13
  export * from './models';
@@ -21,4 +23,6 @@ export {
21
23
  rentalDb,
22
24
  JointHirer,
23
25
  JointHirerRepository,
26
+ Agreement,
27
+ AgreementRepository,
24
28
  };
@@ -0,0 +1,4 @@
1
+ export interface IAgreementAttr {
2
+ AgreementNo: string;
3
+ Status: string;
4
+ }
@@ -2,10 +2,12 @@ import { IRentalAttr } from './rental-attr.interface';
2
2
  import { IRentalPriceAttr } from './rental-price-attr.interface';
3
3
  import { IRentalFindAllSearchAttr } from './rental-find-all-search-attr.interface';
4
4
  import { IBookingAttr } from './booking-attr.interface';
5
+ import { IAgreementAttr } from './agreement-attr.interface';
5
6
 
6
7
  export {
7
8
  IRentalAttr,
8
9
  IRentalPriceAttr,
9
10
  IRentalFindAllSearchAttr,
10
11
  IBookingAttr,
12
+ IAgreementAttr,
11
13
  };
@@ -0,0 +1,26 @@
1
+ import { Column, DataType, Table, Model, HasMany } from 'sequelize-typescript';
2
+ import { RentalModel } from './rental.entity';
3
+
4
+ @Table({
5
+ tableName: 'rental_Agreement',
6
+ createdAt: false,
7
+ updatedAt: false,
8
+ timestamps: false,
9
+ })
10
+ export class AgreementModel extends Model {
11
+ @Column({
12
+ primaryKey: true,
13
+ allowNull: false,
14
+ type: DataType.STRING(30),
15
+ })
16
+ AgreementNo: string;
17
+
18
+ @Column({
19
+ allowNull: false,
20
+ type: DataType.STRING(10),
21
+ })
22
+ Status: string;
23
+
24
+ @HasMany(() => RentalModel)
25
+ Rentals: RentalModel[];
26
+ }
@@ -2,5 +2,12 @@ import { RentalModel } from './rental.entity';
2
2
  import { RentalPriceModel } from './rental-price.entity';
3
3
  import { BookingModel } from './booking.entity';
4
4
  import { JointHirerModel } from './joint-hirer.entity';
5
+ import { AgreementModel } from './agreement.entity';
5
6
 
6
- export { RentalModel, RentalPriceModel, BookingModel, JointHirerModel };
7
+ export {
8
+ RentalModel,
9
+ RentalPriceModel,
10
+ BookingModel,
11
+ JointHirerModel,
12
+ AgreementModel,
13
+ };
@@ -13,6 +13,7 @@ import { RentalPriceModel } from './rental-price.entity';
13
13
  import { RentalStatusEnum } from '../enum/rental-status.enum';
14
14
  import { JointHirerModel } from './joint-hirer.entity';
15
15
  import { RentalAccountTypeEnum } from '../enum/account-type.enum';
16
+ import { AgreementModel } from './agreement.entity';
16
17
 
17
18
  @Table({
18
19
  tableName: 'rental_Rental',
@@ -89,6 +90,7 @@ export class RentalModel extends Model {
89
90
  })
90
91
  EscheatmentYN: string;
91
92
 
93
+ @ForeignKey(() => AgreementModel)
92
94
  @Column({
93
95
  allowNull: false,
94
96
  unique: true,
@@ -123,6 +125,9 @@ export class RentalModel extends Model {
123
125
  @BelongsTo(() => RentalPriceModel)
124
126
  RentalPrice: RentalPriceModel;
125
127
 
128
+ @BelongsTo(() => AgreementModel)
129
+ Agreement: AgreementModel;
130
+
126
131
  @HasMany(() => JointHirerModel)
127
132
  JointHirers: JointHirerModel[];
128
133
  }
package/tsconfig.json CHANGED
@@ -18,6 +18,6 @@
18
18
  "strictBindCallApply": false,
19
19
  "forceConsistentCasingInFileNames": false,
20
20
  "noFallthroughCasesInSwitch": false,
21
- "strictNullChecks": true
21
+ "strictNullChecks": false,
22
22
  },
23
23
  }