@tomei/rental 0.17.1 → 0.17.3-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.
Files changed (140) hide show
  1. package/.husky/commit-msg +0 -6
  2. package/dist/src/components/agreement-signature/hirer-signature.d.ts +27 -0
  3. package/dist/src/components/agreement-signature/hirer-signature.js +112 -0
  4. package/dist/src/components/agreement-signature/hirer-signature.js.map +1 -0
  5. package/dist/src/components/agreement-signature/hirer-signature.repository.d.ts +8 -0
  6. package/dist/src/components/agreement-signature/hirer-signature.repository.js +67 -0
  7. package/dist/src/components/agreement-signature/hirer-signature.repository.js.map +1 -0
  8. package/dist/src/components/hirer-change-request-new-hirer/hirer-change-request-new-hirer.d.ts +32 -0
  9. package/dist/src/components/hirer-change-request-new-hirer/hirer-change-request-new-hirer.js +121 -0
  10. package/dist/src/components/hirer-change-request-new-hirer/hirer-change-request-new-hirer.js.map +1 -0
  11. package/dist/src/components/hirer-change-request-new-hirer/hirer-change-request-new-hirer.repository.d.ts +9 -0
  12. package/dist/src/components/hirer-change-request-new-hirer/hirer-change-request-new-hirer.repository.js +79 -0
  13. package/dist/src/components/hirer-change-request-new-hirer/hirer-change-request-new-hirer.repository.js.map +1 -0
  14. package/dist/src/components/hirer-change-request-remove-hirer/hirer-change-request-remove-hirer.d.ts +22 -0
  15. package/dist/src/components/hirer-change-request-remove-hirer/hirer-change-request-remove-hirer.js +104 -0
  16. package/dist/src/components/hirer-change-request-remove-hirer/hirer-change-request-remove-hirer.js.map +1 -0
  17. package/dist/src/components/hirer-change-request-remove-hirer/hirer-change-request-remove-hirer.repository.d.ts +9 -0
  18. package/dist/src/components/hirer-change-request-remove-hirer/hirer-change-request-remove-hirer.repository.js +80 -0
  19. package/dist/src/components/hirer-change-request-remove-hirer/hirer-change-request-remove-hirer.repository.js.map +1 -0
  20. package/dist/src/components/hirer-change-request-signature/hirer-change-request-signature.d.ts +30 -0
  21. package/dist/src/components/hirer-change-request-signature/hirer-change-request-signature.js +225 -0
  22. package/dist/src/components/hirer-change-request-signature/hirer-change-request-signature.js.map +1 -0
  23. package/dist/src/components/hirer-change-request-signature/hirer-change-request-signature.repository.d.ts +9 -0
  24. package/dist/src/components/hirer-change-request-signature/hirer-change-request-signature.repository.js +80 -0
  25. package/dist/src/components/hirer-change-request-signature/hirer-change-request-signature.repository.js.map +1 -0
  26. package/dist/src/components/hirer-signature/hirer-signature.d.ts +27 -0
  27. package/dist/src/components/hirer-signature/hirer-signature.js +112 -0
  28. package/dist/src/components/hirer-signature/hirer-signature.js.map +1 -0
  29. package/dist/src/components/hirer-signature/hirer-signature.repository.d.ts +8 -0
  30. package/dist/src/components/hirer-signature/hirer-signature.repository.js +67 -0
  31. package/dist/src/components/hirer-signature/hirer-signature.repository.js.map +1 -0
  32. package/dist/src/components/joint-hirer/joint-hirer.d.ts +3 -0
  33. package/dist/src/components/joint-hirer/joint-hirer.js +46 -0
  34. package/dist/src/components/joint-hirer/joint-hirer.js.map +1 -1
  35. package/dist/src/components/rental/rental.d.ts +1 -0
  36. package/dist/src/components/rental/rental.js +28 -0
  37. package/dist/src/components/rental/rental.js.map +1 -1
  38. package/dist/src/components/rental-hirer-change-request/rental-hirer-change-request.d.ts +70 -0
  39. package/dist/src/components/rental-hirer-change-request/rental-hirer-change-request.js +570 -0
  40. package/dist/src/components/rental-hirer-change-request/rental-hirer-change-request.js.map +1 -0
  41. package/dist/src/components/rental-hirer-change-request/rental-hirer-change-request.repository.d.ts +9 -0
  42. package/dist/src/components/rental-hirer-change-request/rental-hirer-change-request.repository.js +79 -0
  43. package/dist/src/components/rental-hirer-change-request/rental-hirer-change-request.repository.js.map +1 -0
  44. package/dist/src/database.js +8 -0
  45. package/dist/src/database.js.map +1 -1
  46. package/dist/src/enum/hirer-signature-status.enum.d.ts +4 -0
  47. package/dist/src/enum/hirer-signature-status.enum.js +9 -0
  48. package/dist/src/enum/hirer-signature-status.enum.js.map +1 -0
  49. package/dist/src/enum/index.d.ts +4 -1
  50. package/dist/src/enum/index.js +7 -1
  51. package/dist/src/enum/index.js.map +1 -1
  52. package/dist/src/enum/rental-hirer-change-request-hirer-role.d.ts +4 -0
  53. package/dist/src/enum/rental-hirer-change-request-hirer-role.js +9 -0
  54. package/dist/src/enum/rental-hirer-change-request-hirer-role.js.map +1 -0
  55. package/dist/src/enum/rental-hirer-change-request-status.d.ts +7 -0
  56. package/dist/src/enum/rental-hirer-change-request-status.js +12 -0
  57. package/dist/src/enum/rental-hirer-change-request-status.js.map +1 -0
  58. package/dist/src/enum/rental-hirer-change-request-type.d.ts +4 -0
  59. package/dist/src/enum/rental-hirer-change-request-type.js +9 -0
  60. package/dist/src/enum/rental-hirer-change-request-type.js.map +1 -0
  61. package/dist/src/index.d.ts +9 -1
  62. package/dist/src/index.js +17 -1
  63. package/dist/src/index.js.map +1 -1
  64. package/dist/src/interfaces/hirer-change-request-new-hirer-attr.interface.d.ts +15 -0
  65. package/dist/src/interfaces/hirer-change-request-new-hirer-attr.interface.js +3 -0
  66. package/dist/src/interfaces/hirer-change-request-new-hirer-attr.interface.js.map +1 -0
  67. package/dist/src/interfaces/hirer-change-request-remove-hirer-attr.interface.d.ts +5 -0
  68. package/dist/src/interfaces/hirer-change-request-remove-hirer-attr.interface.js +3 -0
  69. package/dist/src/interfaces/hirer-change-request-remove-hirer-attr.interface.js.map +1 -0
  70. package/dist/src/interfaces/hirer-change-request-signature-attr.interface.d.ts +14 -0
  71. package/dist/src/interfaces/hirer-change-request-signature-attr.interface.js +3 -0
  72. package/dist/src/interfaces/hirer-change-request-signature-attr.interface.js.map +1 -0
  73. package/dist/src/interfaces/hirer-signature-attr.interface.d.ts +14 -0
  74. package/dist/src/interfaces/hirer-signature-attr.interface.js +3 -0
  75. package/dist/src/interfaces/hirer-signature-attr.interface.js.map +1 -0
  76. package/dist/src/interfaces/index.d.ts +6 -1
  77. package/dist/src/interfaces/joint-hirer-attr.interface.d.ts +1 -0
  78. package/dist/src/interfaces/rental-hirer-change-request.attr.interface.d.ts +16 -0
  79. package/dist/src/interfaces/rental-hirer-change-request.attr.interface.js +3 -0
  80. package/dist/src/interfaces/rental-hirer-change-request.attr.interface.js.map +1 -0
  81. package/dist/src/interfaces/rental-hirer-change-request.update.interface.d.ts +4 -0
  82. package/dist/src/interfaces/rental-hirer-change-request.update.interface.js +3 -0
  83. package/dist/src/interfaces/rental-hirer-change-request.update.interface.js.map +1 -0
  84. package/dist/src/models/hirer-change-request-new-hirer.entity.d.ts +19 -0
  85. package/dist/src/models/hirer-change-request-new-hirer.entity.js +121 -0
  86. package/dist/src/models/hirer-change-request-new-hirer.entity.js.map +1 -0
  87. package/dist/src/models/hirer-change-request-remove-hirer.entity.d.ts +11 -0
  88. package/dist/src/models/hirer-change-request-remove-hirer.entity.js +57 -0
  89. package/dist/src/models/hirer-change-request-remove-hirer.entity.js.map +1 -0
  90. package/dist/src/models/hirer-change-request-signature.entity.d.ts +18 -0
  91. package/dist/src/models/hirer-change-request-signature.entity.js +101 -0
  92. package/dist/src/models/hirer-change-request-signature.entity.js.map +1 -0
  93. package/dist/src/models/hirer-signature.entity.d.ts +16 -0
  94. package/dist/src/models/hirer-signature.entity.js +100 -0
  95. package/dist/src/models/hirer-signature.entity.js.map +1 -0
  96. package/dist/src/models/index.d.ts +5 -1
  97. package/dist/src/models/index.js +9 -1
  98. package/dist/src/models/index.js.map +1 -1
  99. package/dist/src/models/joint-hirer.entity.d.ts +1 -0
  100. package/dist/src/models/joint-hirer.entity.js +12 -0
  101. package/dist/src/models/joint-hirer.entity.js.map +1 -1
  102. package/dist/src/models/rental-hirer-change-request.entity.d.ts +22 -0
  103. package/dist/src/models/rental-hirer-change-request.entity.js +108 -0
  104. package/dist/src/models/rental-hirer-change-request.entity.js.map +1 -0
  105. package/dist/tsconfig.tsbuildinfo +1 -1
  106. package/migrations/20250529092130-add-status-to-joint-hirer.js +19 -0
  107. package/migrations/hirer-change-request-new-hirer-migration.js +72 -0
  108. package/migrations/hirer-change-request-remove-hirer-migration.js +39 -0
  109. package/migrations/hirer-change-request-signature-migration.js +65 -0
  110. package/migrations/rental-hirer-change-request-migrations.js +64 -0
  111. package/package.json +3 -3
  112. package/src/components/hirer-change-request-new-hirer/hirer-change-request-new-hirer.repository.ts +64 -0
  113. package/src/components/hirer-change-request-new-hirer/hirer-change-request-new-hirer.ts +153 -0
  114. package/src/components/hirer-change-request-remove-hirer/hirer-change-request-remove-hirer.repository.ts +65 -0
  115. package/src/components/hirer-change-request-remove-hirer/hirer-change-request-remove-hirer.ts +134 -0
  116. package/src/components/hirer-change-request-signature/hirer-change-request-signature.repository.ts +65 -0
  117. package/src/components/hirer-change-request-signature/hirer-change-request-signature.ts +272 -0
  118. package/src/components/joint-hirer/joint-hirer.ts +52 -0
  119. package/src/components/rental/rental.ts +32 -0
  120. package/src/components/rental-hirer-change-request/rental-hirer-change-request.repository.ts +64 -0
  121. package/src/components/rental-hirer-change-request/rental-hirer-change-request.ts +919 -0
  122. package/src/database.ts +8 -0
  123. package/src/enum/index.ts +6 -0
  124. package/src/enum/rental-hirer-change-request-hirer-role.ts +4 -0
  125. package/src/enum/rental-hirer-change-request-status.ts +7 -0
  126. package/src/enum/rental-hirer-change-request-type.ts +4 -0
  127. package/src/index.ts +16 -0
  128. package/src/interfaces/hirer-change-request-new-hirer-attr.interface.ts +15 -0
  129. package/src/interfaces/hirer-change-request-remove-hirer-attr.interface.ts +5 -0
  130. package/src/interfaces/hirer-change-request-signature-attr.interface.ts +15 -0
  131. package/src/interfaces/index.ts +10 -0
  132. package/src/interfaces/joint-hirer-attr.interface.ts +1 -0
  133. package/src/interfaces/rental-hirer-change-request.attr.interface.ts +17 -0
  134. package/src/interfaces/rental-hirer-change-request.update.interface.ts +4 -0
  135. package/src/models/hirer-change-request-new-hirer.entity.ts +102 -0
  136. package/src/models/hirer-change-request-remove-hirer.entity.ts +47 -0
  137. package/src/models/hirer-change-request-signature.entity.ts +86 -0
  138. package/src/models/index.ts +8 -0
  139. package/src/models/joint-hirer.entity.ts +7 -0
  140. package/src/models/rental-hirer-change-request.entity.ts +93 -0
