@tomei/rental 0.5.2 → 0.6.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 (49) hide show
  1. package/dist/src/components/joint-hirer/joint-hirer.d.ts +23 -0
  2. package/dist/src/components/joint-hirer/joint-hirer.js +106 -0
  3. package/dist/src/components/joint-hirer/joint-hirer.js.map +1 -0
  4. package/dist/src/components/joint-hirer/joint-hirer.repository.d.ts +8 -0
  5. package/dist/src/components/joint-hirer/joint-hirer.repository.js +67 -0
  6. package/dist/src/components/joint-hirer/joint-hirer.repository.js.map +1 -0
  7. package/dist/src/components/rental/rental.d.ts +9 -3
  8. package/dist/src/components/rental/rental.js +13 -1
  9. package/dist/src/components/rental/rental.js.map +1 -1
  10. package/dist/src/database.js +2 -0
  11. package/dist/src/database.js.map +1 -1
  12. package/dist/src/enum/account-type.enum.d.ts +4 -0
  13. package/dist/src/enum/account-type.enum.js +9 -0
  14. package/dist/src/enum/account-type.enum.js.map +1 -0
  15. package/dist/src/enum/index.d.ts +2 -1
  16. package/dist/src/enum/index.js +3 -1
  17. package/dist/src/enum/index.js.map +1 -1
  18. package/dist/src/index.d.ts +3 -1
  19. package/dist/src/index.js +5 -1
  20. package/dist/src/index.js.map +1 -1
  21. package/dist/src/interfaces/joint-hirer-attr.interface.d.ts +10 -0
  22. package/dist/src/interfaces/joint-hirer-attr.interface.js +3 -0
  23. package/dist/src/interfaces/joint-hirer-attr.interface.js.map +1 -0
  24. package/dist/src/interfaces/rental-attr.interface.d.ts +2 -0
  25. package/dist/src/models/index.d.ts +2 -1
  26. package/dist/src/models/index.js +3 -1
  27. package/dist/src/models/index.js.map +1 -1
  28. package/dist/src/models/joint-hirer.entity.d.ts +13 -0
  29. package/dist/src/models/joint-hirer.entity.js +79 -0
  30. package/dist/src/models/joint-hirer.entity.js.map +1 -0
  31. package/dist/src/models/rental.entity.d.ts +4 -0
  32. package/dist/src/models/rental.entity.js +13 -0
  33. package/dist/src/models/rental.entity.js.map +1 -1
  34. package/dist/tsconfig.tsbuildinfo +1 -1
  35. package/migrations/joint-hirer-table-migration.js +52 -0
  36. package/migrations/rental-table-migrations.js +4 -0
  37. package/package.json +1 -1
  38. package/src/components/joint-hirer/joint-hirer.repository.ts +54 -0
  39. package/src/components/joint-hirer/joint-hirer.ts +137 -0
  40. package/src/components/rental/rental.ts +20 -2
  41. package/src/database.ts +2 -0
  42. package/src/enum/account-type.enum.ts +4 -0
  43. package/src/enum/index.ts +2 -1
  44. package/src/index.ts +4 -0
  45. package/src/interfaces/joint-hirer-attr.interface.ts +10 -0
  46. package/src/interfaces/rental-attr.interface.ts +2 -0
  47. package/src/models/index.ts +2 -1
  48. package/src/models/joint-hirer.entity.ts +63 -0
  49. package/src/models/rental.entity.ts +12 -0
