@tomei/rental 0.12.2 → 0.12.3

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 (147) hide show
  1. package/.commitlintrc.json +22 -22
  2. package/.eslintrc +16 -16
  3. package/.eslintrc.js +35 -35
  4. package/.gitlab-ci.yml +16 -16
  5. package/.husky/commit-msg +15 -15
  6. package/.husky/pre-commit +7 -7
  7. package/.prettierrc +4 -4
  8. package/Jenkinsfile +51 -51
  9. package/README.md +8 -8
  10. package/eslint.config.mjs +37 -37
  11. package/jest.config.js +10 -10
  12. package/migrations/booking-table-migration.js +79 -79
  13. package/migrations/joint-hirer-table-migration.js +52 -52
  14. package/migrations/rental-aggrement-table-migration.js +30 -30
  15. package/migrations/rental-price-table-migration.js +32 -32
  16. package/migrations/rental-table-migrations.js +96 -96
  17. package/package.json +78 -78
  18. package/sonar-project.properties +12 -12
  19. package/src/components/agreement/agreement.repository.ts +54 -54
  20. package/src/components/agreement/agreement.ts +49 -49
  21. package/src/components/booking/booking.repository.ts +51 -51
  22. package/src/components/booking/booking.ts +492 -492
  23. package/src/components/joint-hirer/joint-hirer.repository.ts +54 -54
  24. package/src/components/joint-hirer/joint-hirer.ts +137 -137
  25. package/src/components/rental/rental.repository.ts +51 -51
  26. package/src/components/rental/rental.ts +963 -963
  27. package/src/components/rental-price/rental-price.repository.ts +54 -54
  28. package/src/components/rental-price/rental-price.ts +100 -100
  29. package/src/database.ts +27 -27
  30. package/src/enum/account-type.enum.ts +4 -4
  31. package/src/enum/booking.enum.ts +5 -5
  32. package/src/enum/index.ts +11 -11
  33. package/src/enum/rental-status.enum.ts +39 -39
  34. package/src/index.ts +28 -28
  35. package/src/interfaces/agreement-attr.interface.ts +7 -7
  36. package/src/interfaces/booking-attr.interface.ts +19 -19
  37. package/src/interfaces/booking-find-all-search-attr.interface.ts +12 -12
  38. package/src/interfaces/index.ts +15 -15
  39. package/src/interfaces/joint-hirer-attr.interface.ts +10 -10
  40. package/src/interfaces/rental-attr.interface.ts +25 -25
  41. package/src/interfaces/rental-find-all-search-attr.interface.ts +11 -11
  42. package/src/interfaces/rental-price-attr.interface.ts +7 -7
  43. package/src/models/agreement.entity.ts +39 -39
  44. package/src/models/booking.entity.ts +105 -105
  45. package/src/models/index.ts +13 -13
  46. package/src/models/joint-hirer.entity.ts +63 -63
  47. package/src/models/rental-price.entity.ts +38 -38
  48. package/src/models/rental.entity.ts +133 -133
  49. package/tsconfig.build.json +5 -5
  50. package/tsconfig.json +23 -23
  51. package/dist/index.d.ts +0 -1
  52. package/dist/index.js +0 -18
  53. package/dist/index.js.map +0 -1
  54. package/dist/src/components/agreement/agreement.d.ts +0 -17
  55. package/dist/src/components/agreement/agreement.js +0 -50
  56. package/dist/src/components/agreement/agreement.js.map +0 -1
  57. package/dist/src/components/agreement/agreement.repository.d.ts +0 -8
  58. package/dist/src/components/agreement/agreement.repository.js +0 -67
  59. package/dist/src/components/agreement/agreement.repository.js.map +0 -1
  60. package/dist/src/components/booking/booking.d.ts +0 -46
  61. package/dist/src/components/booking/booking.js +0 -314
  62. package/dist/src/components/booking/booking.js.map +0 -1
  63. package/dist/src/components/booking/booking.repository.d.ts +0 -8
  64. package/dist/src/components/booking/booking.repository.js +0 -67
  65. package/dist/src/components/booking/booking.repository.js.map +0 -1
  66. package/dist/src/components/joint-hirer/joint-hirer.d.ts +0 -23
  67. package/dist/src/components/joint-hirer/joint-hirer.js +0 -106
  68. package/dist/src/components/joint-hirer/joint-hirer.js.map +0 -1
  69. package/dist/src/components/joint-hirer/joint-hirer.repository.d.ts +0 -8
  70. package/dist/src/components/joint-hirer/joint-hirer.repository.js +0 -67
  71. package/dist/src/components/joint-hirer/joint-hirer.repository.js.map +0 -1
  72. package/dist/src/components/rental/rental.d.ts +0 -59
  73. package/dist/src/components/rental/rental.js +0 -619
  74. package/dist/src/components/rental/rental.js.map +0 -1
  75. package/dist/src/components/rental/rental.repository.d.ts +0 -8
  76. package/dist/src/components/rental/rental.repository.js +0 -67
  77. package/dist/src/components/rental/rental.repository.js.map +0 -1
  78. package/dist/src/components/rental-price/rental-price.d.ts +0 -18
  79. package/dist/src/components/rental-price/rental-price.js +0 -79
  80. package/dist/src/components/rental-price/rental-price.js.map +0 -1
  81. package/dist/src/components/rental-price/rental-price.repository.d.ts +0 -8
  82. package/dist/src/components/rental-price/rental-price.repository.js +0 -67
  83. package/dist/src/components/rental-price/rental-price.repository.js.map +0 -1
  84. package/dist/src/database.d.ts +0 -4
  85. package/dist/src/database.js +0 -25
  86. package/dist/src/database.js.map +0 -1
  87. package/dist/src/enum/account-type.enum.d.ts +0 -4
  88. package/dist/src/enum/account-type.enum.js +0 -9
  89. package/dist/src/enum/account-type.enum.js.map +0 -1
  90. package/dist/src/enum/aggrement-status.enum.d.ts +0 -5
  91. package/dist/src/enum/aggrement-status.enum.js +0 -10
  92. package/dist/src/enum/aggrement-status.enum.js.map +0 -1
  93. package/dist/src/enum/booking.enum.d.ts +0 -5
  94. package/dist/src/enum/booking.enum.js +0 -10
  95. package/dist/src/enum/booking.enum.js.map +0 -1
  96. package/dist/src/enum/index.d.ts +0 -5
  97. package/dist/src/enum/index.js +0 -12
  98. package/dist/src/enum/index.js.map +0 -1
  99. package/dist/src/enum/rental-status.enum.d.ts +0 -9
  100. package/dist/src/enum/rental-status.enum.js +0 -14
  101. package/dist/src/enum/rental-status.enum.js.map +0 -1
  102. package/dist/src/index.d.ts +0 -15
  103. package/dist/src/index.js +0 -43
  104. package/dist/src/index.js.map +0 -1
  105. package/dist/src/interfaces/agreement-attr.interface.d.ts +0 -7
  106. package/dist/src/interfaces/agreement-attr.interface.js +0 -3
  107. package/dist/src/interfaces/agreement-attr.interface.js.map +0 -1
  108. package/dist/src/interfaces/booking-attr.interface.d.ts +0 -18
  109. package/dist/src/interfaces/booking-attr.interface.js +0 -3
  110. package/dist/src/interfaces/booking-attr.interface.js.map +0 -1
  111. package/dist/src/interfaces/booking-find-all-search-attr.interface.d.ts +0 -12
  112. package/dist/src/interfaces/booking-find-all-search-attr.interface.js +0 -3
  113. package/dist/src/interfaces/booking-find-all-search-attr.interface.js.map +0 -1
  114. package/dist/src/interfaces/index.d.ts +0 -7
  115. package/dist/src/interfaces/index.js +0 -3
  116. package/dist/src/interfaces/index.js.map +0 -1
  117. package/dist/src/interfaces/joint-hirer-attr.interface.d.ts +0 -10
  118. package/dist/src/interfaces/joint-hirer-attr.interface.js +0 -3
  119. package/dist/src/interfaces/joint-hirer-attr.interface.js.map +0 -1
  120. package/dist/src/interfaces/rental-attr.interface.d.ts +0 -24
  121. package/dist/src/interfaces/rental-attr.interface.js +0 -3
  122. package/dist/src/interfaces/rental-attr.interface.js.map +0 -1
  123. package/dist/src/interfaces/rental-find-all-search-attr.interface.d.ts +0 -10
  124. package/dist/src/interfaces/rental-find-all-search-attr.interface.js +0 -3
  125. package/dist/src/interfaces/rental-find-all-search-attr.interface.js.map +0 -1
  126. package/dist/src/interfaces/rental-price-attr.interface.d.ts +0 -7
  127. package/dist/src/interfaces/rental-price-attr.interface.js +0 -3
  128. package/dist/src/interfaces/rental-price-attr.interface.js.map +0 -1
  129. package/dist/src/models/agreement.entity.d.ts +0 -10
  130. package/dist/src/models/agreement.entity.js +0 -60
  131. package/dist/src/models/agreement.entity.js.map +0 -1
  132. package/dist/src/models/booking.entity.d.ts +0 -21
  133. package/dist/src/models/booking.entity.js +0 -128
  134. package/dist/src/models/booking.entity.js.map +0 -1
  135. package/dist/src/models/index.d.ts +0 -6
  136. package/dist/src/models/index.js +0 -14
  137. package/dist/src/models/index.js.map +0 -1
  138. package/dist/src/models/joint-hirer.entity.d.ts +0 -13
  139. package/dist/src/models/joint-hirer.entity.js +0 -79
  140. package/dist/src/models/joint-hirer.entity.js.map +0 -1
  141. package/dist/src/models/rental-price.entity.d.ts +0 -8
  142. package/dist/src/models/rental-price.entity.js +0 -59
  143. package/dist/src/models/rental-price.entity.js.map +0 -1
  144. package/dist/src/models/rental.entity.d.ts +0 -29
  145. package/dist/src/models/rental.entity.js +0 -160
  146. package/dist/src/models/rental.entity.js.map +0 -1
  147. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -1,54 +1,54 @@
