@tomei/rental 0.11.4 → 0.12.2

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 (98) hide show
  1. package/.husky/commit-msg +0 -0
  2. package/.husky/pre-commit +0 -0
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.js +17 -17
  5. package/dist/src/components/agreement/agreement.d.ts +17 -17
  6. package/dist/src/components/agreement/agreement.js +49 -49
  7. package/dist/src/components/agreement/agreement.js.map +1 -1
  8. package/dist/src/components/agreement/agreement.repository.d.ts +8 -8
  9. package/dist/src/components/agreement/agreement.repository.js +66 -66
  10. package/dist/src/components/agreement/agreement.repository.js.map +1 -1
  11. package/dist/src/components/booking/booking.d.ts +46 -45
  12. package/dist/src/components/booking/booking.js +313 -271
  13. package/dist/src/components/booking/booking.js.map +1 -1
  14. package/dist/src/components/booking/booking.repository.d.ts +8 -8
  15. package/dist/src/components/booking/booking.repository.js +66 -66
  16. package/dist/src/components/booking/booking.repository.js.map +1 -1
  17. package/dist/src/components/joint-hirer/joint-hirer.d.ts +23 -23
  18. package/dist/src/components/joint-hirer/joint-hirer.js +105 -105
  19. package/dist/src/components/joint-hirer/joint-hirer.js.map +1 -1
  20. package/dist/src/components/joint-hirer/joint-hirer.repository.d.ts +8 -8
  21. package/dist/src/components/joint-hirer/joint-hirer.repository.js +66 -66
  22. package/dist/src/components/joint-hirer/joint-hirer.repository.js.map +1 -1
  23. package/dist/src/components/rental/rental.d.ts +59 -59
  24. package/dist/src/components/rental/rental.js +603 -603
  25. package/dist/src/components/rental/rental.js.map +1 -1
  26. package/dist/src/components/rental/rental.repository.d.ts +8 -8
  27. package/dist/src/components/rental/rental.repository.js +66 -66
  28. package/dist/src/components/rental/rental.repository.js.map +1 -1
  29. package/dist/src/components/rental-price/rental-price.d.ts +18 -18
  30. package/dist/src/components/rental-price/rental-price.js +78 -78
  31. package/dist/src/components/rental-price/rental-price.js.map +1 -1
  32. package/dist/src/components/rental-price/rental-price.repository.d.ts +8 -8
  33. package/dist/src/components/rental-price/rental-price.repository.js +66 -66
  34. package/dist/src/components/rental-price/rental-price.repository.js.map +1 -1
  35. package/dist/src/database.d.ts +4 -4
  36. package/dist/src/database.js +24 -25
  37. package/dist/src/database.js.map +1 -1
  38. package/dist/src/enum/account-type.enum.d.ts +4 -4
  39. package/dist/src/enum/account-type.enum.js +8 -8
  40. package/dist/src/enum/account-type.enum.js.map +1 -1
  41. package/dist/src/enum/aggrement-status.enum.d.ts +5 -5
  42. package/dist/src/enum/aggrement-status.enum.js +9 -9
  43. package/dist/src/enum/aggrement-status.enum.js.map +1 -1
  44. package/dist/src/enum/booking.enum.d.ts +5 -5
  45. package/dist/src/enum/booking.enum.js +9 -9
  46. package/dist/src/enum/booking.enum.js.map +1 -1
  47. package/dist/src/enum/index.d.ts +5 -5
  48. package/dist/src/enum/index.js +11 -11
  49. package/dist/src/enum/rental-status.enum.d.ts +9 -9
  50. package/dist/src/enum/rental-status.enum.js +13 -13
  51. package/dist/src/enum/rental-status.enum.js.map +1 -1
  52. package/dist/src/index.d.ts +15 -15
  53. package/dist/src/index.js +42 -42
  54. package/dist/src/interfaces/agreement-attr.interface.d.ts +7 -7
  55. package/dist/src/interfaces/agreement-attr.interface.js +2 -2
  56. package/dist/src/interfaces/booking-attr.interface.d.ts +18 -18
  57. package/dist/src/interfaces/booking-attr.interface.js +2 -2
  58. package/dist/src/interfaces/booking-find-all-search-attr.interface.d.ts +12 -12
  59. package/dist/src/interfaces/booking-find-all-search-attr.interface.js +2 -2
  60. package/dist/src/interfaces/index.d.ts +7 -7
  61. package/dist/src/interfaces/index.js +2 -2
  62. package/dist/src/interfaces/joint-hirer-attr.interface.d.ts +10 -10
  63. package/dist/src/interfaces/joint-hirer-attr.interface.js +2 -2
  64. package/dist/src/interfaces/rental-attr.interface.d.ts +24 -24
  65. package/dist/src/interfaces/rental-attr.interface.js +2 -2
  66. package/dist/src/interfaces/rental-find-all-search-attr.interface.d.ts +10 -10
  67. package/dist/src/interfaces/rental-find-all-search-attr.interface.js +2 -2
  68. package/dist/src/interfaces/rental-price-attr.interface.d.ts +7 -7
  69. package/dist/src/interfaces/rental-price-attr.interface.js +2 -2
  70. package/dist/src/models/agreement.entity.d.ts +10 -10
  71. package/dist/src/models/agreement.entity.js +59 -59
  72. package/dist/src/models/agreement.entity.js.map +1 -1
  73. package/dist/src/models/booking.entity.d.ts +21 -21
  74. package/dist/src/models/booking.entity.js +127 -127
  75. package/dist/src/models/booking.entity.js.map +1 -1
  76. package/dist/src/models/index.d.ts +6 -6
  77. package/dist/src/models/index.js +13 -13
  78. package/dist/src/models/joint-hirer.entity.d.ts +13 -13
  79. package/dist/src/models/joint-hirer.entity.js +78 -78
  80. package/dist/src/models/joint-hirer.entity.js.map +1 -1
  81. package/dist/src/models/rental-price.entity.d.ts +8 -8
  82. package/dist/src/models/rental-price.entity.js +58 -58
  83. package/dist/src/models/rental-price.entity.js.map +1 -1
  84. package/dist/src/models/rental.entity.d.ts +29 -29
  85. package/dist/src/models/rental.entity.js +159 -159
  86. package/dist/src/models/rental.entity.js.map +1 -1
  87. package/dist/tsconfig.tsbuildinfo +1 -1
  88. package/eslint.config.mjs +37 -0
  89. package/migrations/booking-table-migration.js +1 -1
  90. package/migrations/joint-hirer-table-migration.js +1 -1
  91. package/migrations/rental-aggrement-table-migration.js +1 -1
  92. package/migrations/rental-price-table-migration.js +1 -1
  93. package/migrations/rental-table-migrations.js +1 -1
  94. package/package.json +33 -30
  95. package/src/components/booking/booking.ts +94 -1
  96. package/src/components/joint-hirer/joint-hirer.ts +1 -1
  97. package/src/components/rental/rental.ts +7 -10
  98. package/.eslintignore +0 -1
