@tomei/rental 0.12.4 → 0.13.0

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 (99) hide show
  1. package/.commitlintrc.json +22 -22
  2. package/.gitlab-ci.yml +16 -16
  3. package/.husky/commit-msg +15 -15
  4. package/.husky/pre-commit +7 -7
  5. package/.prettierrc +4 -4
  6. package/Jenkinsfile +51 -51
  7. package/README.md +8 -8
  8. package/dist/src/components/agreement/agreement.d.ts +6 -1
  9. package/dist/src/components/agreement/agreement.js +39 -0
  10. package/dist/src/components/agreement/agreement.js.map +1 -1
  11. package/dist/src/components/hirer-signature/hirer-signature.d.ts +27 -0
  12. package/dist/src/components/hirer-signature/hirer-signature.js +112 -0
  13. package/dist/src/components/hirer-signature/hirer-signature.js.map +1 -0
  14. package/dist/src/components/hirer-signature/hirer-signature.repository.d.ts +8 -0
  15. package/dist/src/components/hirer-signature/hirer-signature.repository.js +67 -0
  16. package/dist/src/components/hirer-signature/hirer-signature.repository.js.map +1 -0
  17. package/dist/src/components/rental/rental.d.ts +3 -1
  18. package/dist/src/components/rental/rental.js +84 -16
  19. package/dist/src/components/rental/rental.js.map +1 -1
  20. package/dist/src/database.js +2 -0
  21. package/dist/src/database.js.map +1 -1
  22. package/dist/src/enum/hirer-signature-status.enum.d.ts +4 -0
  23. package/dist/src/enum/hirer-signature-status.enum.js +9 -0
  24. package/dist/src/enum/hirer-signature-status.enum.js.map +1 -0
  25. package/dist/src/enum/hirer-type.enum.d.ts +4 -0
  26. package/dist/src/enum/hirer-type.enum.js +9 -0
  27. package/dist/src/enum/hirer-type.enum.js.map +1 -0
  28. package/dist/src/enum/index.d.ts +3 -1
  29. package/dist/src/enum/index.js +5 -1
  30. package/dist/src/enum/index.js.map +1 -1
  31. package/dist/src/index.d.ts +3 -1
  32. package/dist/src/index.js +5 -1
  33. package/dist/src/index.js.map +1 -1
  34. package/dist/src/interfaces/hirer-signature-attr.interface.d.ts +14 -0
  35. package/dist/src/interfaces/hirer-signature-attr.interface.js +3 -0
  36. package/dist/src/interfaces/hirer-signature-attr.interface.js.map +1 -0
  37. package/dist/src/interfaces/index.d.ts +3 -1
  38. package/dist/src/interfaces/response-hirer-signature-attr.interface.d.ts +15 -0
  39. package/dist/src/interfaces/response-hirer-signature-attr.interface.js +3 -0
  40. package/dist/src/interfaces/response-hirer-signature-attr.interface.js.map +1 -0
  41. package/dist/src/models/agreement.entity.d.ts +2 -0
  42. package/dist/src/models/agreement.entity.js +5 -0
  43. package/dist/src/models/agreement.entity.js.map +1 -1
  44. package/dist/src/models/hirer-signature.entity.d.ts +16 -0
  45. package/dist/src/models/hirer-signature.entity.js +100 -0
  46. package/dist/src/models/hirer-signature.entity.js.map +1 -0
  47. package/dist/src/models/index.d.ts +2 -1
  48. package/dist/src/models/index.js +3 -1
  49. package/dist/src/models/index.js.map +1 -1
  50. package/dist/tsconfig.tsbuildinfo +1 -1
  51. package/eslint.config.mjs +58 -58
  52. package/jest.config.js +10 -10
  53. package/migrations/booking-table-migration.js +79 -79
  54. package/migrations/hirer-signature-table-migration.js +64 -0
  55. package/migrations/joint-hirer-table-migration.js +52 -52
  56. package/migrations/rental-aggrement-table-migration.js +30 -30
  57. package/migrations/rental-price-table-migration.js +32 -32
  58. package/migrations/rental-table-migrations.js +96 -96
  59. package/package.json +75 -75
  60. package/sonar-project.properties +12 -12
  61. package/src/components/agreement/agreement.repository.ts +54 -54
  62. package/src/components/agreement/agreement.ts +117 -49
  63. package/src/components/booking/booking.repository.ts +51 -51
  64. package/src/components/booking/booking.ts +492 -492
  65. package/src/components/hirer-signature/hirer-signature.repository.ts +54 -0
  66. package/src/components/hirer-signature/hirer-signature.ts +140 -0
  67. package/src/components/joint-hirer/joint-hirer.repository.ts +54 -54
  68. package/src/components/joint-hirer/joint-hirer.ts +137 -137
  69. package/src/components/rental/rental.repository.ts +51 -51
  70. package/src/components/rental/rental.ts +1073 -963
  71. package/src/components/rental-price/rental-price.repository.ts +54 -54
  72. package/src/components/rental-price/rental-price.ts +100 -100
  73. package/src/database.ts +29 -27
  74. package/src/enum/account-type.enum.ts +4 -4
  75. package/src/enum/booking.enum.ts +5 -5
  76. package/src/enum/hirer-signature-status.enum.ts +4 -0
  77. package/src/enum/hirer-type.enum.ts +4 -0
  78. package/src/enum/index.ts +15 -11
  79. package/src/enum/rental-status.enum.ts +39 -39
  80. package/src/index.ts +32 -28
  81. package/src/interfaces/agreement-attr.interface.ts +7 -7
  82. package/src/interfaces/booking-attr.interface.ts +19 -19
  83. package/src/interfaces/booking-find-all-search-attr.interface.ts +12 -12
  84. package/src/interfaces/hirer-signature-attr.interface.ts +15 -0
  85. package/src/interfaces/index.ts +19 -15
  86. package/src/interfaces/joint-hirer-attr.interface.ts +10 -10
  87. package/src/interfaces/rental-attr.interface.ts +25 -25
  88. package/src/interfaces/rental-find-all-search-attr.interface.ts +11 -11
  89. package/src/interfaces/rental-price-attr.interface.ts +7 -7
  90. package/src/interfaces/response-hirer-signature-attr.interface.ts +16 -0
  91. package/src/models/agreement.entity.ts +43 -39
  92. package/src/models/booking.entity.ts +105 -105
  93. package/src/models/hirer-signature.entity.ts +81 -0
  94. package/src/models/index.ts +15 -13
  95. package/src/models/joint-hirer.entity.ts +63 -63
  96. package/src/models/rental-price.entity.ts +38 -38
  97. package/src/models/rental.entity.ts +133 -133
  98. package/tsconfig.build.json +5 -5
  99. package/tsconfig.json +24 -24