1
- import { RepositoryBase, IRepositoryBase } from '@tomei/general';
2
- import { JointHirerModel } from '../../models/joint-hirer.entity';
3
-
4
- export class JointHirerRepository
5
- extends RepositoryBase<JointHirerModel>
6
- implements IRepositoryBase<JointHirerModel>
7
- {
8
- constructor() {
9
- super(JointHirerModel);
10
- }
11
-
12
- async findByPk(
13
- id: string,
14
- transaction?: any,
15
- ): Promise<JointHirerModel | null> {
16
- try {
17
- const result = await JointHirerModel.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(hirerId: string, dbTransaction?: any) {
28
- try {
29
- const options = {
30
- where: {
31
- HirerId: hirerId,
32
- },
33
- transaction: dbTransaction,
34
- };
35
- await JointHirerModel.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 jointHirers: any;
44
- if (options) {
45
- jointHirers = await JointHirerModel.findAndCountAll(options);
46
- } else {
47
- jointHirers = await JointHirerModel.findAndCountAll();
48
- }
49
- return jointHirers;
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 { JointHirerModel } from '../../models/joint-hirer.entity';
3
+
4
+ export class JointHirerRepository
5
+ extends RepositoryBase<JointHirerModel>
6
+ implements IRepositoryBase<JointHirerModel>
7
+ {
8
+ constructor() {
9
+ super(JointHirerModel);
10
+ }
11
+
12
+ async findByPk(
13
+ id: string,
14
+ transaction?: any,
15
+ ): Promise<JointHirerModel | null> {
16
+ try {
17
+ const result = await JointHirerModel.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(hirerId: string, dbTransaction?: any) {
28
+ try {
29
+ const options = {
30
+ where: {
31
+ HirerId: hirerId,
32
+ },
33
+ transaction: dbTransaction,
34
+ };
35
+ await JointHirerModel.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 jointHirers: any;
44
+ if (options) {
45
+ jointHirers = await JointHirerModel.findAndCountAll(options);
46
+ } else {
47
+ jointHirers = await JointHirerModel.findAndCountAll();
48
+ }
49
+ return jointHirers;
50
+ } catch (error) {
51
+ throw new Error(`An Error occured when retriving : ${error.message}`);
52
+ }
53
+ }
54
+ }
@@ -1,137 +1,137 @@
1
- import { ClassError, ObjectBase } from '@tomei/general';
2
- import { JointHirerRepository } from './joint-hirer.repository';
3
- import { IJointHirerAttr } from '../../interfaces/joint-hirer-attr.interface';
4
- import { ApplicationConfig } from '@tomei/config';
5
- import { LoginUser } from '@tomei/sso';
6
- import { ActionEnum, Activity } from '@tomei/activity-history';
7
-
8
- export class JointHirer extends ObjectBase {
9
- ObjectId: string;
10
- ObjectName: string;
11
- ObjectType: string = 'JointHirer';
12
- TableName: string = 'rental_JointHirer';
13
- RentalId: string;
14
- CustomerId: string;
15
- CustomerType: string;
16
- CreatedById: string;
17
- CreatedAt: Date;
18
- UpdatedById: string;
19
- UpdatedAt: Date;
20
-
21
- get HirerId(): string {
22
- return this.ObjectId;
23
- }
24
-
25
- set HirerId(value: string) {
26
- this.ObjectId = value;
27
- }
28
-
29
- protected static _Repository = new JointHirerRepository();
30
-
31
- protected constructor(jointHirerAttr?: IJointHirerAttr) {
32
- super();
33
- if (jointHirerAttr) {
34
- this.HirerId = jointHirerAttr.HirerId;
35
- this.RentalId = jointHirerAttr.RentalId;
36
- this.CustomerId = jointHirerAttr.CustomerId;
37
- this.CustomerType = jointHirerAttr.CustomerType;
38
- this.CreatedById = jointHirerAttr.CreatedById;
39
- this.CreatedAt = jointHirerAttr.CreatedAt;
40
- this.UpdatedById = jointHirerAttr.UpdatedById;
41
- this.UpdatedAt = jointHirerAttr.UpdatedAt;
42
- }
43
- }
44
-
45
- public static async init(hirerId?: string, dbTransaction?: any) {
46
- try {
47
- if (hirerId) {
48
- const jr = await JointHirer._Repository.findByPk(
49
- hirerId,
50
- dbTransaction,
51
- );
52
- if (jr) {
53
- return new JointHirer(jr.get({ plain: true }));
54
- } else {
55
- throw new ClassError(
56
- 'JointHirer',
57
- 'JointHirerErrMsg01',
58
- 'JointHirer not found',
59
- );
60
- }
61
- }
62
- return new JointHirer();
63
- } catch (error) {
64
- throw error;
65
- }
66
- }
67
-
68
- public async create(loginUser: LoginUser, dbTransaction?: any) {
69
- //This method will create a new joint hirer record.
70
- try {
71
- //Part 1: Check Privilege
72
- const systemCode =
73
- ApplicationConfig.getComponentConfigValue('system-code');
74
- const isPrivileged = await loginUser.checkPrivileges(
75
- systemCode,
76
- 'JointHirer - Create',
77
- );
78
-
79
- if (!isPrivileged) {
80
- throw new ClassError(
81
- 'JointHirer',
82
- 'JointHirerErrMsg00',
83
- "You do not have 'JointHirer - Create' privilege.",
84
- );
85
- }
86
-
87
- //Part 2: Insert Joint Hirer Record
88
- //Check if this.RentalId, this.CustomerId, this.CustomerType have value otherwise throw new ClassError with below params
89
- if (!this.RentalId || !this.CustomerId || !this.CustomerType) {
90
- throw new ClassError(
91
- 'JointHirer',
92
- 'JointHirerErrMsg03',
93
- 'RentalId, CustomerId and CustomerType are required.',
94
- );
95
- }
96
-
97
- //Set other attributes
98
- this.ObjectId = this.createId();
99
- this.CreatedById = loginUser.ObjectId;
100
- this.CreatedAt = new Date();
101
- this.UpdatedById = loginUser.ObjectId;
102
- this.UpdatedAt = new Date();
103
-
104
- const entityValueAfter: IJointHirerAttr = {
105
- HirerId: this.HirerId,
106
- RentalId: this.RentalId,
107
- CustomerId: this.CustomerId,
108
- CustomerType: this.CustomerType,
109
- CreatedById: this.CreatedById,
110
- CreatedAt: this.CreatedAt,
111
- UpdatedById: this.UpdatedById,
112
- UpdatedAt: this.UpdatedAt,
113
- };
114
-
115
- //Call repo class create method by passing the class attributes and db transaction.
116
- await JointHirer._Repository.create(entityValueAfter, {
117
- transaction: dbTransaction,
118
- });
119
-
120
- //Part 4: Record Create JointHirer Activity
121
- const activity = new Activity();
122
- activity.ObjectId = this._createId();
123
- activity.Action = ActionEnum.CREATE;
124
- activity.Description = 'Add Joint Hirer';
125
- activity.EntityId = this.ObjectId;
126
- activity.EntityType = this.ObjectType;
127
- activity.EntityValueBefore = JSON.stringify({});
128
- activity.EntityValueAfter = JSON.stringify(entityValueAfter);
129
-
130
- await activity.create(loginUser.ObjectId, dbTransaction);
131
-
132
- return this;
133
- } catch (error) {
134
- throw error;
135
- }
136
- }
137
- }
1
+ import { ClassError, ObjectBase } from '@tomei/general';
2
+ import { JointHirerRepository } from './joint-hirer.repository';
3
+ import { IJointHirerAttr } from '../../interfaces/joint-hirer-attr.interface';
4
+ import { ApplicationConfig } from '@tomei/config';
5
+ import { LoginUser } from '@tomei/sso';
6
+ import { ActionEnum, Activity } from '@tomei/activity-history';
7
+
8
+ export class JointHirer extends ObjectBase {
9
+ ObjectId: string;
10
+ ObjectName: string;
11
+ ObjectType: string = 'JointHirer';
12
+ TableName: string = 'rental_JointHirer';
13
+ RentalId: string;
14
+ CustomerId: string;
15
+ CustomerType: string;
16
+ CreatedById: string;
17
+ CreatedAt: Date;
18
+ UpdatedById: string;
19
+ UpdatedAt: Date;
20
+
21
+ get HirerId(): string {
22
+ return this.ObjectId;
23
+ }
24
+
25
+ set HirerId(value: string) {
26
+ this.ObjectId = value;
27
+ }
28
+
29
+ protected static _Repository = new JointHirerRepository();
30
+
31
+ protected constructor(jointHirerAttr?: IJointHirerAttr) {
32
+ super();
33
+ if (jointHirerAttr) {
34
+ this.HirerId = jointHirerAttr.HirerId;
35
+ this.RentalId = jointHirerAttr.RentalId;
36
+ this.CustomerId = jointHirerAttr.CustomerId;
37
+ this.CustomerType = jointHirerAttr.CustomerType;
38
+ this.CreatedById = jointHirerAttr.CreatedById;
39
+ this.CreatedAt = jointHirerAttr.CreatedAt;
40
+ this.UpdatedById = jointHirerAttr.UpdatedById;
41
+ this.UpdatedAt = jointHirerAttr.UpdatedAt;
42
+ }
43
+ }
44
+
45
+ public static async init(hirerId?: string, dbTransaction?: any) {
46
+ try {
47
+ if (hirerId) {
48
+ const jr = await JointHirer._Repository.findByPk(
49
+ hirerId,
50
+ dbTransaction,
51
+ );
52
+ if (jr) {
53
+ return new JointHirer(jr.get({ plain: true }));
54
+ } else {
55
+ throw new ClassError(
56
+ 'JointHirer',
57
+ 'JointHirerErrMsg01',
58
+ 'JointHirer not found',
59
+ );
60
+ }
61
+ }
62
+ return new JointHirer();
63
+ } catch (error) {
64
+ throw error;
65
+ }
66
+ }
67
+
68
+ public async create(loginUser: LoginUser, dbTransaction?: any) {
69
+ //This method will create a new joint hirer record.
70
+ try {
71
+ //Part 1: Check Privilege
72
+ const systemCode =
73
+ ApplicationConfig.getComponentConfigValue('system-code');
74
+ const isPrivileged = await loginUser.checkPrivileges(
75
+ systemCode,
76
+ 'JointHirer - Create',
77
+ );
78
+
79
+ if (!isPrivileged) {
80
+ throw new ClassError(
81
+ 'JointHirer',
82
+ 'JointHirerErrMsg00',
83
+ "You do not have 'JointHirer - Create' privilege.",
84
+ );
85
+ }
86
+
87
+ //Part 2: Insert Joint Hirer Record
88
+ //Check if this.RentalId, this.CustomerId, this.CustomerType have value otherwise throw new ClassError with below params
89
+ if (!this.RentalId || !this.CustomerId || !this.CustomerType) {
90
+ throw new ClassError(
91
+ 'JointHirer',
92
+ 'JointHirerErrMsg03',
93
+ 'RentalId, CustomerId and CustomerType are required.',
94
+ );
95
+ }
96
+
97
+ //Set other attributes
98
+ this.ObjectId = this.createId();
99
+ this.CreatedById = loginUser.ObjectId;
100
+ this.CreatedAt = new Date();
101
+ this.UpdatedById = loginUser.ObjectId;
102
+ this.UpdatedAt = new Date();
103
+
104
+ const entityValueAfter: IJointHirerAttr = {
105
+ HirerId: this.HirerId,
106
+ RentalId: this.RentalId,
107
+ CustomerId: this.CustomerId,
108
+ CustomerType: this.CustomerType,
109
+ CreatedById: this.CreatedById,
110
+ CreatedAt: this.CreatedAt,
111
+ UpdatedById: this.UpdatedById,
112
+ UpdatedAt: this.UpdatedAt,
113
+ };
114
+
115
+ //Call repo class create method by passing the class attributes and db transaction.
116
+ await JointHirer._Repository.create(entityValueAfter, {
117
+ transaction: dbTransaction,
118
+ });
119
+
120
+ //Part 4: Record Create JointHirer Activity
121
+ const activity = new Activity();
122
+ activity.ObjectId = this._createId();
123
+ activity.Action = ActionEnum.CREATE;
124
+ activity.Description = 'Add Joint Hirer';
125
+ activity.EntityId = this.ObjectId;
126
+ activity.EntityType = this.ObjectType;
127
+ activity.EntityValueBefore = JSON.stringify({});
128
+ activity.EntityValueAfter = JSON.stringify(entityValueAfter);
129
+
130
+ await activity.create(loginUser.ObjectId, dbTransaction);
131
+
132
+ return this;
133
+ } catch (error) {
134
+ throw error;
135
+ }
136
+ }
137
+ }
@@ -1,51 +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
- }
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
+ }