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