@@ -1,96 +1,96 @@
1
- 'use strict';
2
-
3
- /** @type {import('sequelize-cli').Migration} */
4
- module.exports = {
5
- async up(queryInterface, Sequelize) {
6
- await queryInterface.createTable('rental_Rental', {
7
- RentalId: {
8
- type: Sequelize.STRING(30),
9
- allowNull: false,
10
- primaryKey: true,
11
- },
12
- CustomerId: {
13
- type: Sequelize.STRING(30),
14
- allowNull: false,
15
- },
16
- CustomerType: {
17
- type: Sequelize.STRING(30),
18
- allowNull: false,
19
- },
20
- ItemId: {
21
- type: Sequelize.STRING(30),
22
- allowNull: false,
23
- },
24
- ItemType: {
25
- type: Sequelize.STRING(30),
26
- allowNull: false,
27
- },
28
- PriceId: {
29
- type: Sequelize.STRING(30),
30
- allowNull: false,
31
- references: {
32
- model: 'rental_Price',
33
- key: 'PriceId',
34
- },
35
- onUpdate: 'CASCADE',
36
- onDelete: 'CASCADE',
37
- },
38
- StartDateTime: {
39
- type: Sequelize.DATE,
40
- allowNull: false,
41
- },
42
- EndDateTime: {
43
- type: Sequelize.DATE,
44
- allowNull: false,
45
- },
46
- Status: {
47
- type: Sequelize.STRING(50),
48
- allowNull: false,
49
- },
50
- CancelRemarks: {
51
- type: Sequelize.STRING(3000),
52
- },
53
- TerminateRemarks: {
54
- type: Sequelize.STRING(3000),
55
- },
56
- EscheatmentYN: {
57
- type: Sequelize.CHAR(1),
58
- },
59
- AgreementNo: {
60
- type: Sequelize.STRING(30),
61
- allowNull: false,
62
- unique: true,
63
- references: {
64
- model: 'rental_Agreement',
65
- key: 'AgreementNo',
66
- },
67
- onUpdate: 'CASCADE',
68
- onDelete: 'CASCADE',
69
- },
70
- AccountType: {
71
- type: Sequelize.STRING(10),
72
- allowNull: false,
73
- },
74
- CreatedById: {
75
- type: Sequelize.STRING(30),
76
- allowNull: false,
77
- },
78
- CreatedAt: {
79
- type: Sequelize.DATE,
80
- allowNull: false,
81
- },
82
- UpdatedById: {
83
- type: Sequelize.STRING(30),
84
- allowNull: false,
85
- },
86
- UpdatedAt: {
87
- type: Sequelize.DATE,
88
- allowNull: false,
89
- },
90
- });
91
- },
92
-
93
- async down(queryInterface) {
94
- await queryInterface.dropTable('rental_Rental');
95
- },
96
- };
1
+ 'use strict';
2
+
3
+ /** @type {import('sequelize-cli').Migration} */
4
+ module.exports = {
5
+ async up(queryInterface, Sequelize) {
6
+ await queryInterface.createTable('rental_Rental', {
7
+ RentalId: {
8
+ type: Sequelize.STRING(30),
9
+ allowNull: false,
10
+ primaryKey: true,
11
+ },
12
+ CustomerId: {
13
+ type: Sequelize.STRING(30),
14
+ allowNull: false,
15
+ },
16
+ CustomerType: {
17
+ type: Sequelize.STRING(30),
18
+ allowNull: false,
19
+ },
20
+ ItemId: {
21
+ type: Sequelize.STRING(30),
22
+ allowNull: false,
23
+ },
24
+ ItemType: {
25
+ type: Sequelize.STRING(30),
26
+ allowNull: false,
27
+ },
28
+ PriceId: {
29
+ type: Sequelize.STRING(30),
30
+ allowNull: false,
31
+ references: {
32
+ model: 'rental_Price',
33
+ key: 'PriceId',
34
+ },
35
+ onUpdate: 'CASCADE',
36
+ onDelete: 'CASCADE',
37
+ },
38
+ StartDateTime: {
39
+ type: Sequelize.DATE,
40
+ allowNull: false,
41
+ },
42
+ EndDateTime: {
43
+ type: Sequelize.DATE,
44
+ allowNull: false,
45
+ },
46
+ Status: {
47
+ type: Sequelize.STRING(50),
48
+ allowNull: false,
49
+ },
50
+ CancelRemarks: {
51
+ type: Sequelize.STRING(3000),
52
+ },
53
+ TerminateRemarks: {
54
+ type: Sequelize.STRING(3000),
55
+ },
56
+ EscheatmentYN: {
57
+ type: Sequelize.CHAR(1),
58
+ },
59
+ AgreementNo: {
60
+ type: Sequelize.STRING(30),
61
+ allowNull: false,
62
+ unique: true,
63
+ references: {
64
+ model: 'rental_Agreement',
65
+ key: 'AgreementNo',
66
+ },
67
+ onUpdate: 'CASCADE',
68
+ onDelete: 'CASCADE',
69
+ },
70
+ AccountType: {
71
+ type: Sequelize.STRING(10),
72
+ allowNull: false,
73
+ },
74
+ CreatedById: {
75
+ type: Sequelize.STRING(30),
76
+ allowNull: false,
77
+ },
78
+ CreatedAt: {
79
+ type: Sequelize.DATE,
80
+ allowNull: false,
81
+ },
82
+ UpdatedById: {
83
+ type: Sequelize.STRING(30),
84
+ allowNull: false,
85
+ },
86
+ UpdatedAt: {
87
+ type: Sequelize.DATE,
88
+ allowNull: false,
89
+ },
90
+ });
91
+ },
92
+
93
+ async down(queryInterface) {
94
+ await queryInterface.dropTable('rental_Rental');
95
+ },
96
+ };
package/package.json CHANGED
@@ -1,75 +1,75 @@
1
- {
2
- "name": "@tomei/rental",
3
- "version": "0.12.4",
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": "^19.6.0",
30
- "@commitlint/config-conventional": "^19.6.0",
31
- "@eslint/js": "^9.15.0",
32
- "@tsconfig/node18": "^18.2.4",
33
- "@types/jest": "^29.5.14",
34
- "@types/luxon": "^3.4.2",
35
- "@types/node": "^22.10.0",
36
- "@types/validator": "^13.12.2",
37
- "@typescript-eslint/eslint-plugin": "^8.16.0",
38
- "dotenv": "^16.4.5",
39
- "eslint": "^9.15.0",
40
- "eslint-config-prettier": "^9.1.0",
41
- "eslint-plugin-import": "^2.31.0",
42
- "eslint-plugin-prettier": "^5.2.1",
43
- "globals": "^15.12.0",
44
- "husky": "^9.1.7",
45
- "jest": "^29.7.0",
46
- "jest-mock-extended": "^3.0.7",
47
- "lint-staged": "^15.2.10",
48
- "prettier": "^3.4.1",
49
- "ts-jest": "^29.2.5",
50
- "ts-node": "^10.9.2",
51
- "tsc-watch": "^6.2.1",
52
- "tsconfig-paths": "^4.2.0",
53
- "typescript": "^5.7.2",
54
- "typescript-eslint": "^8.16.0"
55
- },
56
- "publishConfig": {
57
- "access": "public"
58
- },
59
- "peerDependencies": {
60
- "@tomei/activity-history": "^0.2.23",
61
- "@tomei/config": "^0.3.21",
62
- "@tomei/general": "^0.21.3",
63
- "@tomei/sso": "^0.51.6",
64
- "luxon": "^3.5.0",
65
- "reflect-metadata": "^0.2.2",
66
- "sequelize": "^6.37.5",
67
- "sequelize-typescript": "^2.1.6"
68
- },
69
- "lint-staged": {
70
- "*/**/*.{js,ts,tsx}": [
71
- "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
72
- "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
73
- ]
74
- }
75
- }
1
+ {
2
+ "name": "@tomei/rental",
3
+ "version": "0.13.0",
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": "^19.6.0",
30
+ "@commitlint/config-conventional": "^19.6.0",
31
+ "@eslint/js": "^9.15.0",
32
+ "@tsconfig/node18": "^18.2.4",
33
+ "@types/jest": "^29.5.14",
34
+ "@types/luxon": "^3.4.2",
35
+ "@types/node": "^22.10.0",
36
+ "@types/validator": "^13.12.2",
37
+ "@typescript-eslint/eslint-plugin": "^8.16.0",
38
+ "dotenv": "^16.4.5",
39
+ "eslint": "^9.15.0",
40
+ "eslint-config-prettier": "^9.1.0",
41
+ "eslint-plugin-import": "^2.31.0",
42
+ "eslint-plugin-prettier": "^5.2.1",
43
+ "globals": "^15.12.0",
44
+ "husky": "^9.1.7",
45
+ "jest": "^29.7.0",
46
+ "jest-mock-extended": "^3.0.7",
47
+ "lint-staged": "^15.2.10",
48
+ "prettier": "^3.4.1",
49
+ "ts-jest": "^29.2.5",
50
+ "ts-node": "^10.9.2",
51
+ "tsc-watch": "^6.2.1",
52
+ "tsconfig-paths": "^4.2.0",
53
+ "typescript": "^5.7.2",
54
+ "typescript-eslint": "^8.16.0"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public"
58
+ },
59
+ "peerDependencies": {
60
+ "@tomei/activity-history": "^0.2.23",
61
+ "@tomei/config": "^0.3.21",
62
+ "@tomei/general": "^0.21.3",
63
+ "@tomei/sso": "^0.51.6",
64
+ "luxon": "^3.5.0",
65
+ "reflect-metadata": "^0.2.2",
66
+ "sequelize": "^6.37.5",
67
+ "sequelize-typescript": "^2.1.6"
68
+ },
69
+ "lint-staged": {
70
+ "*/**/*.{js,ts,tsx}": [
71
+ "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
72
+ "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
73
+ ]
74
+ }
75
+ }
@@ -1,13 +1,13 @@
1
- sonar.projectKey=all-tomei-projects_rental
2
- sonar.organization=all-tomei-projects
3
-
4
- # This is the name and version displayed in the SonarCloud UI.
5
- #sonar.projectName=Rental
6
- #sonar.projectVersion=1.0
7
-
8
-
9
- # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
10
- #sonar.sources=.
11
-
12
- # Encoding of the source code. Default is default system encoding
1
+ sonar.projectKey=all-tomei-projects_rental
2
+ sonar.organization=all-tomei-projects
3
+
4
+ # This is the name and version displayed in the SonarCloud UI.
5
+ #sonar.projectName=Rental
6
+ #sonar.projectVersion=1.0
7
+
8
+
9
+ # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
10
+ #sonar.sources=.
11
+
12
+ # Encoding of the source code. Default is default system encoding
13
13
  #sonar.sourceEncoding=UTF-8
