@tomei/rental 0.4.3 → 0.4.4
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 +51 -51
- package/README.md +8 -8
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -17
- package/dist/src/components/rental/rental.d.ts +45 -39
- package/dist/src/components/rental/rental.js +338 -331
- 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 +18 -12
- package/dist/src/components/rental-price/rental-price.js +78 -71
- package/dist/src/components/rental-price/rental-price.js.map +1 -1
- 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 +19 -19
- 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 +7 -7
- package/dist/src/enum/rental-status.enum.js +11 -11
- package/dist/src/index.d.ts +9 -9
- package/dist/src/index.js +30 -30
- package/dist/src/interfaces/index.d.ts +4 -4
- 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 +10 -10
- package/dist/src/interfaces/rental-find-all-search-attr.interface.js +2 -2
- 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 +140 -140
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/jest.config.js +10 -10
- package/migrations/rental-price-table-migration.js +32 -32
- package/migrations/rental-table-migrations.js +86 -86
- package/package.json +71 -71
- package/src/components/rental/rental.repository.ts +51 -51
- package/src/components/rental/rental.ts +511 -500
- package/src/components/rental-price/rental-price.repository.ts +54 -54
- package/src/components/rental-price/rental-price.ts +100 -89
- package/src/database.ts +21 -21
- package/src/enum/index.ts +3 -3
- package/src/enum/rental-status.enum.ts +29 -29
- package/src/index.ts +16 -16
- package/src/interfaces/index.ts +5 -5
- package/src/interfaces/rental-attr.interface.ts +21 -21
- package/src/interfaces/rental-find-all-search-attr.interface.ts +11 -11
- 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 +116 -116
- package/tsconfig.build.json +5 -5
- package/tsconfig.json +23 -23
|
@@ -1,332 +1,339 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Rental = void 0;
|
|
13
|
-
const rental_status_enum_1 = require("../../enum/rental-status.enum");
|
|
14
|
-
const rental_repository_1 = require("./rental.repository");
|
|
15
|
-
const general_1 = require("@tomei/general");
|
|
16
|
-
const config_1 = require("@tomei/config");
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
56
|
-
this.
|
|
57
|
-
this.
|
|
58
|
-
this.
|
|
59
|
-
this.
|
|
60
|
-
this.
|
|
61
|
-
this.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
this.
|
|
104
|
-
this.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
activity
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if (
|
|
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
|
-
|
|
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
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
activity
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Rental = void 0;
|
|
13
|
+
const rental_status_enum_1 = require("../../enum/rental-status.enum");
|
|
14
|
+
const rental_repository_1 = require("./rental.repository");
|
|
15
|
+
const general_1 = require("@tomei/general");
|
|
16
|
+
const config_1 = require("@tomei/config");
|
|
17
|
+
const sequelize_1 = require("sequelize");
|
|
18
|
+
const activity_history_1 = require("@tomei/activity-history");
|
|
19
|
+
class Rental extends general_1.ObjectBase {
|
|
20
|
+
get RentalId() {
|
|
21
|
+
return this.ObjectId;
|
|
22
|
+
}
|
|
23
|
+
set RentalId(value) {
|
|
24
|
+
this.ObjectId = value;
|
|
25
|
+
}
|
|
26
|
+
get Status() {
|
|
27
|
+
return this._Status;
|
|
28
|
+
}
|
|
29
|
+
get EscheatmentYN() {
|
|
30
|
+
return this._EscheatmentYN;
|
|
31
|
+
}
|
|
32
|
+
get CreatedById() {
|
|
33
|
+
return this._CreatedById;
|
|
34
|
+
}
|
|
35
|
+
get CreatedAt() {
|
|
36
|
+
return this._CreatedAt;
|
|
37
|
+
}
|
|
38
|
+
get UpdatedById() {
|
|
39
|
+
return this._UpdatedById;
|
|
40
|
+
}
|
|
41
|
+
get UpdatedAt() {
|
|
42
|
+
return this._UpdatedAt;
|
|
43
|
+
}
|
|
44
|
+
setTerminated() {
|
|
45
|
+
this._Status = rental_status_enum_1.RentalStatusEnum.TERMINATED;
|
|
46
|
+
}
|
|
47
|
+
constructor(rentalAttr) {
|
|
48
|
+
super();
|
|
49
|
+
this.ObjectType = 'Rental';
|
|
50
|
+
this._EscheatmentYN = 'N';
|
|
51
|
+
if (rentalAttr) {
|
|
52
|
+
this.RentalId = rentalAttr.RentalId;
|
|
53
|
+
this.CustomerId = rentalAttr.CustomerId;
|
|
54
|
+
this.CustomerType = rentalAttr.CustomerType;
|
|
55
|
+
this.ItemId = rentalAttr.ItemId;
|
|
56
|
+
this.ItemType = rentalAttr.ItemType;
|
|
57
|
+
this.PriceId = rentalAttr.PriceId;
|
|
58
|
+
this.StartDateTime = rentalAttr.StartDateTime;
|
|
59
|
+
this.EndDateTime = rentalAttr.EndDateTime;
|
|
60
|
+
this.CancelRemarks = rentalAttr.CancelRemarks;
|
|
61
|
+
this.TerminateRemarks = rentalAttr.TerminateRemarks;
|
|
62
|
+
this.AgreementNo = rentalAttr.AgreementNo;
|
|
63
|
+
this._Status = rentalAttr.Status;
|
|
64
|
+
this._EscheatmentYN = rentalAttr.EscheatmentYN;
|
|
65
|
+
this._CreatedById = rentalAttr.CreatedById;
|
|
66
|
+
this._CreatedAt = rentalAttr.CreatedAt;
|
|
67
|
+
this._UpdatedById = rentalAttr.UpdatedById;
|
|
68
|
+
this._UpdatedAt = rentalAttr.UpdatedAt;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
static init(dbTransaction, rentalId) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
try {
|
|
74
|
+
if (rentalId) {
|
|
75
|
+
const rental = yield Rental._Repo.findByPk(rentalId, dbTransaction);
|
|
76
|
+
if (rental) {
|
|
77
|
+
return new Rental(rental);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg00', 'Rental Not Found');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return new Rental();
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg00', 'Failed To Initialize Price');
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
create(rentalPrice, loginUser, dbTransaction) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
try {
|
|
93
|
+
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
94
|
+
const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'Rental - Create');
|
|
95
|
+
if (!isPrivileged) {
|
|
96
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg01', "You do not have 'Rental - Create' privilege.");
|
|
97
|
+
}
|
|
98
|
+
const isItemAvailable = yield this.isItemAvailable(this.ItemId, this.ItemType, this.StartDateTime, this.EndDateTime, dbTransaction);
|
|
99
|
+
if (!isItemAvailable) {
|
|
100
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg02', 'Rental Item is not available at current date.');
|
|
101
|
+
}
|
|
102
|
+
yield rentalPrice.create(loginUser, dbTransaction);
|
|
103
|
+
this.PriceId = rentalPrice.PriceId;
|
|
104
|
+
this.RentalId = this.createId();
|
|
105
|
+
if (!this.Status) {
|
|
106
|
+
this._Status = rental_status_enum_1.RentalStatusEnum.ACTIVE;
|
|
107
|
+
}
|
|
108
|
+
this._CreatedById = loginUser.ObjectId;
|
|
109
|
+
this._UpdatedById = loginUser.ObjectId;
|
|
110
|
+
this._CreatedAt = new Date();
|
|
111
|
+
this._UpdatedAt = new Date();
|
|
112
|
+
const data = {
|
|
113
|
+
RentalId: this.RentalId,
|
|
114
|
+
CustomerId: this.CustomerId,
|
|
115
|
+
CustomerType: this.CustomerType,
|
|
116
|
+
ItemId: this.ItemId,
|
|
117
|
+
ItemType: this.ItemType,
|
|
118
|
+
PriceId: this.PriceId,
|
|
119
|
+
StartDateTime: this.StartDateTime,
|
|
120
|
+
EndDateTime: this.EndDateTime,
|
|
121
|
+
CancelRemarks: this.CancelRemarks,
|
|
122
|
+
TerminateRemarks: this.TerminateRemarks,
|
|
123
|
+
AgreementNo: this.AgreementNo,
|
|
124
|
+
Status: this.Status,
|
|
125
|
+
EscheatmentYN: this.EscheatmentYN,
|
|
126
|
+
CreatedById: this.CreatedById,
|
|
127
|
+
CreatedAt: this.CreatedAt,
|
|
128
|
+
UpdatedById: this.UpdatedById,
|
|
129
|
+
UpdatedAt: this.UpdatedAt,
|
|
130
|
+
};
|
|
131
|
+
yield Rental._Repo.create(data, dbTransaction);
|
|
132
|
+
const activity = new activity_history_1.Activity();
|
|
133
|
+
activity.ActivityId = this.createId();
|
|
134
|
+
activity.Action = activity_history_1.ActionEnum.ADD;
|
|
135
|
+
activity.Description = 'Add Rental';
|
|
136
|
+
activity.EntityType = 'Rental';
|
|
137
|
+
activity.EntityId = this.RentalId;
|
|
138
|
+
activity.EntityValueBefore = JSON.stringify({});
|
|
139
|
+
activity.EntityValueAfter = JSON.stringify(data);
|
|
140
|
+
yield activity.create(loginUser, dbTransaction);
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
throw error;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
isItemAvailable(itemId, itemType, startDateTime, endDateTime, dbTransaction) {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
try {
|
|
151
|
+
const item = yield Rental._Repo.findOne({
|
|
152
|
+
where: {
|
|
153
|
+
ItemId: itemId,
|
|
154
|
+
ItemType: itemType,
|
|
155
|
+
StartDateTime: {
|
|
156
|
+
[sequelize_1.Op.lte]: endDateTime,
|
|
157
|
+
},
|
|
158
|
+
EndDateTime: {
|
|
159
|
+
[sequelize_1.Op.gte]: startDateTime,
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
transaction: dbTransaction,
|
|
163
|
+
});
|
|
164
|
+
if (item) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
static findAll(loginUser, dbTransaction, page, row, search) {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
try {
|
|
179
|
+
const systemCode = yield config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
180
|
+
const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'Rental - View');
|
|
181
|
+
if (!isPrivileged) {
|
|
182
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg01', "You do not have 'Rental - View' privilege.");
|
|
183
|
+
}
|
|
184
|
+
const queryObj = {};
|
|
185
|
+
let options = {
|
|
186
|
+
transaction: dbTransaction,
|
|
187
|
+
};
|
|
188
|
+
if (page && row) {
|
|
189
|
+
options = Object.assign(Object.assign({}, options), { limit: row, offset: row * (page - 1), order: [['CreatedAt', 'DESC']] });
|
|
190
|
+
}
|
|
191
|
+
if (search) {
|
|
192
|
+
Object.entries(search).forEach(([key, value]) => {
|
|
193
|
+
if (key === 'StartDateTime') {
|
|
194
|
+
queryObj[key] = {
|
|
195
|
+
[sequelize_1.Op.gte]: value,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
else if (key === 'EndDateTime') {
|
|
199
|
+
queryObj[key] = {
|
|
200
|
+
[sequelize_1.Op.lte]: value,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
queryObj[key] = {
|
|
205
|
+
[sequelize_1.Op.substring]: value,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
options = Object.assign(Object.assign({}, options), { where: queryObj });
|
|
210
|
+
}
|
|
211
|
+
return yield Rental._Repo.findAndCountAll(options);
|
|
212
|
+
}
|
|
213
|
+
catch (err) {
|
|
214
|
+
throw err;
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
static checkActiveByItemId(loginUser, itemId, itemType, dbTransaction) {
|
|
219
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
try {
|
|
221
|
+
const systemCode = yield config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
222
|
+
const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'Rental - View');
|
|
223
|
+
if (!isPrivileged) {
|
|
224
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg01', "You do not have 'Rental - View' privilege.");
|
|
225
|
+
}
|
|
226
|
+
const queryObj = {
|
|
227
|
+
ItemId: itemId,
|
|
228
|
+
ItemType: itemType,
|
|
229
|
+
Status: rental_status_enum_1.RentalStatusEnum.ACTIVE,
|
|
230
|
+
};
|
|
231
|
+
const options = {
|
|
232
|
+
transaction: dbTransaction,
|
|
233
|
+
where: queryObj,
|
|
234
|
+
};
|
|
235
|
+
const rental = yield Rental._Repo.findOne(options);
|
|
236
|
+
if (rental) {
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
catch (err) {
|
|
244
|
+
throw err;
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
setStartDateTime(startDateTime) {
|
|
249
|
+
const startDateTimeObject = new Date(startDateTime);
|
|
250
|
+
startDateTimeObject.setHours(0, 0, 0, 0);
|
|
251
|
+
if (startDateTimeObject < new Date(new Date().setHours(0, 0, 0, 0))) {
|
|
252
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg02', 'StartDateTime cannot be a past datetime.');
|
|
253
|
+
}
|
|
254
|
+
if (this.EndDateTime && startDateTimeObject > this.EndDateTime) {
|
|
255
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg03', 'StartDateTime cannot be more than EndDateTime.');
|
|
256
|
+
}
|
|
257
|
+
if (startDateTimeObject > new Date(new Date().setHours(0, 0, 0, 0))) {
|
|
258
|
+
this._Status = rental_status_enum_1.RentalStatusEnum.RESERVED;
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
this._Status = rental_status_enum_1.RentalStatusEnum.ACTIVE;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
periodEndProcess(loginUser, dbTransaction, stockInventory) {
|
|
265
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
266
|
+
try {
|
|
267
|
+
const systemCode = yield config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
268
|
+
const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'Rental – PeriodEndProcess');
|
|
269
|
+
if (!isPrivileged) {
|
|
270
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg04', "You do not have 'Rental - PeriodEndProcess' privilege.");
|
|
271
|
+
}
|
|
272
|
+
if (this.AgreementNo === undefined || this.AgreementNo === null) {
|
|
273
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg05', 'Rental must be existing rental.');
|
|
274
|
+
}
|
|
275
|
+
if (this.EndDateTime === new Date(new Date().setHours(0, 0, 0, 0))) {
|
|
276
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg06', 'Rental period is not ending today.');
|
|
277
|
+
}
|
|
278
|
+
yield stockInventory.setAvailable(loginUser, dbTransaction);
|
|
279
|
+
const entityValueBefore = {
|
|
280
|
+
RentalId: this.RentalId,
|
|
281
|
+
CustomerId: this.CustomerId,
|
|
282
|
+
CustomerType: this.CustomerType,
|
|
283
|
+
ItemId: this.ItemId,
|
|
284
|
+
ItemType: this.ItemType,
|
|
285
|
+
PriceId: this.PriceId,
|
|
286
|
+
StartDateTime: this.StartDateTime,
|
|
287
|
+
EndDateTime: this.EndDateTime,
|
|
288
|
+
CancelRemarks: this.CancelRemarks,
|
|
289
|
+
TerminateRemarks: this.TerminateRemarks,
|
|
290
|
+
AgreementNo: this.AgreementNo,
|
|
291
|
+
Status: this.Status,
|
|
292
|
+
EscheatmentYN: this.EscheatmentYN,
|
|
293
|
+
CreatedById: this.CreatedById,
|
|
294
|
+
CreatedAt: this.CreatedAt,
|
|
295
|
+
UpdatedById: this.UpdatedById,
|
|
296
|
+
UpdatedAt: this.UpdatedAt,
|
|
297
|
+
};
|
|
298
|
+
this.setTerminated();
|
|
299
|
+
this._UpdatedById = loginUser.ObjectId;
|
|
300
|
+
this._UpdatedAt = new Date();
|
|
301
|
+
const entityValueAfter = {
|
|
302
|
+
RentalId: this.RentalId,
|
|
303
|
+
CustomerId: this.CustomerId,
|
|
304
|
+
CustomerType: this.CustomerType,
|
|
305
|
+
ItemId: this.ItemId,
|
|
306
|
+
ItemType: this.ItemType,
|
|
307
|
+
PriceId: this.PriceId,
|
|
308
|
+
StartDateTime: this.StartDateTime,
|
|
309
|
+
EndDateTime: this.EndDateTime,
|
|
310
|
+
CancelRemarks: this.CancelRemarks,
|
|
311
|
+
TerminateRemarks: this.TerminateRemarks,
|
|
312
|
+
AgreementNo: this.AgreementNo,
|
|
313
|
+
Status: this.Status,
|
|
314
|
+
EscheatmentYN: this.EscheatmentYN,
|
|
315
|
+
CreatedById: this.CreatedById,
|
|
316
|
+
CreatedAt: this.CreatedAt,
|
|
317
|
+
UpdatedById: this.UpdatedById,
|
|
318
|
+
UpdatedAt: this.UpdatedAt,
|
|
319
|
+
};
|
|
320
|
+
const activity = new activity_history_1.Activity();
|
|
321
|
+
activity.ActivityId = this.createId();
|
|
322
|
+
activity.Action = activity_history_1.ActionEnum.UPDATE;
|
|
323
|
+
activity.Description = 'Set Rental as Terminated';
|
|
324
|
+
activity.EntityType = 'Rental';
|
|
325
|
+
activity.EntityId = this.RentalId;
|
|
326
|
+
activity.EntityValueBefore = JSON.stringify(entityValueBefore);
|
|
327
|
+
activity.EntityValueAfter = JSON.stringify(entityValueAfter);
|
|
328
|
+
yield activity.create(loginUser, dbTransaction);
|
|
329
|
+
return this;
|
|
330
|
+
}
|
|
331
|
+
catch (err) {
|
|
332
|
+
throw err;
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
exports.Rental = Rental;
|
|
338
|
+
Rental._Repo = new rental_repository_1.RentalRepository();
|
|
332
339
|
//# sourceMappingURL=rental.js.map
|