@@ -0,0 +1,65 @@
1
+ import { RepositoryBase, IRepositoryBase } from '@tomei/general';
2
+ import { HirerChangeRequestSignatureModel } from '../../models/hirer-change-request-signature.entity';
3
+
4
+ export class HirerChangeRequestSignatureRepository
5
+ extends RepositoryBase<HirerChangeRequestSignatureModel>
6
+ implements IRepositoryBase<HirerChangeRequestSignatureModel>
7
+ {
8
+ constructor() {
9
+ super(HirerChangeRequestSignatureModel);
10
+ }
11
+
12
+ async findByPk(
13
+ id: string,
14
+ transaction?: any,
15
+ ): Promise<HirerChangeRequestSignatureModel | null> {
16
+ try {
17
+ const result = await HirerChangeRequestSignatureModel.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(signatureId: string, dbTransaction?: any) {
28
+ try {
29
+ const options = {
30
+ where: {
31
+ SignatureId: signatureId,
32
+ },
33
+ transaction: dbTransaction,
34
+ };
35
+ await HirerChangeRequestSignatureModel.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 hcrSignatures: any;
44
+ if (options) {
45
+ hcrSignatures =
46
+ await HirerChangeRequestSignatureModel.findAndCountAll(options);
47
+ } else {
48
+ hcrSignatures =
49
+ await HirerChangeRequestSignatureModel.findAndCountAll();
50
+ }
51
+ return hcrSignatures;
52
+ } catch (error) {
53
+ throw new Error(`An Error occured when retriving : ${error.message}`);
54
+ }
55
+ }
56
+
57
+ async findAll(options: any): Promise<HirerChangeRequestSignatureModel[]> {
58
+ try {
59
+ const result = await HirerChangeRequestSignatureModel.findAll(options);
60
+ return result;
61
+ } catch (error) {
62
+ throw new Error(`An Error occured when fetching : ${error.message}`);
63
+ }
64
+ }
65
+ }
@@ -0,0 +1,272 @@
1
+ import { ClassError, ObjectBase } from '@tomei/general';
2
+ import { HirerChangeRequestSignatureRepository } from './hirer-change-request-signature.repository';
3
+ import { LoginUser } from '@tomei/sso';
4
+ import { ActionEnum, Activity } from '@tomei/activity-history';
5
+ import { HirerChangeRequestHirerRoleEnum } from '../../enum/rental-hirer-change-request-hirer-role';
6
+ import { IHirerChangeRequestSignatureAttr } from '../../interfaces';
7
+
8
+ export class HirerChangeRequestSignature
9
+ extends ObjectBase
10
+ implements IHirerChangeRequestSignatureAttr
11
+ {
12
+ ObjectId: string;
13
+ ObjectName: string;
14
+ ObjectType: string = 'HirerChangeRequestSignature';
15
+ TableName: string = 'hirerChangeRequest_Signature';
16
+
17
+ RequestId: string;
18
+ CustomerId: string;
19
+ JointHirerId: string;
20
+ HirerType: HirerChangeRequestHirerRoleEnum;
21
+ SignedAt: Date;
22
+ Method: string;
23
+ Remarks: string;
24
+ CreatedAt: Date;
25
+ UpdatedAt: Date;
26
+ UpdatedById: string;
27
+
28
+ protected static _Repository = new HirerChangeRequestSignatureRepository();
29
+
30
+ protected constructor(attr?: IHirerChangeRequestSignatureAttr) {
31
+ super();
32
+ if (attr) {
33
+ this.SignatureId = attr.SignatureId;
34
+ this.RequestId = attr.RequestId;
35
+ this.CustomerId = attr.CustomerId;
36
+ this.JointHirerId = attr.JointHirerId;
37
+ this.SignedAt = attr.SignedAt;
38
+ this.Method = attr.Method;
39
+ this.HirerType = attr.HirerType;
40
+ this.Remarks = attr.Remarks;
41
+ this.CreatedAt = attr.CreatedAt;
42
+ this.UpdatedAt = attr.UpdatedAt;
43
+ this.UpdatedById = attr.UpdatedById;
44
+ }
45
+ }
46
+
47
+ get SignatureId(): string {
48
+ return this.ObjectId;
49
+ }
50
+
51
+ set SignatureId(value: string) {
52
+ this.ObjectId = value;
53
+ }
54
+
55
+ public static async init(signatureId?: string, dbTransaction?: any) {
56
+ try {
57
+ if (signatureId) {
58
+ const hirerChangeReqSignature =
59
+ await HirerChangeRequestSignature._Repository.findByPk(
60
+ signatureId,
61
+ dbTransaction,
62
+ );
63
+ if (hirerChangeReqSignature) {
64
+ return new HirerChangeRequestSignature(
65
+ hirerChangeReqSignature.get({ plain: true }),
66
+ );
67
+ } else {
68
+ throw new ClassError(
69
+ 'HirerChangeRequestSignature',
70
+ 'HirerChangeRequestSignatureErrMsg00',
71
+ 'HirerChangeRequestSignature not found',
72
+ );
73
+ }
74
+ }
75
+ return new HirerChangeRequestSignature();
76
+ } catch (error) {
77
+ throw error;
78
+ }
79
+ }
80
+
81
+ toJSON(): IHirerChangeRequestSignatureAttr {
82
+ return {
83
+ SignatureId: this.SignatureId,
84
+ RequestId: this.RequestId,
85
+ CustomerId: this.CustomerId,
86
+ JointHirerId: this.JointHirerId,
87
+ HirerType: this.HirerType,
88
+ SignedAt: this.SignedAt,
89
+ Method: this.Method,
90
+ Remarks: this.Remarks,
91
+ CreatedAt: this.CreatedAt,
92
+ UpdatedAt: this.UpdatedAt,
93
+ UpdatedById: this.UpdatedById,
94
+ };
95
+ }
96
+
97
+ public async create(loginUser: LoginUser, dbTransaction?: any) {
98
+ //This method will create a new Hirer Change Request Signature.
99
+ try {
100
+ // Part 1: Create Hirer Change Request Signature Records
101
+ // 1.1 Set other attributes
102
+ this.ObjectId = this.createId();
103
+ this.CreatedAt = new Date();
104
+ this.UpdatedById = loginUser.ObjectId;
105
+ this.UpdatedAt = new Date();
106
+
107
+ // 1.2 Set Entity value after
108
+ const entityValueAfter: IHirerChangeRequestSignatureAttr = {
109
+ SignatureId: this.SignatureId,
110
+ RequestId: this.RequestId,
111
+ CustomerId: this.CustomerId,
112
+ JointHirerId: this.JointHirerId,
113
+ HirerType: this.HirerType,
114
+ SignedAt: this.SignedAt,
115
+ Method: this.Method,
116
+ Remarks: this.Remarks,
117
+ CreatedAt: this.CreatedAt,
118
+ UpdatedAt: this.UpdatedAt,
119
+ UpdatedById: this.UpdatedById,
120
+ };
121
+
122
+ // 1.3 Call repo class create method by passing the class attributes and db transaction.
123
+ await HirerChangeRequestSignature._Repository.create(entityValueAfter, {
124
+ transaction: dbTransaction,
125
+ });
126
+
127
+ //Part 2: Record Create Hirer Change Request Signature Activity
128
+ const activity = new Activity();
129
+ activity.ObjectId = this._createId();
130
+ activity.Action = ActionEnum.CREATE;
131
+ activity.Description = 'Add Hirer Change Request Signature';
132
+ activity.EntityId = this.ObjectId;
133
+ activity.EntityType = this.ObjectType;
134
+ activity.EntityValueBefore = JSON.stringify({});
135
+ activity.EntityValueAfter = JSON.stringify(entityValueAfter);
136
+
137
+ await activity.create(loginUser.ObjectId, dbTransaction);
138
+
139
+ return this;
140
+ } catch (error) {
141
+ throw error;
142
+ }
143
+ }
144
+
145
+ public async update(loginUser: LoginUser, dbTransaction: any) {
146
+ try {
147
+ // Part 1: Update Hirer Change Request Signature Records
148
+ // 1.1 Set entityValueBefore
149
+ const entityValueBefore: IHirerChangeRequestSignatureAttr = {
150
+ SignatureId: this.SignatureId,
151
+ RequestId: this.RequestId,
152
+ CustomerId: this.CustomerId,
153
+ JointHirerId: this.JointHirerId,
154
+ HirerType: this.HirerType,
155
+ SignedAt: this.SignedAt,
156
+ Method: this.Method,
157
+ Remarks: this.Remarks,
158
+ CreatedAt: this.CreatedAt,
159
+ UpdatedAt: this.UpdatedAt,
160
+ UpdatedById: this.UpdatedById,
161
+ };
162
+
163
+ // 1.2 Update SignedAt UpdatedById, and UpdateAt
164
+ this.SignedAt = new Date();
165
+ this.UpdatedById = loginUser.ObjectId;
166
+ this.UpdatedAt = new Date();
167
+
168
+ // 1.3 Set Entity value after
169
+ const entityValueAfter: IHirerChangeRequestSignatureAttr = {
170
+ SignatureId: this.SignatureId,
171
+ RequestId: this.RequestId,
172
+ CustomerId: this.CustomerId,
173
+ JointHirerId: this.JointHirerId,
174
+ HirerType: this.HirerType,
175
+ SignedAt: this.SignedAt,
176
+ Method: this.Method,
177
+ Remarks: this.Remarks,
178
+ CreatedAt: this.CreatedAt,
179
+ UpdatedAt: this.UpdatedAt,
180
+ UpdatedById: this.UpdatedById,
181
+ };
182
+
183
+ // 1.3 Call repo class create method by passing the class attributes and db transaction.
184
+ await HirerChangeRequestSignature._Repository.update(entityValueAfter, {
185
+ where: {
186
+ SignatureId: this.SignatureId,
187
+ },
188
+ transaction: dbTransaction,
189
+ });
190
+
191
+ //Part 2: Record Create Hirer Change Request Activity
192
+ const activity = new Activity();
193
+ activity.ObjectId = this._createId();
194
+ activity.Action = ActionEnum.UPDATE;
195
+ activity.Description = 'Update Hirer Change Request Signature';
196
+ activity.EntityId = this.ObjectId;
197
+ activity.EntityType = this.ObjectType;
198
+ activity.EntityValueBefore = JSON.stringify(entityValueBefore);
199
+ activity.EntityValueAfter = JSON.stringify(entityValueAfter);
200
+
201
+ await activity.create(loginUser.ObjectId, dbTransaction);
202
+
203
+ return this;
204
+ } catch (error) {
205
+ throw error;
206
+ }
207
+ }
208
+
209
+ public async markSigned(loginUser: LoginUser, dbTransaction: any) {
210
+ try {
211
+ // Part 1: Update Hirer Change Request Signature Records
212
+ // 1.1 Set entityValueBefore
213
+ const entityValueBefore: IHirerChangeRequestSignatureAttr = {
214
+ SignatureId: this.SignatureId,
215
+ RequestId: this.RequestId,
216
+ CustomerId: this.CustomerId,
217
+ JointHirerId: this.JointHirerId,
218
+ HirerType: this.HirerType,
219
+ SignedAt: this.SignedAt,
220
+ Method: this.Method,
221
+ Remarks: this.Remarks,
222
+ CreatedAt: this.CreatedAt,
223
+ UpdatedAt: this.UpdatedAt,
224
+ UpdatedById: this.UpdatedById,
225
+ };
226
+
227
+ // 1.2 Update SignedAt UpdatedById, and UpdateAt
228
+ this.SignedAt = new Date();
229
+ this.UpdatedById = loginUser.ObjectId;
230
+ this.UpdatedAt = new Date();
231
+
232
+ // 1.3 Set Entity value after
233
+ const entityValueAfter: IHirerChangeRequestSignatureAttr = {
234
+ SignatureId: this.SignatureId,
235
+ RequestId: this.RequestId,
236
+ CustomerId: this.CustomerId,
237
+ JointHirerId: this.JointHirerId,
238
+ HirerType: this.HirerType,
239
+ SignedAt: this.SignedAt,
240
+ Method: this.Method,
241
+ Remarks: this.Remarks,
242
+ CreatedAt: this.CreatedAt,
243
+ UpdatedAt: this.UpdatedAt,
244
+ UpdatedById: this.UpdatedById,
245
+ };
246
+
247
+ // 1.3 Call repo class create method by passing the class attributes and db transaction.
248
+ await HirerChangeRequestSignature._Repository.update(entityValueAfter, {
249
+ where: {
250
+ SignatureId: this.SignatureId,
251
+ },
252
+ transaction: dbTransaction,
253
+ });
254
+
255
+ //Part 2: Record Create Hirer Change Request Activity
256
+ const activity = new Activity();
257
+ activity.ObjectId = this._createId();
258
+ activity.Action = ActionEnum.UPDATE;
259
+ activity.Description = 'Mark Hirer Change Request Signature as Signed';
260
+ activity.EntityId = this.ObjectId;
261
+ activity.EntityType = this.ObjectType;
262
+ activity.EntityValueBefore = JSON.stringify(entityValueBefore);
263
+ activity.EntityValueAfter = JSON.stringify(entityValueAfter);
264
+
265
+ await activity.create(loginUser.ObjectId, dbTransaction);
266
+
267
+ return this;
268
+ } catch (error) {
269
+ throw error;
270
+ }
271
+ }
272
+ }
@@ -13,6 +13,7 @@ export class JointHirer extends ObjectBase {
13
13
  RentalId: string;
14
14
  CustomerId: string;
15
15
  CustomerType: string;
16
+ Status = 'Active'; // Default status
16
17
  CreatedById: string;
17
18
  CreatedAt: Date;
18
19
  UpdatedById: string;
@@ -35,6 +36,7 @@ export class JointHirer extends ObjectBase {
35
36
  this.RentalId = jointHirerAttr.RentalId;
36
37
  this.CustomerId = jointHirerAttr.CustomerId;
37
38
  this.CustomerType = jointHirerAttr.CustomerType;
39
+ this.Status = jointHirerAttr.Status;
38
40
  this.CreatedById = jointHirerAttr.CreatedById;
39
41
  this.CreatedAt = jointHirerAttr.CreatedAt;
40
42
  this.UpdatedById = jointHirerAttr.UpdatedById;
@@ -42,6 +44,20 @@ export class JointHirer extends ObjectBase {
42
44
  }
43
45
  }
44
46
 
47
+ toJSON(): IJointHirerAttr {
48
+ return {
49
+ HirerId: this.HirerId,
50
+ RentalId: this.RentalId,
51
+ CustomerId: this.CustomerId,
52
+ CustomerType: this.CustomerType,
53
+ Status: this.Status,
54
+ CreatedById: this.CreatedById,
55
+ CreatedAt: this.CreatedAt,
56
+ UpdatedById: this.UpdatedById,
57
+ UpdatedAt: this.UpdatedAt,
58
+ };
59
+ }
60
+
45
61
  public static async init(hirerId?: string, dbTransaction?: any) {
46
62
  try {
47
63
  if (hirerId) {
@@ -106,6 +122,7 @@ export class JointHirer extends ObjectBase {
106
122
  RentalId: this.RentalId,
107
123
  CustomerId: this.CustomerId,
108
124
  CustomerType: this.CustomerType,
125
+ Status: this.Status,
109
126
  CreatedById: this.CreatedById,
110
127
  CreatedAt: this.CreatedAt,
111
128
  UpdatedById: this.UpdatedById,
@@ -134,4 +151,39 @@ export class JointHirer extends ObjectBase {
134
151
  throw error;
135
152
  }
136
153
  }
154
+
155
+ public async remove(loginUser: LoginUser, dbTransaction?: any) {
156
+ try {
157
+ //Mark Joint Hirer as Inactive
158
+ const entityValueBefore: IJointHirerAttr = this.toJSON();
159
+ this.Status = 'Inactive'; // Set status to 'Inactive' instead of deleting the record
160
+ this.UpdatedById = loginUser.ObjectId;
161
+ this.UpdatedAt = new Date();
162
+ const entityValueAfter: IJointHirerAttr = this.toJSON();
163
+
164
+ // Part 2: Remove Joint Hirer Record
165
+ await JointHirer._Repository.update(entityValueAfter, {
166
+ where: {
167
+ HirerId: this.HirerId,
168
+ },
169
+ transaction: dbTransaction,
170
+ });
171
+
172
+ // Part 3: Record Remove JointHirer Activity
173
+ const activity = new Activity();
174
+ activity.ObjectId = this._createId();
175
+ activity.Action = ActionEnum.UPDATE;
176
+ activity.Description = 'Mark Joint Hirer as Inactive';
177
+ activity.EntityId = this.ObjectId;
178
+ activity.EntityType = this.ObjectType;
179
+ activity.EntityValueBefore = JSON.stringify(entityValueBefore);
180
+ activity.EntityValueAfter = JSON.stringify(entityValueAfter);
181
+
182
+ await activity.create(loginUser.ObjectId, dbTransaction);
183
+
184
+ return this;
185
+ } catch (error) {
186
+ throw error;
187
+ }
188
+ }
137
189
  }
@@ -728,6 +728,38 @@ export class Rental extends ObjectBase {
728
728
  }
729
729
  }
730
730
 
731
+ async getJointHirers(dbTransaction: any) {
732
+ try {
733
+ if (!this.RentalId) {
734
+ throw new ClassError('Rental', 'RentalErrMsg01', 'RentalId is missing');
735
+ }
736
+ if (this.AccountType !== RentalAccountTypeEnum.JOINT) {
737
+ throw new ClassError(
738
+ 'Rental',
739
+ 'RentalErrMsg07',
740
+ 'This rental does not have joint hirers.',
741
+ );
742
+ }
743
+
744
+ const jointHirers = await Rental._JointHirerRepo.findAll({
745
+ where: {
746
+ RentalId: this.RentalId,
747
+ },
748
+ transaction: dbTransaction,
749
+ });
750
+ // Map the jointHirers to JointHirer instances
751
+ const jointHirerInstances = Promise.all(
752
+ jointHirers.map(async (hirer: JointHirerModel) => {
753
+ return await JointHirer.init(hirer.HirerId, dbTransaction);
754
+ }),
755
+ );
756
+ return jointHirerInstances;
757
+ } catch (error) {
758
+ console.error('Error in getJointHirers:', error);
759
+ throw error;
760
+ }
761
+ }
762
+
731
763
  async getCustomerIds(loginUser: LoginUser, dbTransaction: any) {
732
764
  try {
733
765
  // Part 1: Privilege Checking
@@ -0,0 +1,64 @@
1
+ import { RepositoryBase, IRepositoryBase } from '@tomei/general';
2
+ import { RentalHirerChangeRequestModel } from '../../models/rental-hirer-change-request.entity';
3
+
4
+ export class RentalHirerChangeRequestRepository
5
+ extends RepositoryBase<RentalHirerChangeRequestModel>
6
+ implements IRepositoryBase<RentalHirerChangeRequestModel>
7
+ {
8
+ constructor() {
9
+ super(RentalHirerChangeRequestModel);
10
+ }
11
+
12
+ async findByPk(
13
+ id: string,
14
+ transaction?: any,
15
+ ): Promise<RentalHirerChangeRequestModel | null> {
16
+ try {
17
+ const result = await RentalHirerChangeRequestModel.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(requestId: string, dbTransaction?: any) {
28
+ try {
29
+ const options = {
30
+ where: {
31
+ RequestId: requestId,
32
+ },
33
+ transaction: dbTransaction,
34
+ };
35
+ await RentalHirerChangeRequestModel.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 =
46
+ await RentalHirerChangeRequestModel.findAndCountAll(options);
47
+ } else {
48
+ jointHirers = await RentalHirerChangeRequestModel.findAndCountAll();
49
+ }
50
+ return jointHirers;
51
+ } catch (error) {
52
+ throw new Error(`An Error occured when retriving : ${error.message}`);
53
+ }
54
+ }
55
+
56
+ async findAll(options: any): Promise<RentalHirerChangeRequestModel[]> {
57
+ try {
58
+ const result = await RentalHirerChangeRequestModel.findAll(options);
59
+ return result;
60
+ } catch (error) {
61
+ throw new Error(`An Error occured when fetching : ${error.message}`);
62
+ }
63
+ }
64
+ }