@tomei/rental 0.1.2 → 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 -0
- package/dist/src/components/rental/rental.js +209 -0
- package/dist/src/components/rental/rental.js.map +1 -0
- package/dist/src/components/rental/rental.repository.d.ts +8 -0
- package/dist/src/components/rental/rental.repository.js +67 -0
- package/dist/src/components/rental/rental.repository.js.map +1 -0
- package/dist/src/components/rental-price/rental-price.d.ts +12 -0
- package/dist/src/components/rental-price/rental-price.js +72 -0
- package/dist/src/components/rental-price/rental-price.js.map +1 -0
- package/dist/src/components/rental-price/rental-price.repository.d.ts +8 -0
- package/dist/src/components/rental-price/rental-price.repository.js +67 -0
- package/dist/src/components/rental-price/rental-price.repository.js.map +1 -0
- package/dist/src/database.d.ts +4 -4
- package/dist/src/database.js +14 -14
- package/dist/src/enum/index.d.ts +2 -0
- package/dist/src/enum/index.js +6 -0
- package/dist/src/enum/index.js.map +1 -0
- package/dist/src/enum/rental-status.enum.d.ts +6 -0
- package/dist/src/enum/rental-status.enum.js +11 -0
- package/dist/src/enum/rental-status.enum.js.map +1 -0
- package/dist/src/index.d.ts +9 -1
- package/dist/src/index.js +30 -4
- package/dist/src/index.js.map +1 -1
- package/dist/src/interfaces/index.d.ts +4 -0
- package/dist/src/interfaces/index.js +3 -0
- package/dist/src/interfaces/index.js.map +1 -0
- package/dist/src/interfaces/rental-attr.interface.d.ts +20 -0
- package/dist/src/interfaces/rental-attr.interface.js +3 -0
- package/dist/src/interfaces/rental-attr.interface.js.map +1 -0
- 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 -0
- package/dist/src/interfaces/rental-price-attr.interface.js +3 -0
- package/dist/src/interfaces/rental-price-attr.interface.js.map +1 -0
- package/dist/src/models/index.d.ts +3 -0
- package/dist/src/models/index.js +8 -0
- package/dist/src/models/index.js.map +1 -0
- package/dist/src/models/rental-price.entity.d.ts +8 -0
- package/dist/src/models/rental-price.entity.js +59 -0
- package/dist/src/models/rental-price.entity.js.map +1 -0
- package/dist/src/models/rental.entity.d.ts +23 -0
- package/dist/src/models/rental.entity.js +139 -0
- package/dist/src/models/rental.entity.js.map +1 -0
- 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 -0
- package/migrations/rental-table-migrations.js +84 -0
- package/package.json +71 -67
- package/src/components/rental/rental.repository.ts +51 -0
- package/src/components/rental/rental.ts +289 -0
- package/src/components/rental-price/rental-price.repository.ts +54 -0
- package/src/components/rental-price/rental-price.ts +89 -0
- package/src/database.ts +15 -15
- package/src/enum/index.ts +3 -0
- package/src/enum/rental-status.enum.ts +6 -0
- package/src/index.ts +16 -1
- package/src/interfaces/index.ts +5 -0
- package/src/interfaces/rental-attr.interface.ts +21 -0
- package/src/interfaces/rental-find-all-search-attr.interface.ts +8 -0
- package/src/interfaces/rental-price-attr.interface.ts +7 -0
- package/src/models/index.ts +4 -0
- package/src/models/rental-price.entity.ts +38 -0
- package/src/models/rental.entity.ts +114 -0
- package/tsconfig.build.json +5 -5
- package/tsconfig.json +23 -23
- package/tsconfig.tsbuildinfo +1 -0
package/package.json
CHANGED
|
@@ -1,67 +1,71 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@tomei/rental",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"description": "Tomei Rental Package",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"start:dev": "tsc -w",
|
|
8
|
-
"build": "tsc",
|
|
9
|
-
"prepare": "husky install",
|
|
10
|
-
"format": "prettier --write \"src/**/*.ts\"",
|
|
11
|
-
"lint": "npx eslint . --fix",
|
|
12
|
-
"test": "jest --forceExit --detectOpenHandles"
|
|
13
|
-
},
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "git+ssh://git@gitlab.com/tomei-package/rental.git"
|
|
17
|
-
},
|
|
18
|
-
"keywords": [
|
|
19
|
-
"tomei",
|
|
20
|
-
"rental"
|
|
21
|
-
],
|
|
22
|
-
"author": "Tomei",
|
|
23
|
-
"license": "ISC",
|
|
24
|
-
"bugs": {
|
|
25
|
-
"url": "https://gitlab.com/tomei-package/rental/issues"
|
|
26
|
-
},
|
|
27
|
-
"homepage": "https://gitlab.com/tomei-package/rental#readme",
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"@commitlint/cli": "^17.6.3",
|
|
30
|
-
"@commitlint/config-conventional": "^17.6.3",
|
|
31
|
-
"@tsconfig/node18": "^2.0.1",
|
|
32
|
-
"@types/jest": "^29.5.2",
|
|
33
|
-
"@types/node": "^18.17.12",
|
|
34
|
-
"@types/validator": "^13.11.1",
|
|
35
|
-
"@typescript-eslint/eslint-plugin": "^5.33.0",
|
|
36
|
-
"dotenv": "^16.1.4",
|
|
37
|
-
"eslint": "^8.40.0",
|
|
38
|
-
"eslint-config-prettier": "^8.5.0",
|
|
39
|
-
"eslint-plugin-prettier": "^4.2.1",
|
|
40
|
-
"husky": "^8.0.3",
|
|
41
|
-
"jest": "^29.5.0",
|
|
42
|
-
"jest-mock-extended": "^3.0.4",
|
|
43
|
-
"lint-staged": "^13.2.2",
|
|
44
|
-
"prettier": "^2.7.1",
|
|
45
|
-
"ts-jest": "^29.1.0",
|
|
46
|
-
"ts-node": "^10.9.1",
|
|
47
|
-
"tsc-watch": "^5.0.3",
|
|
48
|
-
"tsconfig-paths": "^4.0.0",
|
|
49
|
-
"tslint": "^6.1.3",
|
|
50
|
-
"typescript": "^4.7.4"
|
|
51
|
-
},
|
|
52
|
-
"publishConfig": {
|
|
53
|
-
"access": "public"
|
|
54
|
-
},
|
|
55
|
-
"peerDependencies": {
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"sequelize
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@tomei/rental",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Tomei Rental Package",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start:dev": "tsc -w",
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"prepare": "husky install",
|
|
10
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
11
|
+
"lint": "npx eslint . --fix",
|
|
12
|
+
"test": "jest --forceExit --detectOpenHandles"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+ssh://git@gitlab.com/tomei-package/rental.git"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"tomei",
|
|
20
|
+
"rental"
|
|
21
|
+
],
|
|
22
|
+
"author": "Tomei",
|
|
23
|
+
"license": "ISC",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://gitlab.com/tomei-package/rental/issues"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://gitlab.com/tomei-package/rental#readme",
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@commitlint/cli": "^17.6.3",
|
|
30
|
+
"@commitlint/config-conventional": "^17.6.3",
|
|
31
|
+
"@tsconfig/node18": "^2.0.1",
|
|
32
|
+
"@types/jest": "^29.5.2",
|
|
33
|
+
"@types/node": "^18.17.12",
|
|
34
|
+
"@types/validator": "^13.11.1",
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "^5.33.0",
|
|
36
|
+
"dotenv": "^16.1.4",
|
|
37
|
+
"eslint": "^8.40.0",
|
|
38
|
+
"eslint-config-prettier": "^8.5.0",
|
|
39
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
40
|
+
"husky": "^8.0.3",
|
|
41
|
+
"jest": "^29.5.0",
|
|
42
|
+
"jest-mock-extended": "^3.0.4",
|
|
43
|
+
"lint-staged": "^13.2.2",
|
|
44
|
+
"prettier": "^2.7.1",
|
|
45
|
+
"ts-jest": "^29.1.0",
|
|
46
|
+
"ts-node": "^10.9.1",
|
|
47
|
+
"tsc-watch": "^5.0.3",
|
|
48
|
+
"tsconfig-paths": "^4.0.0",
|
|
49
|
+
"tslint": "^6.1.3",
|
|
50
|
+
"typescript": "^4.7.4"
|
|
51
|
+
},
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"cuid": "^3.0.0",
|
|
57
|
+
"reflect-metadata": "^0.1.13",
|
|
58
|
+
"sequelize": "^6.32.1",
|
|
59
|
+
"sequelize-typescript": "^2.1.5",
|
|
60
|
+
"@tomei/activity-history": "^0.2.1",
|
|
61
|
+
"@tomei/config": "^0.2.2",
|
|
62
|
+
"@tomei/general": "^0.5.1",
|
|
63
|
+
"@tomei/sso": "^0.11.6"
|
|
64
|
+
},
|
|
65
|
+
"lint-staged": {
|
|
66
|
+
"*/**/*.{js,ts,tsx}": [
|
|
67
|
+
"prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
68
|
+
"eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { RepositoryBase, IRepositoryBase } from '@tomei/general';
|
|
2
|
+
import { RentalModel } from '../../models/rental.entity';
|
|
3
|
+
|
|
4
|
+
export class RentalRepository
|
|
5
|
+
extends RepositoryBase<RentalModel>
|
|
6
|
+
implements IRepositoryBase<RentalModel>
|
|
7
|
+
{
|
|
8
|
+
constructor() {
|
|
9
|
+
super(RentalModel);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async findByPk(id: string, transaction?: any): Promise<RentalModel | null> {
|
|
13
|
+
try {
|
|
14
|
+
const result = await RentalModel.findByPk(id, {
|
|
15
|
+
transaction: transaction,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return result;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
throw new Error(`An Error occured when fetching : ${error.message}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async delete(RentalId: string, dbTransaction?: any) {
|
|
25
|
+
try {
|
|
26
|
+
const options = {
|
|
27
|
+
where: {
|
|
28
|
+
RentalId: RentalId,
|
|
29
|
+
},
|
|
30
|
+
transaction: dbTransaction,
|
|
31
|
+
};
|
|
32
|
+
await RentalModel.destroy(options);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
throw new Error(`An Error occured when delete : ${error.message}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async findAndCountAll(options?: any) {
|
|
39
|
+
try {
|
|
40
|
+
let Rentals: any;
|
|
41
|
+
if (options) {
|
|
42
|
+
Rentals = await RentalModel.findAndCountAll(options);
|
|
43
|
+
} else {
|
|
44
|
+
Rentals = await RentalModel.findAndCountAll();
|
|
45
|
+
}
|
|
46
|
+
return Rentals;
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw new Error(`An Error occured when retriving : ${error.message}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +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
|
+
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
|
+
}
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { ClassError } from '@tomei/general';
|
|
2
|
+
import { RentalPriceRepository } from './rental-price.repository';
|
|
3
|
+
import { IRentalPriceAttr } from '../../interfaces/rental-price-attr.interface';
|
|
4
|
+
import { LoginUser } from '@tomei/sso';
|
|
5
|
+
import { ApplicationConfig } from '@tomei/config';
|
|
6
|
+
import * as cuid from 'cuid';
|
|
7
|
+
|
|
8
|
+
export class RentalPrice {
|
|
9
|
+
PriceId: string;
|
|
10
|
+
RetailPrice: number;
|
|
11
|
+
Currency: string;
|
|
12
|
+
PromoCode: string;
|
|
13
|
+
Remarks: string;
|
|
14
|
+
|
|
15
|
+
private static _Repo = new RentalPriceRepository();
|
|
16
|
+
|
|
17
|
+
private constructor(rentalPriceAttr?: IRentalPriceAttr) {
|
|
18
|
+
if (rentalPriceAttr) {
|
|
19
|
+
this.PriceId = rentalPriceAttr.PriceId;
|
|
20
|
+
this.RetailPrice = rentalPriceAttr.RetailPrice;
|
|
21
|
+
this.Currency = rentalPriceAttr.Currency;
|
|
22
|
+
this.PromoCode = rentalPriceAttr.PromoCode;
|
|
23
|
+
this.Remarks = rentalPriceAttr.Remarks;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public static async init(dbTransaction?: any, priceId?: string) {
|
|
28
|
+
try {
|
|
29
|
+
if (priceId) {
|
|
30
|
+
const rentalPrice = await RentalPrice._Repo.findByPk(
|
|
31
|
+
priceId,
|
|
32
|
+
dbTransaction,
|
|
33
|
+
);
|
|
34
|
+
if (rentalPrice) {
|
|
35
|
+
return new RentalPrice(rentalPrice);
|
|
36
|
+
} else {
|
|
37
|
+
throw new ClassError(
|
|
38
|
+
'RentalPrice',
|
|
39
|
+
'RentalPriceErrMsg',
|
|
40
|
+
'RentalPrice Not Found',
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return new RentalPrice();
|
|
45
|
+
} catch (error) {
|
|
46
|
+
throw new ClassError(
|
|
47
|
+
'RentalPrice',
|
|
48
|
+
'RentalPriceErrMsg',
|
|
49
|
+
'Failed To Initialize RentalPrice',
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public async create(loginUser: LoginUser, dbTransaction?: any) {
|
|
55
|
+
try {
|
|
56
|
+
const systemCode =
|
|
57
|
+
ApplicationConfig.getComponentConfigValue('system-code');
|
|
58
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
|
59
|
+
systemCode,
|
|
60
|
+
'Rental - Create',
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
if (!isPrivileged) {
|
|
64
|
+
throw new ClassError(
|
|
65
|
+
'RentalPrice',
|
|
66
|
+
'RentalPriceErrMsg',
|
|
67
|
+
'You do not have the privilege.',
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
this.PriceId = cuid();
|
|
72
|
+
|
|
73
|
+
await RentalPrice._Repo.create(
|
|
74
|
+
{
|
|
75
|
+
PriceId: this.PriceId,
|
|
76
|
+
RetailPrice: this.RetailPrice,
|
|
77
|
+
Currency: this.Currency,
|
|
78
|
+
PromoCode: this.PromoCode,
|
|
79
|
+
Remarks: this.Remarks,
|
|
80
|
+
},
|
|
81
|
+
dbTransaction,
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
return this;
|
|
85
|
+
} catch (error) {
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
package/src/database.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { Sequelize, SequelizeOptions } from 'sequelize-typescript';
|
|
2
|
-
|
|
3
|
-
let sequelize: Sequelize;
|
|
4
|
-
|
|
5
|
-
function init(sequelizeOptions: SequelizeOptions) {
|
|
6
|
-
sequelize = new Sequelize(sequelizeOptions);
|
|
7
|
-
|
|
8
|
-
sequelize.addModels([__dirname + '/models']);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function getConnection() {
|
|
12
|
-
return sequelize;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export { init, getConnection };
|
|
1
|
+
import { Sequelize, SequelizeOptions } from 'sequelize-typescript';
|
|
2
|
+
|
|
3
|
+
let sequelize: Sequelize;
|
|
4
|
+
|
|
5
|
+
function init(sequelizeOptions: SequelizeOptions) {
|
|
6
|
+
sequelize = new Sequelize(sequelizeOptions);
|
|
7
|
+
|
|
8
|
+
sequelize.addModels([__dirname + '/models']);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function getConnection() {
|
|
12
|
+
return sequelize;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { init, getConnection };
|
package/src/index.ts
CHANGED
|
@@ -1 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import { RentalPriceRepository } from './components/rental-price/rental-price.repository';
|
|
2
|
+
import { RentalRepository } from './components/rental/rental.repository';
|
|
3
|
+
import { Rental } from './components/rental/rental';
|
|
4
|
+
import { RentalPrice } from './components/rental-price/rental-price';
|
|
5
|
+
import * as rentalDb from './database';
|
|
6
|
+
export * from './interfaces';
|
|
7
|
+
export * from './models';
|
|
8
|
+
export * from './enum';
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
Rental,
|
|
12
|
+
RentalPrice,
|
|
13
|
+
RentalRepository,
|
|
14
|
+
RentalPriceRepository,
|
|
15
|
+
rentalDb,
|
|
16
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { IRentalAttr } from './rental-attr.interface';
|
|
2
|
+
import { IRentalPriceAttr } from './rental-price-attr.interface';
|
|
3
|
+
import { IRentalFindAllSearchAttr } from './rental-find-all-search-attr.interface';
|
|
4
|
+
|
|
5
|
+
export { IRentalAttr, IRentalPriceAttr, IRentalFindAllSearchAttr };
|