@@ -0,0 +1,37 @@
1
+ import eslintPlugin from "@typescript-eslint/eslint-plugin";
2
+ import parser from "@typescript-eslint/parser";
3
+
4
+ export default [
5
+ {
6
+ languageOptions: {
7
+ parser: parser,
8
+ ecmaVersion: "latest", // Allows modern ECMAScript features
9
+ sourceType: "module", // Allows for the use of imports
10
+ },
11
+ plugins: {
12
+ "@typescript-eslint": eslintPlugin,
13
+ },
14
+ rules: {
15
+ "no-console": "off",
16
+ "@typescript-eslint/no-explicit-any": "off",
17
+ "@typescript-eslint/no-var-requires": "off",
18
+ "@typescript-eslint/explicit-module-boundary-types": "off",
19
+ "import/prefer-default-export": "off",
20
+ "@typescript-eslint/no-unused-vars": "warn",
21
+ "no-useless-catch": "off",
22
+ "@typescript-eslint/no-non-null-assertion": "off",
23
+ "@typescript-eslint/no-empty-function": "off",
24
+ "@typescript-eslint/no-empty-interface": "off",
25
+ "@typescript-eslint/no-inferrable-types": "off",
26
+ "@typescript-eslint/no-namespace": "off",
27
+ "@typescript-eslint/no-use-before-define": "off",
28
+ "@typescript-eslint/no-unsafe-assignment": "off",
29
+ "@typescript-eslint/no-unsafe-call": "off",
30
+ "@typescript-eslint/no-unsafe-member-access": "off",
31
+ "@typescript-eslint/no-unsafe-return": "off",
32
+ "@typescript-eslint/restrict-template-expressions": "off",
33
+ "no-useless-escape": "off",
34
+ },
35
+ ignores: ["node_modules", "dist"],
36
+ },
37
+ ];
@@ -73,7 +73,7 @@ module.exports = {
73
73
  });