@@ -0,0 +1,54 @@
1
+ import { RepositoryBase, IRepositoryBase } from '@tomei/general';
2
+ import { JointHirerModel } from '../../models/joint-hirer.entity';
3
+
4
+ export class JointHirerRepository
5
+ extends RepositoryBase<JointHirerModel>
6
+ implements IRepositoryBase<JointHirerModel>
7
+ {
8
+ constructor() {
9
+ super(JointHirerModel);
10
+ }
11
+
12
+ async findByPk(
13
+ id: string,
14
+ transaction?: any,
15
+ ): Promise<JointHirerModel | null> {
16
+ try {
17
+ const result = await JointHirerModel.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(hirerId: string, dbTransaction?: any) {
28
+ try {
29
+ const options = {
30
+ where: {
31
+ HirerId: hirerId,
32
+ },
33
+ transaction: dbTransaction,
34
+ };
35
+ await JointHirerModel.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 jointHirers: any;
44
+ if (options) {
45
+ jointHirers = await JointHirerModel.findAndCountAll(options);
46
+ } else {
47
+ jointHirers = await JointHirerModel.findAndCountAll();
48
+ }
49
+ return jointHirers;
50
+ } catch (error) {
51
+ throw new Error(`An Error occured when retriving : ${error.message}`);
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,137 @@
1
+ import { ClassError, ObjectBase } from '@tomei/general';
2
+ import { JointHirerRepository } from './joint-hirer.repository';
3
+ import { IJointHirerAttr } from '../../interfaces/joint-hirer-attr.interface';
4
+ import { ApplicationConfig } from '@tomei/config';
5
+ import { LoginUser } from '@tomei/sso';
6
+ import { ActionEnum, Activity } from '@tomei/activity-history';
7
+
8
+ export class JointHirer extends ObjectBase {
9
+ ObjectId: string;
10
+ ObjectName: string;
11
+ ObjectType: string = 'JointHirer';
12
+ TableName: string = 'rental_JointHirer';
13
+ RentalId: string;
14
+ CustomerId: string;
15
+ CustomerType: string;
16
+ CreatedById: string;
17
+ CreatedAt: Date;
18
+ UpdatedById: string;
19
+ UpdatedAt: Date;
20
+
21
+ get HirerId(): string {
22
+ return this.ObjectId;
23
+ }
24
+
25
+ set HirerId(value: string) {
26
+ this.ObjectId = value;
27
+ }
28
+
29
+ protected static _Repository = new JointHirerRepository();
30
+
31
+ protected constructor(jointHirerAttr?: IJointHirerAttr) {
32
+ super();
33
+ if (jointHirerAttr) {
34
+ this.HirerId = jointHirerAttr.HirerId;
35
+ this.RentalId = jointHirerAttr.RentalId;
36
+ this.CustomerId = jointHirerAttr.CustomerId;
37
+ this.CustomerType = jointHirerAttr.CustomerType;
38
+ this.CreatedById = jointHirerAttr.CreatedById;
39
+ this.CreatedAt = jointHirerAttr.CreatedAt;
40
+ this.UpdatedById = jointHirerAttr.UpdatedById;
41
+ this.UpdatedAt = jointHirerAttr.UpdatedAt;
42
+ }
43
+ }
44
+
45
+ public static async init(hirerId?: string, dbTransaction?: any) {
46
+ try {
47
+ if (hirerId) {
48
+ const jr = await JointHirer._Repository.findByPk(
49
+ hirerId,
50
+ dbTransaction,
51
+ );
52
+ if (jr) {
53
+ return new JointHirer(jr.get({ plain: true }));
54
+ } else {
55
+ throw new ClassError(
56
+ 'JointHirer',
57
+ 'JointHirerErrMsg01',
58
+ 'JointHirer not found',
59
+ );
60
+ }
61
+ }
62
+ return new JointHirer();
63
+ } catch (error) {
64
+ throw error;
65
+ }
66
+ }
67
+
68
+ public async create(loginUser: LoginUser, dbTransaction?: any) {
69
+ //This method will create a new joint hirer record.
70
+ try {
71
+ //Part 1: Check Privilege
72
+ const systemCode =
73
+ ApplicationConfig.getComponentConfigValue('system-code');
74
+ const isPrivileged = await loginUser.checkPrivileges(
75
+ systemCode,
76
+ 'JointHirer - Create',
77
+ );
78
+
79
+ if (!isPrivileged) {
80
+ throw new ClassError(
81
+ 'JointHirer',
82
+ 'JointHirerErrMsg00',
83
+ "You do not have 'JointHirer - Create' privilege.",
84
+ );
85
+ }
86
+
87
+ //Part 2: Insert Joint Hirer Record
88
+ //Check if this.RentalId, this.CustomerId, this.CustomerType have value otherwise throw new ClassError with below params
89
+ if (!this.RentalId || !this.CustomerId || !this.CustomerType) {
90
+ throw new ClassError(
91
+ 'JointHirer',
92
+ 'JointHirerErrMsg03',
93
+ 'RentalId, CustomerId and CustomerType are required.',
94
+ );
95
+ }
96
+
97
+ //Set other attributes
98
+ this.ObjectId = this.createId();
99
+ this.CreatedById = loginUser.ObjectId;
100
+ this.CreatedAt = new Date();
101
+ this.UpdatedById = loginUser.ObjectId;
102
+ this.UpdatedAt = new Date();
103
+
104
+ const entityValueAfter: IJointHirerAttr = {
105
+ HirerId: this.HirerId,
106
+ RentalId: this.RentalId,
107
+ CustomerId: this.CustomerId,
108
+ CustomerType: this.CustomerType,
109
+ CreatedById: this.CreatedById,
110
+ CreatedAt: this.CreatedAt,
111
+ UpdatedById: this.UpdatedById,
112
+ UpdatedAt: this.UpdatedAt,
113
+ };
114
+
115
+ //Call repo class create method by passing the class attributes and db transaction.
116
+ await JointHirer._Repository.create(entityValueAfter, {
117
+ transaction: dbTransaction,
118
+ });
119
+
120
+ //Part 4: Record Create JointHirer Activity
121
+ const activity = new Activity();
122
+ activity.ObjectId = this._createId();
123
+ activity.Action = ActionEnum.ADD;
124
+ activity.Description = 'Add Joint Hirer';
125
+ activity.EntityId = this.ObjectId;
126
+ activity.EntityType = this.ObjectType;
127
+ activity.EntityValueBefore = JSON.stringify({});
128
+ activity.EntityValueAfter = JSON.stringify(entityValueAfter);
129
+
130
+ await activity.create(loginUser.ObjectId, dbTransaction);
131
+
132
+ return this;
133
+ } catch (error) {
134
+ throw error;
135
+ }
136
+ }
137
+ }
@@ -8,6 +8,8 @@ import { RentalPrice } from '../rental-price/rental-price';
8
8
  import { Op } from 'sequelize';
9
9
  import { ActionEnum, Activity } from '@tomei/activity-history';
10
10
  import { IRentalFindAllSearchAttr } from '../../interfaces/rental-find-all-search-attr.interface';
11
+ import { RentalAccountTypeEnum } from '../../enum/account-type.enum';
12
+ import { JointHirer } from '../joint-hirer/joint-hirer';
11
13
 
12
14
  export class Rental extends ObjectBase {
13
15
  ObjectId: string;
@@ -24,13 +26,15 @@ export class Rental extends ObjectBase {
24
26
  CancelRemarks: string;
25
27
  TerminateRemarks: string;
26
28
  AgreementNo: string;
29
+ AccountType: RentalAccountTypeEnum;
30
+ JointHirers: JointHirer[] = [];
27
31
  private _Status: RentalStatusEnum;
28
32
  private _EscheatmentYN: string = 'N';
29
33
  private _CreatedById: string;
30
34
  private _CreatedAt: Date;
31
35
  private _UpdatedById: string;
32
36
  private _UpdatedAt: Date;
33
- private static _Repo = new RentalRepository();
37
+ protected static _Repo = new RentalRepository();
34
38
 
35
39
  get RentalId(): string {
36
40
  return this.ObjectId;
@@ -68,7 +72,7 @@ export class Rental extends ObjectBase {
68
72
  this._Status = RentalStatusEnum.TERMINATED;
69
73
  }
70
74
 
71
- private constructor(rentalAttr?: IRentalAttr) {
75
+ protected constructor(rentalAttr?: IRentalAttr) {
72
76
  super();
73
77
  if (rentalAttr) {
74
78
  this.RentalId = rentalAttr.RentalId;
@@ -82,6 +86,7 @@ export class Rental extends ObjectBase {
82
86
  this.CancelRemarks = rentalAttr.CancelRemarks;
83
87
  this.TerminateRemarks = rentalAttr.TerminateRemarks;
84
88
  this.AgreementNo = rentalAttr.AgreementNo;
89
+ this.AccountType = rentalAttr.AccountType;
85
90
  this._Status = rentalAttr.Status;
86
91
  this._EscheatmentYN = rentalAttr.EscheatmentYN;
87
92
  this._CreatedById = rentalAttr.CreatedById;
@@ -124,6 +129,7 @@ export class Rental extends ObjectBase {
124
129
  public async create(
125
130
  rentalPrice: RentalPrice,
126
131
  loginUser: LoginUser,
132
+ jointHirers?: JointHirer[],
127
133
  dbTransaction?: any,
128
134
  ): Promise<any> {
129
135
  try {
@@ -186,6 +192,7 @@ export class Rental extends ObjectBase {
186
192
  CancelRemarks: this.CancelRemarks,
187
193
  TerminateRemarks: this.TerminateRemarks,
188
194
  AgreementNo: this.AgreementNo,
195
+ AccountType: this.AccountType,
189
196
  Status: this.Status,
190
197
  EscheatmentYN: this.EscheatmentYN,
191
198
  CreatedById: this.CreatedById,
@@ -196,6 +203,15 @@ export class Rental extends ObjectBase {
196
203
 
197
204
  await Rental._Repo.create(data, dbTransaction);
198
205
 
206
+ //For every data inside Param.jointHirers, update the rentalId and call jointHirer.create
207
+ if (jointHirers) {
208
+ for (let i = 0; i < jointHirers.length; i++) {
209
+ jointHirers[i].RentalId = this.RentalId;
210
+ await jointHirers[i].create(loginUser, dbTransaction);
211
+ this.JointHirers.push(jointHirers[i]);
212
+ }
213
+ }
214
+
199
215
  /*Part 4: Record Create Rental Activity*/
200
216
  const activity = new Activity();
201
217
  activity.ActivityId = activity.createId();
@@ -458,6 +474,7 @@ export class Rental extends ObjectBase {
458
474
  CancelRemarks: this.CancelRemarks,
459
475
  TerminateRemarks: this.TerminateRemarks,
460
476
  AgreementNo: this.AgreementNo,
477
+ AccountType: this.AccountType,
461
478
  Status: this.Status,
462
479
  EscheatmentYN: this.EscheatmentYN,
463
480
  CreatedById: this.CreatedById,
@@ -484,6 +501,7 @@ export class Rental extends ObjectBase {
484
501
  CancelRemarks: this.CancelRemarks,
485
502
  TerminateRemarks: this.TerminateRemarks,
486
503
  AgreementNo: this.AgreementNo,
504
+ AccountType: this.AccountType,
487
505
  Status: this.Status,
488
506
  EscheatmentYN: this.EscheatmentYN,
489
507
  CreatedById: this.CreatedById,
package/src/database.ts CHANGED
@@ -2,6 +2,7 @@ import { Sequelize, SequelizeOptions } from 'sequelize-typescript';
2
2
  import { RentalModel } from './models/rental.entity';
3
3
  import { RentalPriceModel } from './models/rental-price.entity';
4
4
  import { BookingModel } from './models/booking.entity';
5
+ import { JointHirerModel } from './models/joint-hirer.entity';
5
6
 
6
7
  let sequelize: Sequelize;
7
8
 
@@ -13,6 +14,7 @@ function init(sequelizeOptions: SequelizeOptions) {
13
14
  RentalModel,
14
15
  RentalPriceModel,
15
16
  BookingModel,
17
+ JointHirerModel,
16
18
  ]);
17
19
  }
18
20
 
@@ -0,0 +1,4 @@
1
+ export enum RentalAccountTypeEnum {
2
+ SINGLE = 'Single',
3
+ JOINT = 'Joint',
4
+ }
package/src/enum/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { RentalStatusEnum } from './rental-status.enum';
2
2
  import { BookingStatusEnum } from './booking.enum';
3
+ import { RentalAccountTypeEnum } from './account-type.enum';
3
4
 
4
- export { RentalStatusEnum, BookingStatusEnum };
5
+ export { RentalStatusEnum, BookingStatusEnum, RentalAccountTypeEnum };
package/src/index.ts CHANGED
@@ -4,6 +4,8 @@ import { Rental } from './components/rental/rental';
4
4
  import { RentalPrice } from './components/rental-price/rental-price';
5
5
  import { Booking } from './components/booking/booking';
6
6
  import { BookingRepository } from './components/booking/booking.repository';
7
+ import { JointHirer } from './components/joint-hirer/joint-hirer';
8
+ import { JointHirerRepository } from './components/joint-hirer/joint-hirer.repository';
7
9
  import * as rentalDb from './database';
8
10
  export * from './interfaces';
9
11
  export * from './models';
@@ -17,4 +19,6 @@ export {
17
19
  Booking,
18
20
  BookingRepository,
19
21
  rentalDb,
22
+ JointHirer,
23
+ JointHirerRepository,
20
24
  };
@@ -0,0 +1,10 @@
1
+ export interface IJointHirerAttr {
2
+ HirerId: string;
3
+ RentalId: string;
4
+ CustomerId: string;
5
+ CustomerType: string;
6
+ CreatedById: string;
7
+ CreatedAt: Date;
8
+ UpdatedById: string;
9
+ UpdatedAt: Date;
10
+ }
@@ -1,4 +1,5 @@
1
1
  import { RentalStatusEnum } from '../enum/rental-status.enum';
2
+ import { RentalAccountTypeEnum } from '../enum/account-type.enum';
2
3
 
3
4
  export interface IRentalAttr {
4
5
  RentalId: string;
@@ -12,6 +13,7 @@ export interface IRentalAttr {
12
13
  CancelRemarks: string;
13
14
  TerminateRemarks: string;
14
15
  AgreementNo: string;
16
+ AccountType: RentalAccountTypeEnum;
15
17
  Status: RentalStatusEnum;
16
18
  EscheatmentYN: string;
17
19
  CreatedById: string;
@@ -1,5 +1,6 @@
1
1
  import { RentalModel } from './rental.entity';
2
2
  import { RentalPriceModel } from './rental-price.entity';
3
3
  import { BookingModel } from './booking.entity';
4
+ import { JointHirerModel } from './joint-hirer.entity';
4
5
 
5
- export { RentalModel, RentalPriceModel, BookingModel };
6
+ export { RentalModel, RentalPriceModel, BookingModel, JointHirerModel };
@@ -0,0 +1,63 @@
1
+ import {
2
+ Column,
3
+ DataType,
4
+ Table,
5
+ Model,
6
+ ForeignKey,
7
+ BelongsTo,
8
+ CreatedAt,
9
+ UpdatedAt,
10
+ } from 'sequelize-typescript';
11
+ import { RentalModel } from './rental.entity';
12
+
13
+ @Table({
14
+ tableName: 'rental_JointHirer',
15
+ })
16
+ export class JointHirerModel extends Model {
17
+ @Column({
18
+ primaryKey: true,
19
+ allowNull: false,
20
+ type: DataType.STRING(30),
21
+ })
22
+ HirerId: string;
23
+
24
+ @ForeignKey(() => RentalModel)
25
+ @Column({
26
+ allowNull: false,
27
+ type: DataType.STRING(30),
28
+ })
29
+ RentalId: string;
30
+
31
+ @Column({
32
+ allowNull: false,
33
+ type: DataType.STRING(30),
34
+ })
35
+ CustomerId: string;
36
+
37
+ @Column({
38
+ allowNull: false,
39
+ type: DataType.STRING(30),
40
+ })
41
+ CustomerType: string;
42
+
43
+ @Column({
44
+ allowNull: false,
45
+ type: DataType.STRING(30),
46
+ })
47
+ CreatedById: string;
48
+
49
+ @CreatedAt
50
+ CreatedAt: Date;
51
+
52
+ @Column({
53
+ allowNull: false,
54
+ type: DataType.STRING(30),
55
+ })
56
+ UpdatedById: string;
57
+
58
+ @UpdatedAt
59
+ UpdatedAt: Date;
60
+
61
+ @BelongsTo(() => RentalModel)
62
+ RentalPrice: RentalModel;
63
+ }
@@ -7,9 +7,12 @@ import {
7
7
  BelongsTo,
8
8
  CreatedAt,
9
9
  UpdatedAt,
10
+ HasMany,
10
11
  } from 'sequelize-typescript';
11
12
  import { RentalPriceModel } from './rental-price.entity';
12
13
  import { RentalStatusEnum } from '../enum/rental-status.enum';
14
+ import { JointHirerModel } from './joint-hirer.entity';
15
+ import { RentalAccountTypeEnum } from '../enum/account-type.enum';
13
16
 
14
17
  @Table({
15
18
  tableName: 'rental_Rental',
@@ -93,6 +96,12 @@ export class RentalModel extends Model {
93
96
  })
94
97
  AgreementNo: string;
95
98
 
99
+ @Column({
100
+ allowNull: false,
101
+ type: DataType.STRING(10),
102
+ })
103
+ AccountType: RentalAccountTypeEnum;
104
+
96
105
  @Column({
97
106
  allowNull: false,
98
107
  type: DataType.STRING(30),
@@ -113,4 +122,7 @@ export class RentalModel extends Model {
113
122
 
114
123
  @BelongsTo(() => RentalPriceModel)
115
124
  RentalPrice: RentalPriceModel;
125
+
126
+ @HasMany(() => JointHirerModel)
127
+ JointHirers: JointHirerModel[];
116
128
  }