@@ -1,54 +1,54 @@
1
- import { RepositoryBase, IRepositoryBase } from '@tomei/general';
2
- import { AgreementModel } from '../../models/agreement.entity';
3
-
4
- export class AgreementRepository
5
- extends RepositoryBase<AgreementModel>
6
- implements IRepositoryBase<AgreementModel>
7
- {
8
- constructor() {
9
- super(AgreementModel);
10
- }
11
-
12
- async findByPk(
13
- id: string,
14
- transaction?: any,
15
- ): Promise<AgreementModel | null> {
16
- try {
17
- const result = await AgreementModel.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(AgreementNo: string, dbTransaction?: any) {
28
- try {
29
- const options = {
30
- where: {
31
- AgreementNo,
32
- },
33
- transaction: dbTransaction,
34
- };
35
- await AgreementModel.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 Agreements: any;
44
- if (options) {
45
- Agreements = await AgreementModel.findAndCountAll(options);
46
- } else {
47
- Agreements = await AgreementModel.findAndCountAll();
48
- }
49
- return Agreements;
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 { AgreementModel } from '../../models/agreement.entity';
3
+
4
+ export class AgreementRepository
5
+ extends RepositoryBase<AgreementModel>
6
+ implements IRepositoryBase<AgreementModel>
7
+ {
8
+ constructor() {
9
+ super(AgreementModel);
10
+ }
11
+
12
+ async findByPk(
13
+ id: string,
14
+ transaction?: any,
15
+ ): Promise<AgreementModel | null> {
16
+ try {
17
+ const result = await AgreementModel.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(AgreementNo: string, dbTransaction?: any) {
28
+ try {
29
+ const options = {
30
+ where: {
31
+ AgreementNo,
32
+ },
33
+ transaction: dbTransaction,
34
+ };
35
+ await AgreementModel.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 Agreements: any;
44
+ if (options) {
45
+ Agreements = await AgreementModel.findAndCountAll(options);
46
+ } else {
47
+ Agreements = await AgreementModel.findAndCountAll();
48
+ }
49
+ return Agreements;
50
+ } catch (error) {
51
+ throw new Error(`An Error occured when retriving : ${error.message}`);
52
+ }
53
+ }
54
+ }
@@ -1,49 +1,117 @@
1
- import { ObjectBase } from '@tomei/general';
2
- import { IAgreementAttr } from '../../interfaces/agreement-attr.interface';
3
- import { AgreementRepository } from './agreement.repository';
4
- import { AggrementStatusEnum } from '../../enum/aggrement-status.enum';
5
-
6
- export class Agreement extends ObjectBase {
7
- ObjectId: string;
8
- ObjectName: string;
9
- ObjectType: string = 'Agreement';
10
- TableName = 'rental_Agreement';
11
- Status: AggrementStatusEnum;
12
- DateSigned: Date;
13
- MediaId: string;
14
-
15
- private static _Repo = new AgreementRepository();
16
-
17
- get AgreementNo(): string {
18
- return this.ObjectId;
19
- }
20
-
21
- set AgreementNo(value: string) {
22
- this.ObjectId = value;
23
- }
24
-
25
- protected constructor(agreementAttr?: IAgreementAttr) {
26
- super();
27
- if (agreementAttr) {
28
- this.ObjectId = agreementAttr.AgreementNo;
29
- this.Status = agreementAttr.Status;
30
- this.DateSigned = agreementAttr.DateSigned;
31
- this.MediaId = agreementAttr.MediaId;
32
- }
33
- }
34
-
35
- public static async init(
36
- agreementNo?: string,
37
- dbTransaction?: any,
38
- ): Promise<Agreement> {
39
- try {
40
- if (agreementNo) {
41
- const agreement = await this._Repo.findByPk(agreementNo, dbTransaction);
42
- return new Agreement(agreement?.get({ plain: true }));
43
- }
44
- return new Agreement();
45
- } catch (error) {
46
- throw error;
47
- }
48
- }
49
- }
1
+ import { ClassError, ObjectBase } from '@tomei/general';
2
+ import { AggrementStatusEnum } from '../../enum/aggrement-status.enum';
3
+ import { IAgreementAttr } from '../../interfaces/agreement-attr.interface';
4
+ import { AgreementRepository } from './agreement.repository';
5
+ import { ApplicationConfig } from '@tomei/config';
6
+ import { LoginUser } from '@tomei/sso';
7
+ import { HirerSignatureRepository } from '../hirer-signature/hirer-signature.repository';
8
+ import * as rentalDb from '../../database';
9
+ import { QueryTypes } from 'sequelize';
10
+ import { IResponseHirerSignature } from '../../interfaces/response-hirer-signature-attr.interface';
11
+
12
+ export class Agreement extends ObjectBase {
13
+ ObjectId: string;
14
+ ObjectName: string;
15
+ ObjectType: string = 'Agreement';
16
+ TableName = 'rental_Agreement';
17
+ Status: AggrementStatusEnum;
18
+ DateSigned: Date;
19
+ MediaId: string;
20
+
21
+ private static _Repo = new AgreementRepository();
22
+ protected static _HirerSignatureRepo = new HirerSignatureRepository();
23
+
24
+ get AgreementNo(): string {
25
+ return this.ObjectId;
26
+ }
27
+
28
+ set AgreementNo(value: string) {
29
+ this.ObjectId = value;
30
+ }
31
+
32
+ protected constructor(agreementAttr?: IAgreementAttr) {
33
+ super();
34
+ if (agreementAttr) {
35
+ this.ObjectId = agreementAttr.AgreementNo;
36
+ this.Status = agreementAttr.Status;
37
+ this.DateSigned = agreementAttr.DateSigned;
38
+ this.MediaId = agreementAttr.MediaId;
39
+ }
40
+ }
41
+
42
+ public static async init(
43
+ agreementNo?: string,
44
+ dbTransaction?: any,
45
+ ): Promise<Agreement> {
46
+ try {
47
+ if (agreementNo) {
48
+ const agreement = await this._Repo.findByPk(agreementNo, dbTransaction);
49
+ return new Agreement(agreement?.get({ plain: true }));
50
+ }
51
+ return new Agreement();
52
+ } catch (error) {
53
+ throw error;
54
+ }
55
+ }
56
+
57
+ public static async getSignatureList(
58
+ loginUser: LoginUser,
59
+ agreementNo: string,
60
+ dbTransaction: any,
61
+ ) {
62
+ try {
63
+ // Part 1: Privilege Checking
64
+ // Call loginUser.checkPrivileges() by passing:
65
+ // SystemCode: "<get_from_app_config>"
66
+ // PrivilegeCode: "AGREEMENT_SIGNATURE_LIST"
67
+ const systemCode =
68
+ ApplicationConfig.getComponentConfigValue('system-code');
69
+ const isPrivileged = loginUser.checkPrivileges(
70
+ systemCode,
71
+ 'AGREEMENT_SIGNATURE_LIST',
72
+ );
73
+
74
+ if (!isPrivileged) {
75
+ throw new ClassError(
76
+ 'Agreement',
77
+ 'AgreementErrMsg01',
78
+ "You do not have 'AGREEMENT_SIGNATURE_LIST' privilege.",
79
+ );
80
+ }
81
+
82
+ // Part 2: Validation
83
+ // Make sure agreementNo exists, if not throw new ClassError by passing:
84
+ if (!agreementNo) {
85
+ throw new ClassError(
86
+ 'AgreementNo',
87
+ 'AgreementNoErrMsg01',
88
+ 'AgreementNo is missing',
89
+ );
90
+ }
91
+
92
+ // Part 3: Retrieve Listing
93
+ const query = `
94
+ SELECT
95
+ hs.*,
96
+ c.FullName
97
+ FROM
98
+ rental_HirerSignature hs
99
+ LEFT JOIN
100
+ sdb_Customer c ON hs.CustomerId = c.CustomerId
101
+ WHERE
102
+ hs.AgreementNo = '${agreementNo}'
103
+ `;
104
+
105
+ const db = rentalDb.getConnection();
106
+ const signatures: IResponseHirerSignature[] = await db.query(query, {
107
+ type: QueryTypes.SELECT,
108
+ transaction: dbTransaction,
109
+ });
110
+
111
+ // Part 4: Return the returned records.
112
+ return signatures;
113
+ } catch (error) {
114
+ throw error;
115
+ }
116
+ }
117
+ }