74
74
  },
75
75
 
76
- async down(queryInterface, Sequelize) {
76
+ async down(queryInterface, _Sequelize) {
77
77
  await queryInterface.dropTable('booking_Booking');
78
78
  },
79
79
  };
@@ -46,7 +46,7 @@ module.exports = {
46
46
  });
47
47
  },
48
48
 
49
- async down(queryInterface, Sequelize) {
49
+ async down(queryInterface, _Sequelize) {
50
50
  await queryInterface.dropTable('rental_JointHirer');
51
51
  },
52
52
  };
@@ -24,7 +24,7 @@ module.exports = {
24
24
  });
25
25
  },
26
26
 
27
- async down(queryInterface, Sequelize) {
27
+ async down(queryInterface, _Sequelize) {
28
28
  await queryInterface.dropTable('rental_Agreement');
29
29
  },
30
30
  };
@@ -26,7 +26,7 @@ module.exports = {
26
26
  });
27
27
  },
28
28
 
29
- async down(queryInterface, Sequelize) {
29
+ async down(queryInterface, _Sequelize) {
30
30
  await queryInterface.dropTable('rental_Price');
31
31
  },
32
32
  };
@@ -90,7 +90,7 @@ module.exports = {
90
90
  });
91
91
  },
92
92
 
93
- async down(queryInterface, Sequelize) {
93
+ async down(queryInterface, _Sequelize) {
94
94
  await queryInterface.dropTable('rental_Rental');
95
95
  },
96
96
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/rental",
3
- "version": "0.11.4",
3
+ "version": "0.12.2",
4
4
  "description": "Tomei Rental Package",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -26,42 +26,45 @@
26
26
  },
27
27
  "homepage": "https://gitlab.com/tomei-package/rental#readme",
28
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",
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",
33
34
  "@types/luxon": "^3.4.2",
34
- "@types/node": "^18.17.12",
35
- "@types/validator": "^13.11.1",
36
- "@typescript-eslint/eslint-plugin": "^5.33.0",
37
- "dotenv": "^16.1.4",
38
- "eslint": "^8.40.0",
39
- "eslint-config-prettier": "^8.5.0",
40
- "eslint-plugin-prettier": "^4.2.1",
41
- "husky": "^8.0.3",
42
- "jest": "^29.5.0",
43
- "jest-mock-extended": "^3.0.4",
44
- "lint-staged": "^13.2.2",
45
- "prettier": "^2.7.1",
46
- "ts-jest": "^29.1.0",
47
- "ts-node": "^10.9.1",
48
- "tsc-watch": "^5.0.3",
49
- "tsconfig-paths": "^4.0.0",
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-prettier": "^5.2.1",
42
+ "globals": "^15.12.0",
43
+ "husky": "^9.1.7",
44
+ "jest": "^29.7.0",
45
+ "jest-mock-extended": "^3.0.7",
46
+ "lint-staged": "^15.2.10",
47
+ "prettier": "^3.4.1",
48
+ "ts-jest": "^29.2.5",
49
+ "ts-node": "^10.9.2",
50
+ "tsc-watch": "^6.2.1",
51
+ "tsconfig-paths": "^4.2.0",
50
52
  "tslint": "^6.1.3",
51
- "typescript": "^4.7.4"
53
+ "typescript": "^5.7.2",
54
+ "typescript-eslint": "^8.16.0"
52
55
  },
53
56
  "publishConfig": {
54
57
  "access": "public"
55
58
  },
