@tomei/rental 0.2.4 → 0.2.5

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 (72) hide show
  1. package/.commitlintrc.json +22 -22
  2. package/.eslintrc +16 -16
  3. package/.eslintrc.js +35 -35
  4. package/.husky/commit-msg +15 -15
  5. package/.husky/pre-commit +7 -7
  6. package/.prettierrc +4 -4
  7. package/Jenkinsfile +57 -57
  8. package/README.md +8 -8
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.js +17 -17
  11. package/dist/jest.config.d.ts +2 -0
  12. package/dist/jest.config.js +11 -0
  13. package/dist/jest.config.js.map +1 -0
  14. package/dist/migrations/rental-price-table-migration.d.ts +2 -0
  15. package/dist/migrations/rental-price-table-migration.js +43 -0
  16. package/dist/migrations/rental-price-table-migration.js.map +1 -0
  17. package/dist/migrations/rental-table-migrations.d.ts +2 -0
  18. package/dist/migrations/rental-table-migrations.js +95 -0
  19. package/dist/migrations/rental-table-migrations.js.map +1 -0
  20. package/dist/src/components/rental/rental.d.ts +35 -35
  21. package/dist/src/components/rental/rental.js +208 -208
  22. package/dist/src/components/rental/rental.js.map +1 -1
  23. package/dist/src/components/rental/rental.repository.d.ts +8 -8
  24. package/dist/src/components/rental/rental.repository.js +66 -66
  25. package/dist/src/components/rental-price/rental-price.d.ts +12 -12
  26. package/dist/src/components/rental-price/rental-price.js +71 -71
  27. package/dist/src/components/rental-price/rental-price.repository.d.ts +8 -8
  28. package/dist/src/components/rental-price/rental-price.repository.js +66 -66
  29. package/dist/src/database.d.ts +4 -4
  30. package/dist/src/database.js +19 -19
  31. package/dist/src/enum/index.d.ts +2 -2
  32. package/dist/src/enum/index.js +5 -5
  33. package/dist/src/enum/rental-status.enum.d.ts +6 -6
  34. package/dist/src/enum/rental-status.enum.js +10 -10
  35. package/dist/src/index.d.ts +9 -9
  36. package/dist/src/index.js +30 -30
  37. package/dist/src/interfaces/index.d.ts +4 -4
  38. package/dist/src/interfaces/index.js +2 -2
  39. package/dist/src/interfaces/rental-attr.interface.d.ts +20 -20
  40. package/dist/src/interfaces/rental-attr.interface.js +2 -2
  41. package/dist/src/interfaces/rental-find-all-search-attr.interface.d.ts +8 -8
  42. package/dist/src/interfaces/rental-find-all-search-attr.interface.js +2 -2
  43. package/dist/src/interfaces/rental-price-attr.interface.d.ts +7 -7
  44. package/dist/src/interfaces/rental-price-attr.interface.js +2 -2
  45. package/dist/src/models/index.d.ts +3 -3
  46. package/dist/src/models/index.js +7 -7
  47. package/dist/src/models/rental-price.entity.d.ts +8 -8
  48. package/dist/src/models/rental-price.entity.js +58 -58
  49. package/dist/src/models/rental.entity.d.ts +23 -23
  50. package/dist/src/models/rental.entity.js +138 -138
  51. package/dist/tsconfig.tsbuildinfo +1 -1
  52. package/jest.config.js +10 -10
  53. package/migrations/rental-price-table-migration.js +32 -32
  54. package/migrations/rental-table-migrations.js +84 -84
  55. package/package.json +71 -71
  56. package/src/components/rental/rental.repository.ts +51 -51
  57. package/src/components/rental/rental.ts +285 -285
  58. package/src/components/rental-price/rental-price.repository.ts +54 -54
  59. package/src/components/rental-price/rental-price.ts +89 -89
  60. package/src/database.ts +21 -21
  61. package/src/enum/index.ts +3 -3
  62. package/src/enum/rental-status.enum.ts +6 -6
  63. package/src/index.ts +16 -16
  64. package/src/interfaces/index.ts +5 -5
  65. package/src/interfaces/rental-attr.interface.ts +21 -21
  66. package/src/interfaces/rental-find-all-search-attr.interface.ts +9 -9
  67. package/src/interfaces/rental-price-attr.interface.ts +7 -7
  68. package/src/models/index.ts +4 -4
  69. package/src/models/rental-price.entity.ts +38 -38
  70. package/src/models/rental.entity.ts +114 -114
  71. package/tsconfig.build.json +5 -5
  72. package/tsconfig.json +23 -23