56
59
  "peerDependencies": {
57
- "@tomei/activity-history": "^0.2.15",
58
- "@tomei/config": "^0.3.10",
59
- "@tomei/general": "^0.11.8",
60
- "@tomei/sso": "^0.21.13",
60
+ "@tomei/activity-history": "^0.2.21",
61
+ "@tomei/config": "^0.3.19",
62
+ "@tomei/general": "^0.21.0",
63
+ "@tomei/sso": "^0.51.3",
61
64
  "cuid": "^3.0.0",
62
- "reflect-metadata": "^0.1.13",
63
- "sequelize": "^6.32.1",
64
- "sequelize-typescript": "^2.1.5"
65
+ "reflect-metadata": "^0.2.2",
66
+ "sequelize": "^6.37.5",
67
+ "sequelize-typescript": "^2.1.6"
65
68
  },
66
69
  "lint-staged": {
67
70
  "*/**/*.{js,ts,tsx}": [
@@ -70,6 +73,6 @@
70
73
  ]
71
74
  },
72
75
  "dependencies": {
73
- "luxon": "^3.4.4"
76
+ "luxon": "^3.5.0"
74
77
  }
75
78
  }
@@ -238,7 +238,7 @@ export class Booking extends ObjectBase {
238
238
  //Part 4: Record Create Booking Activity
239
239
  const activity = new Activity();
240
240
  activity.ActivityId = activity.createId();
241
- activity.Action = ActionEnum.ADD;
241
+ activity.Action = ActionEnum.CREATE;
242
242
  activity.Description = 'Add Booking';
243
243
  activity.EntityId = this.BookingNo;
244
244
  activity.EntityType = this.ObjectType;
@@ -396,4 +396,97 @@ export class Booking extends ObjectBase {
396
396
  throw error;
397
397
  }
398
398
  }
399
+
400
+ public static async updateLeadToCustomer(
401
+ loginUser: LoginUser, //The user performing the operation. Used for tracking who initiated the update.
402
+ dbTransaction: any, //The database transaction object to ensure atomicity of the operation.
403
+ LeadId: string, //The identifier for the lead whose bookings will be updated.
404
+ CustomerId: string, //The identifier of the customer to replace the lead in the booking records.
405
+ ) {
406
+ // This method updates all booking records where LeadId matches the provided LeadId by replacing the LeadId with the CustomerId and updating the CustomerType from 'Lead' to 'Customer'.
407
+ try {
408
+ // Part 1: Privilege Checking
409
+ // Call loginUser.checkPrivileges() with parameters:
410
+ // SystemCode: Retrieve from app config.
411
+ // PrivilegeCode: 'BOOKING_UPDATE'.
412
+ const systemCode =
413
+ ApplicationConfig.getComponentConfigValue('system-code');
414
+ const isPrivileged = await loginUser.checkPrivileges(
415
+ systemCode,
416
+ 'BOOKING_UPDATE',
417
+ );
418
+ if (!isPrivileged) {
419
+ throw new ClassError(
420
+ 'Booking',
421
+ 'BookingErrMsg02',
422
+ "You do not have 'BOOKING_UPDATE' privilege",
423
+ );
424
+ }
425
+ // Part 2: Validation
426
+ // Validate the LeadId and CustomerId to ensure they are not null or invalid.
427
+ if (!LeadId || !CustomerId) {
428
+ throw new ClassError(
429
+ 'Booking',
430
+ 'BookingErrMsg02',
431
+ 'LeadId and CustomerId cannot be null or invalid',
432
+ );
433
+ }
434
+ // Part 3: Retrieve Records
435
+ // Retrieve all booking records:
436
+ // where
437
+ // [Op.AND]:
438
+ // CustomerId: Params.LeadId
439
+ // CustomerType: "Lead"
440
+ // dbTransaction
441
+ const bookings = await Booking._Repo.findAll({
442
+ where: {
443
+ [Op.and]: [{ CustomerId: LeadId }, { CustomerType: 'Lead' }],
444
+ },
445
+ transaction: dbTransaction,
446
+ });
447
+ // Part 5: Update Records and Record Activity
448
+ // For each matching booking record:
449
+ for (const booking of bookings) {
450
+ // Update the CustomerId from LeadId to CustomerId.
451
+ // Update the CustomerType from 'Lead' to 'Customer'.
452
+ // Ensure the UpdatedById and UpdatedAt fields in the SDB booking record are updated to reflect the loginUser and the current timestamp.
453
+ const EntityValueBefore = {
454
+ ...booking.get({ plain: true }),
455
+ };
456
+ booking.CustomerId = CustomerId;
457
+ booking.CustomerType = 'Customer';
458
+ booking.UpdatedById = loginUser.ObjectId;
459
+ booking.UpdatedAt = DateTime.now().toJSDate();
460
+ await booking.save({
461
+ transaction: dbTransaction,
462
+ });
463
+ // Record Update Activity:
464
+ // Initialise EntityValueAfter variable and set it to the updated SDB booking record.
465
+ // Instantiate a new activity from the Activity class, and set:
466
+ // ActivityId: activity.createId()
467
+ // Action: ActionEnum.Update
468
+ // Description: "Update Lead to Customer"
469
+ // EntityType: "Booking"
470
+ // EntityId: <UpdatedBookingRecord>.BookingId
471
+ // EntityValueBefore: Stringified representation of the original SDB booking record.
472
+ // EntityValueAfter: EntityValueAfter (stringified representation of the updated booking record).
473
+ const activity = new Activity();
474
+ activity.ActivityId = activity.createId();
475
+ activity.Action = ActionEnum.UPDATE;
476
+ activity.Description = 'Update Lead to Customer';
477
+ activity.EntityType = 'Booking';
478
+ activity.EntityId = booking.BookingNo;
479
+ activity.EntityValueBefore = JSON.stringify(EntityValueBefore);
480
+ activity.EntityValueAfter = JSON.stringify(
481
+ booking.get({ plain: true }),
482
+ );
483
+ // Call the activity create() method by passing:
484
+ // dbTransaction
485
+ // userId: loginUser.UserId
486
+ await activity.create(loginUser.ObjectId, dbTransaction);
487
+ }
488
+ } catch (error) {
489
+ throw error;
490
+ }
491
+ }
399
492
  }