@@ -1,285 +1,285 @@
1
- import { IRentalAttr } from '../../interfaces/rental-attr.interface';
2
- import { RentalStatusEnum } from '../../enum/rental-status.enum';
3
- import { RentalRepository } from './rental.repository';
4
- import { ClassError } from '@tomei/general';
5
- import { ApplicationConfig } from '@tomei/config';
6
- import { LoginUser } from '@tomei/sso';
7
- import { RentalPrice } from '../rental-price/rental-price';
8
- import * as cuid from 'cuid';
9
- import { Op } from 'sequelize';
10
- import { ActionEnum, Activity } from '@tomei/activity-history';
11
- import { IRentalFindAllSearchAttr } from '../../interfaces/rental-find-all-search-attr.interface';
12
-
13
- export class Rental {
14
- RentalId: string;
15
- CustomerId: string;
16
- CustomerType: string;
17
- ItemId: string;
18
- ItemType: string;
19
- PriceId: string;
20
- StartDateTime: Date;
21
- EndDateTime: Date;
22
- CancelRemarks: string;
23
- TerminateRemarks: string;
24
- AgreementNo: string;
25
- private _Status: RentalStatusEnum;
26
- private _EscheatmentYN: string = 'N';
27
- private _CreatedById: string;
28
- private _CreatedAt: Date;
29
- private _UpdatedById: string;
30
- private _UpdatedAt: Date;
31
- private static _Repo = new RentalRepository();
32
-
33
- get Status(): RentalStatusEnum {
34
- return this._Status;
35
- }
36
-
37
- get EscheatmentYN(): string {
38
- return this._EscheatmentYN;
39
- }
40
-
41
- get CreatedById(): string {
42
- return this._CreatedById;
43
- }
44
-
45
- get CreatedAt(): Date {
46
- return this._CreatedAt;
47
- }
48
-
49
- get UpdatedById(): string {
50
- return this._UpdatedById;
51
- }
52
-
53
- get UpdatedAt(): Date {
54
- return this._UpdatedAt;
55
- }
56
-
57
- private constructor(rentalAttr?: IRentalAttr) {
58
- if (rentalAttr) {
59
- this.RentalId = rentalAttr.RentalId;
60
- this.CustomerId = rentalAttr.CustomerId;
61
- this.CustomerType = rentalAttr.CustomerType;
62
- this.ItemId = rentalAttr.ItemId;
63
- this.ItemType = rentalAttr.ItemType;
64
- this.PriceId = rentalAttr.PriceId;
65
- this.StartDateTime = rentalAttr.StartDateTime;
66
- this.EndDateTime = rentalAttr.EndDateTime;
67
- this.CancelRemarks = rentalAttr.CancelRemarks;
68
- this.TerminateRemarks = rentalAttr.TerminateRemarks;
69
- this.AgreementNo = rentalAttr.AgreementNo;
70
- this._Status = rentalAttr.Status;
71
- this._EscheatmentYN = rentalAttr.EscheatmentYN;
72
- this._CreatedById = rentalAttr.CreatedById;
73
- this._CreatedAt = rentalAttr.CreatedAt;
74
- this._UpdatedById = rentalAttr.UpdatedById;
75
- this._UpdatedAt = rentalAttr.UpdatedAt;
76
- }
77
- }
78
-
79
- public static async init(dbTransaction?: any, rentalId?: string) {
80
- try {
81
- if (rentalId) {
82
- const rental = await Rental._Repo.findByPk(rentalId, dbTransaction);
83
- if (rental) {
84
- return new Rental(rental);
85
- } else {
86
- throw new ClassError('Rental', 'RentalErrMsg', 'Rental Not Found');
87
- }
88
- }
89
- return new Rental();
90
- } catch (error) {
91
- throw new ClassError(
92
- 'Rental',
93
- 'RentalErrMsg',
94
- 'Failed To Initialize Price',
95
- );
96
- }
97
- }
98
-
99
- public async create(
100
- rentalPrice: RentalPrice,
101
- loginUser: LoginUser,
102
- dbTransaction?: any,
103
- ) {
104
- try {
105
- const systemCode =
106
- ApplicationConfig.getComponentConfigValue('system-code');
107
- const isPrivileged = await loginUser.checkPrivileges(
108
- systemCode,
109
- 'Rental - Create',
110
- );
111
-
112
- if (!isPrivileged) {
113
- throw new ClassError(
114
- 'RentalPrice',
115
- 'RentalPriceErrMsg',
116
- 'You do not have the privilege.',
117
- );
118
- }
119
-
120
- const isItemAvailable = await this.isItemAvailable(
121
- this.ItemId,
122
- this.ItemType,
123
- this.StartDateTime,
124
- this.EndDateTime,
125
- dbTransaction,
126
- );
127
-
128
- if (!isItemAvailable) {
129
- throw new ClassError(
130
- 'Rental',
131
- 'RentalErrMsg02',
132
- 'Rental Item is not available at current date.',
133
- );
134
- }
135
-
136
- await rentalPrice.create(loginUser, dbTransaction);
137
-
138
- this.PriceId = rentalPrice.PriceId;
139
-
140
- this.RentalId = cuid();
141
- this._Status = RentalStatusEnum.ACTIVE;
142
- this._CreatedById = loginUser.ObjectId;
143
- this._UpdatedById = loginUser.ObjectId;
144
- this._CreatedAt = new Date();
145
- this._UpdatedAt = new Date();
146
-
147
- const data = {
148
- RentalId: this.RentalId,
149
- CustomerId: this.CustomerId,
150
- CustomerType: this.CustomerType,
151
- ItemId: this.ItemId,
152
- ItemType: this.ItemType,
153
- PriceId: this.PriceId,
154
- StartDateTime: this.StartDateTime,
155
- EndDateTime: this.EndDateTime,
156
- CancelRemarks: this.CancelRemarks,
157
- TerminateRemarks: this.TerminateRemarks,
158
- AgreementNo: this.AgreementNo,
159
- Status: this.Status,
160
- EscheatmentYN: this.EscheatmentYN,
161
- CreatedById: this.CreatedById,
162
- CreatedAt: this.CreatedAt,
163
- UpdatedById: this.UpdatedById,
164
- UpdatedAt: this.UpdatedAt,
165
- };
166
-
167
- await Rental._Repo.create(data, dbTransaction);
168
-
169
- const activity = new Activity();
170
- activity.ActivityId = cuid();
171
- activity.Action = ActionEnum.ADD;
172
- activity.Description = 'Add Rental';
173
- activity.EntityType = 'Rental';
174
- activity.EntityId = this.RentalId;
175
- activity.EntityValueBefore = JSON.stringify({});
176
- activity.EntityValueAfter = JSON.stringify(data);
177
- await activity.create(loginUser, dbTransaction);
178
-
179
- return this;
180
- } catch (error) {
181
- throw error;
182
- }
183
- }
184
-
185
- async isItemAvailable(
186
- itemId: string,
187
- itemType: string,
188
- startDateTime: Date,
189
- endDateTime: Date,
190
- dbTransaction?: any,
191
- ) {
192
- try {
193
- const item = await Rental._Repo.findOne({
194
- where: {
195
- ItemId: itemId,
196
- ItemType: itemType,
197
- StartDateTime: {
198
- [Op.lte]: endDateTime,
199
- },
200
- EndDateTime: {
201
- [Op.gte]: startDateTime,
202
- },
203
- },
204
- transaction: dbTransaction,
205
- });
206
-
207
- if (item) {
208
- return false;
209
- } else {
210
- return true;
211
- }
212
- } catch (error) {
213
- throw error;
214
- }
215
- }
216
-
217
- public static async findAll(
218
- loginUser: LoginUser,
219
- dbTransaction: any,
220
- page?: number,
221
- row?: number,
222
- search?: IRentalFindAllSearchAttr,
223
- ) {
224
- try {
225
- const systemCode = await ApplicationConfig.getComponentConfigValue(
226
- 'system-code',
227
- );
228
-
229
- const isPrivileged = await loginUser.checkPrivileges(
230
- systemCode,
231
- 'Rental - View',
232
- );
233
-
234
- if (!isPrivileged) {
235
- throw new ClassError(
236
- 'Rental',
237
- 'RentalErrMsg',
238
- 'You do not have the privilege.',
239
- );
240
- }
241
-
242
- const queryObj: any = {};
243
-
244
- let options: any = {
245
- transaction: dbTransaction,
246
- };
247
-
248
- if (page && row) {
249
- options = {
250
- ...options,
251
- limit: row,
252
- offset: row * (page - 1),
253
- order: [['CreatedAt', 'DESC']],
254
- };
255
- }
256
-
257
- if (search) {
258
- Object.entries(search).forEach(([key, value]) => {
259
- if (key === 'StartDateTime') {
260
- queryObj[key] = {
261
- [Op.eq]: value,
262
- };
263
- } else if (key === 'EndDateTime') {
264
- queryObj[key] = {
265
- [Op.eq]: value,
266
- };
267
- } else {
268
- queryObj[key] = {
269
- [Op.substring]: value,
270
- };
271
- }
272
- });
273
-
274
- options = {
275
- ...options,
276
- where: queryObj,
277
- };
278
- }
279
-
280
- return await Rental._Repo.findAndCountAll(options);
281
- } catch (err) {
282
- throw err;
283
- }
284
- }
285
- }
1
+ import { IRentalAttr } from '../../interfaces/rental-attr.interface';
2
+ import { RentalStatusEnum } from '../../enum/rental-status.enum';
3
+ import { RentalRepository } from './rental.repository';
4
+ import { ClassError } from '@tomei/general';
5
+ import { ApplicationConfig } from '@tomei/config';
6
+ import { LoginUser } from '@tomei/sso';
7
+ import { RentalPrice } from '../rental-price/rental-price';
8
+ import * as cuid from 'cuid';
9
+ import { Op } from 'sequelize';
10
+ import { ActionEnum, Activity } from '@tomei/activity-history';
11
+ import { IRentalFindAllSearchAttr } from '../../interfaces/rental-find-all-search-attr.interface';
12
+
13
+ export class Rental {
14
+ RentalId: string;
15
+ CustomerId: string;
16
+ CustomerType: string;
17
+ ItemId: string;
18
+ ItemType: string;
19
+ PriceId: string;
20
+ StartDateTime: Date;
21
+ EndDateTime: Date;
22
+ CancelRemarks: string;
23
+ TerminateRemarks: string;
24
+ AgreementNo: string;
25
+ private _Status: RentalStatusEnum;
26
+ private _EscheatmentYN: string = 'N';
27
+ private _CreatedById: string;
28
+ private _CreatedAt: Date;
29
+ private _UpdatedById: string;
30
+ private _UpdatedAt: Date;
31
+ private static _Repo = new RentalRepository();
32
+
33
+ get Status(): RentalStatusEnum {
34
+ return this._Status;
35
+ }
36
+
37
+ get EscheatmentYN(): string {
38
+ return this._EscheatmentYN;
39
+ }
40
+
41
+ get CreatedById(): string {
42
+ return this._CreatedById;
43
+ }
44
+
45
+ get CreatedAt(): Date {
46
+ return this._CreatedAt;
47
+ }
48
+
49
+ get UpdatedById(): string {
50
+ return this._UpdatedById;
51
+ }
52
+
53
+ get UpdatedAt(): Date {
54
+ return this._UpdatedAt;
55
+ }
56
+
57
+ private constructor(rentalAttr?: IRentalAttr) {
58
+ if (rentalAttr) {
59
+ this.RentalId = rentalAttr.RentalId;
60
+ this.CustomerId = rentalAttr.CustomerId;
61
+ this.CustomerType = rentalAttr.CustomerType;
62
+ this.ItemId = rentalAttr.ItemId;
63
+ this.ItemType = rentalAttr.ItemType;
64
+ this.PriceId = rentalAttr.PriceId;
65
+ this.StartDateTime = rentalAttr.StartDateTime;
66
+ this.EndDateTime = rentalAttr.EndDateTime;
67
+ this.CancelRemarks = rentalAttr.CancelRemarks;
68
+ this.TerminateRemarks = rentalAttr.TerminateRemarks;
69
+ this.AgreementNo = rentalAttr.AgreementNo;
70
+ this._Status = rentalAttr.Status;
71
+ this._EscheatmentYN = rentalAttr.EscheatmentYN;
72
+ this._CreatedById = rentalAttr.CreatedById;
73
+ this._CreatedAt = rentalAttr.CreatedAt;
74
+ this._UpdatedById = rentalAttr.UpdatedById;
75
+ this._UpdatedAt = rentalAttr.UpdatedAt;
76
+ }
77
+ }
78
+
79
+ public static async init(dbTransaction?: any, rentalId?: string) {
80
+ try {
81
+ if (rentalId) {
82
+ const rental = await Rental._Repo.findByPk(rentalId, dbTransaction);
83
+ if (rental) {
84
+ return new Rental(rental);
85
+ } else {
86
+ throw new ClassError('Rental', 'RentalErrMsg', 'Rental Not Found');
87
+ }
88
+ }
89
+ return new Rental();
90
+ } catch (error) {
91
+ throw new ClassError(
92
+ 'Rental',
93
+ 'RentalErrMsg',
94
+ 'Failed To Initialize Price',
95
+ );
96
+ }
97
+ }
98
+
99
+ public async create(
100
+ rentalPrice: RentalPrice,
101
+ loginUser: LoginUser,
102
+ dbTransaction?: any,
103
+ ) {
104
+ try {
105
+ const systemCode =
106
+ ApplicationConfig.getComponentConfigValue('system-code');
107
+ const isPrivileged = await loginUser.checkPrivileges(
108
+ systemCode,
109
+ 'Rental - Create',
110
+ );
111
+
112
+ if (!isPrivileged) {
113
+ throw new ClassError(
114
+ 'RentalPrice',
115
+ 'RentalPriceErrMsg',
116
+ 'You do not have the privilege.',
117
+ );
118
+ }
119
+
120
+ const isItemAvailable = await this.isItemAvailable(
121
+ this.ItemId,
122
+ this.ItemType,
123
+ this.StartDateTime,
124
+ this.EndDateTime,
125
+ dbTransaction,
126
+ );
127
+
128
+ if (!isItemAvailable) {
129
+ throw new ClassError(
130
+ 'Rental',
131
+ 'RentalErrMsg02',
132
+ 'Rental Item is not available at current date.',
133
+ );
134
+ }
135
+
136
+ await rentalPrice.create(loginUser, dbTransaction);
137
+
138
+ this.PriceId = rentalPrice.PriceId;
139
+
140
+ this.RentalId = cuid();
141
+ this._Status = RentalStatusEnum.ACTIVE;
142
+ this._CreatedById = loginUser.ObjectId;
143
+ this._UpdatedById = loginUser.ObjectId;
144
+ this._CreatedAt = new Date();
145
+ this._UpdatedAt = new Date();
146
+
147
+ const data = {
148
+ RentalId: this.RentalId,
149
+ CustomerId: this.CustomerId,
150
+ CustomerType: this.CustomerType,
151
+ ItemId: this.ItemId,
152
+ ItemType: this.ItemType,
153
+ PriceId: this.PriceId,
154
+ StartDateTime: this.StartDateTime,
155
+ EndDateTime: this.EndDateTime,
156
+ CancelRemarks: this.CancelRemarks,
157
+ TerminateRemarks: this.TerminateRemarks,
158
+ AgreementNo: this.AgreementNo,
159
+ Status: this.Status,
160
+ EscheatmentYN: this.EscheatmentYN,
161
+ CreatedById: this.CreatedById,
162
+ CreatedAt: this.CreatedAt,
163
+ UpdatedById: this.UpdatedById,
164
+ UpdatedAt: this.UpdatedAt,
165
+ };
166
+
167
+ await Rental._Repo.create(data, dbTransaction);
168
+
169
+ const activity = new Activity();
170
+ activity.ActivityId = cuid();
171
+ activity.Action = ActionEnum.ADD;
172
+ activity.Description = 'Add Rental';
173
+ activity.EntityType = 'Rental';
174
+ activity.EntityId = this.RentalId;
175
+ activity.EntityValueBefore = JSON.stringify({});
176
+ activity.EntityValueAfter = JSON.stringify(data);
177
+ await activity.create(loginUser, dbTransaction);
178
+
179
+ return this;
180
+ } catch (error) {
181
+ throw error;
182
+ }
183
+ }
184
+
185
+ async isItemAvailable(
186
+ itemId: string,
187
+ itemType: string,
188
+ startDateTime: Date,
189
+ endDateTime: Date,
190
+ dbTransaction?: any,
191
+ ) {
192
+ try {
193
+ const item = await Rental._Repo.findOne({
194
+ where: {
195
+ ItemId: itemId,
196
+ ItemType: itemType,
197
+ StartDateTime: {
198
+ [Op.lte]: endDateTime,
199
+ },
200
+ EndDateTime: {
201
+ [Op.gte]: startDateTime,
202
+ },
203
+ },
204
+ transaction: dbTransaction,
205
+ });
206
+
207
+ if (item) {
208
+ return false;
209
+ } else {
210
+ return true;
211
+ }
212
+ } catch (error) {
213
+ throw error;
214
+ }
215
+ }
216
+
217
+ public static async findAll(
218
+ loginUser: LoginUser,
219
+ dbTransaction: any,
220
+ page?: number,
221
+ row?: number,
222
+ search?: IRentalFindAllSearchAttr,
223
+ ) {
224
+ try {
225
+ const systemCode = await ApplicationConfig.getComponentConfigValue(
226
+ 'system-code',
227
+ );
228
+
229
+ const isPrivileged = await loginUser.checkPrivileges(
230
+ systemCode,
231
+ 'Rental - View',
232
+ );
233
+
234
+ if (!isPrivileged) {
235
+ throw new ClassError(
236
+ 'Rental',
237
+ 'RentalErrMsg',
238
+ 'You do not have the privilege.',
239
+ );
240
+ }
241
+
242
+ const queryObj: any = {};
243
+
244
+ let options: any = {
245
+ transaction: dbTransaction,
246
+ };
247
+
248
+ if (page && row) {
249
+ options = {
250
+ ...options,
251
+ limit: row,
252
+ offset: row * (page - 1),
253
+ order: [['CreatedAt', 'DESC']],
254
+ };
255
+ }
256
+
257
+ if (search) {
258
+ Object.entries(search).forEach(([key, value]) => {
259
+ if (key === 'StartDateTime') {
260
+ queryObj[key] = {
261
+ [Op.gte]: value,
262
+ };
263
+ } else if (key === 'EndDateTime') {
264
+ queryObj[key] = {
265
+ [Op.lte]: value,
266
+ };
267
+ } else {
268
+ queryObj[key] = {
269
+ [Op.substring]: value,
270
+ };
271
+ }
272
+ });
273
+
274
+ options = {
275
+ ...options,
276
+ where: queryObj,
277
+ };
278
+ }
279
+
280
+ return await Rental._Repo.findAndCountAll(options);
281
+ } catch (err) {
282
+ throw err;
283
+ }
284
+ }
285
+ }
@@ -1,54 +1,54 @@
1
- import { RepositoryBase, IRepositoryBase } from '@tomei/general';
2
- import { RentalPriceModel } from '../../models/rental-price.entity';
3
-
4
- export class RentalPriceRepository
5
- extends RepositoryBase<RentalPriceModel>
6
- implements IRepositoryBase<RentalPriceModel>
7
- {
8
- constructor() {
9
- super(RentalPriceModel);
10
- }
11
-
12
- async findByPk(
13
- id: string,
14
- transaction?: any,
15
- ): Promise<RentalPriceModel | null> {
16
- try {
17
- const result = await RentalPriceModel.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(RentalPriceId: string, dbTransaction?: any) {
28
- try {
29
- const options = {
30
- where: {
31
- RentalPriceId: RentalPriceId,
32
- },
33
- transaction: dbTransaction,
34
- };
35
- await RentalPriceModel.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 RentalPrices: any;
44
- if (options) {
45
- RentalPrices = await RentalPriceModel.findAndCountAll(options);
46
- } else {
47
- RentalPrices = await RentalPriceModel.findAndCountAll();
48
- }
49
- return RentalPrices;
50
- } catch (error) {
51
- throw new Error(`An Error occured when retriving : ${error.message}`);
52
- }
53
- }
54
- }
1
+ import { RepositoryBase, IRepositoryBase } from '@tomei/general';
2
+ import { RentalPriceModel } from '../../models/rental-price.entity';
3
+
4
+ export class RentalPriceRepository
5
+ extends RepositoryBase<RentalPriceModel>
6
+ implements IRepositoryBase<RentalPriceModel>
7
+ {
8
+ constructor() {
9
+ super(RentalPriceModel);
10
+ }
11
+
12
+ async findByPk(
13
+ id: string,
14
+ transaction?: any,
15
+ ): Promise<RentalPriceModel | null> {
16
+ try {
17
+ const result = await RentalPriceModel.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(RentalPriceId: string, dbTransaction?: any) {
28
+ try {
29
+ const options = {
30
+ where: {
31
+ RentalPriceId: RentalPriceId,
32
+ },
33
+ transaction: dbTransaction,
34
+ };
35
+ await RentalPriceModel.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 RentalPrices: any;
44
+ if (options) {
45
+ RentalPrices = await RentalPriceModel.findAndCountAll(options);
46
+ } else {
47
+ RentalPrices = await RentalPriceModel.findAndCountAll();
48
+ }
49
+ return RentalPrices;
50
+ } catch (error) {
51
+ throw new Error(`An Error occured when retriving : ${error.message}`);
52
+ }
53
+ }
54
+ }