@@ -120,7 +120,7 @@ export class JointHirer extends ObjectBase {
120
120
  //Part 4: Record Create JointHirer Activity
121
121
  const activity = new Activity();
122
122
  activity.ObjectId = this._createId();
123
- activity.Action = ActionEnum.ADD;
123
+ activity.Action = ActionEnum.CREATE;
124
124
  activity.Description = 'Add Joint Hirer';
125
125
  activity.EntityId = this.ObjectId;
126
126
  activity.EntityType = this.ObjectType;
@@ -247,7 +247,7 @@ export class Rental extends ObjectBase {
247
247
  /*Part 5: Record Create Rental Activity*/
248
248
  const activity = new Activity();
249
249
  activity.ActivityId = activity.createId();
250
- activity.Action = ActionEnum.ADD;
250
+ activity.Action = ActionEnum.CREATE;
251
251
  activity.Description = 'Add Rental';
252
252
  activity.EntityType = 'Rental';
253
253
  activity.EntityId = this.RentalId;
@@ -302,9 +302,8 @@ export class Rental extends ObjectBase {
302
302
  search?: IRentalFindAllSearchAttr,
303
303
  ) {
304
304
  try {
305
- const systemCode = await ApplicationConfig.getComponentConfigValue(
306
- 'system-code',
307
- );
305
+ const systemCode =
306
+ await ApplicationConfig.getComponentConfigValue('system-code');
308
307
 
309
308
  const isPrivileged = await loginUser.checkPrivileges(
310
309
  systemCode,
@@ -399,9 +398,8 @@ export class Rental extends ObjectBase {
399
398
  dbTransaction?: any,
400
399
  ) {
401
400
  try {
402
- const systemCode = await ApplicationConfig.getComponentConfigValue(
403
- 'system-code',
404
- );
401
+ const systemCode =
402
+ await ApplicationConfig.getComponentConfigValue('system-code');
405
403
 
406
404
  const isPrivileged = await loginUser.checkPrivileges(
407
405
  systemCode,
@@ -484,9 +482,8 @@ export class Rental extends ObjectBase {
484
482
  ) {
485
483
  try {
486
484
  // Privilege Checking
487
- const systemCode = await ApplicationConfig.getComponentConfigValue(
488
- 'system-code',
489
- );
485
+ const systemCode =
486
+ await ApplicationConfig.getComponentConfigValue('system-code');
490
487
 
491
488
  const isPrivileged = await loginUser.checkPrivileges(
492
489
  systemCode,
package/.eslintignore DELETED
@@ -1 +0,0 @@
1
- dist