@tomei/rental 0.2.0 → 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.
Files changed (77) hide show
  1. package/.commitlintrc.json +22 -22
  2. package/.eslintrc +16 -16
  3. package/.eslintrc.js +35 -35
  4. package/.husky/commit-msg +15 -15
  5. package/.husky/pre-commit +7 -7
  6. package/.prettierrc +4 -4
  7. package/Jenkinsfile +57 -57
  8. package/README.md +8 -8
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.js +17 -17
  11. package/dist/index.js.map +1 -1
  12. package/dist/jest.config.d.ts +2 -0
  13. package/dist/jest.config.js +11 -0
  14. package/dist/jest.config.js.map +1 -0
  15. package/dist/migrations/rental-price-table-migration.d.ts +2 -0
  16. package/dist/migrations/rental-price-table-migration.js +43 -0
  17. package/dist/migrations/rental-price-table-migration.js.map +1 -0
  18. package/dist/migrations/rental-table-migrations.d.ts +2 -0
  19. package/dist/migrations/rental-table-migrations.js +95 -0
  20. package/dist/migrations/rental-table-migrations.js.map +1 -0
  21. package/dist/src/components/rental/rental.d.ts +35 -34
  22. package/dist/src/components/rental/rental.js +208 -194
  23. package/dist/src/components/rental/rental.js.map +1 -1
  24. package/dist/src/components/rental/rental.repository.d.ts +8 -8
  25. package/dist/src/components/rental/rental.repository.js +66 -66
  26. package/dist/src/components/rental-price/rental-price.d.ts +12 -12
  27. package/dist/src/components/rental-price/rental-price.js +71 -71
  28. package/dist/src/components/rental-price/rental-price.repository.d.ts +8 -8
  29. package/dist/src/components/rental-price/rental-price.repository.js +66 -66
  30. package/dist/src/database.d.ts +4 -4
  31. package/dist/src/database.js +14 -14
  32. package/dist/src/enum/index.d.ts +2 -2
  33. package/dist/src/enum/index.js +5 -5
  34. package/dist/src/enum/rental-status.enum.d.ts +6 -6
  35. package/dist/src/enum/rental-status.enum.js +10 -10
  36. package/dist/src/index.d.ts +9 -9
  37. package/dist/src/index.js +30 -29
  38. package/dist/src/index.js.map +1 -1
  39. package/dist/src/interfaces/index.d.ts +4 -3
  40. package/dist/src/interfaces/index.js +2 -2
  41. package/dist/src/interfaces/rental-attr.interface.d.ts +20 -20
  42. package/dist/src/interfaces/rental-attr.interface.js +2 -2
  43. package/dist/src/interfaces/rental-find-all-search-attr.interface.d.ts +7 -0
  44. package/dist/src/interfaces/rental-find-all-search-attr.interface.js +3 -0
  45. package/dist/src/interfaces/rental-find-all-search-attr.interface.js.map +1 -0
  46. package/dist/src/interfaces/rental-price-attr.interface.d.ts +7 -7
  47. package/dist/src/interfaces/rental-price-attr.interface.js +2 -2
  48. package/dist/src/models/index.d.ts +3 -3
  49. package/dist/src/models/index.js +7 -7
  50. package/dist/src/models/rental-price.entity.d.ts +8 -8
  51. package/dist/src/models/rental-price.entity.js +58 -58
  52. package/dist/src/models/rental.entity.d.ts +23 -23
  53. package/dist/src/models/rental.entity.js +138 -138
  54. package/dist/tsconfig.tsbuildinfo +1 -1
  55. package/index.ts +1 -2
  56. package/jest.config.js +10 -10
  57. package/migrations/rental-price-table-migration.js +32 -32
  58. package/migrations/rental-table-migrations.js +84 -84
  59. package/package.json +71 -71
  60. package/src/components/rental/rental.repository.ts +51 -51
  61. package/src/components/rental/rental.ts +289 -277
  62. package/src/components/rental-price/rental-price.repository.ts +54 -54
  63. package/src/components/rental-price/rental-price.ts +89 -89
  64. package/src/database.ts +15 -15
  65. package/src/enum/index.ts +3 -3
  66. package/src/enum/rental-status.enum.ts +6 -6
  67. package/src/index.ts +16 -10
  68. package/src/interfaces/index.ts +5 -4
  69. package/src/interfaces/rental-attr.interface.ts +21 -21
  70. package/src/interfaces/rental-find-all-search-attr.interface.ts +8 -0
  71. package/src/interfaces/rental-price-attr.interface.ts +7 -7
  72. package/src/models/index.ts +4 -4
  73. package/src/models/rental-price.entity.ts +38 -38
  74. package/src/models/rental.entity.ts +114 -114
  75. package/tsconfig.build.json +5 -5
  76. package/tsconfig.json +23 -23
  77. package/tsconfig.tsbuildinfo +1 -0
@@ -1,54 +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
- }
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
+ }
@@ -1,89 +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
- }
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/enum/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { RentalStatusEnum } from './rental-status.enum';
2
-
3
- export { RentalStatusEnum };
1
+ import { RentalStatusEnum } from './rental-status.enum';
2
+
3
+ export { RentalStatusEnum };
@@ -1,6 +1,6 @@
1
- export enum RentalStatusEnum {
2
- ACTIVE = 'Active',
3
- SUSPENDED = 'Suspended',
4
- CANCELLED = 'Cancelled',
5
- TERMINATED = 'Terminated',
6
- }
1
+ export enum RentalStatusEnum {
2
+ ACTIVE = 'Active',
3
+ SUSPENDED = 'Suspended',
4
+ CANCELLED = 'Cancelled',
5
+ TERMINATED = 'Terminated',
6
+ }
package/src/index.ts CHANGED
@@ -1,10 +1,16 @@
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
- export * as rentalDb from './database';
6
- export * from './interfaces';
7
- export * from './models';
8
- export * from './enum';
9
-
10
- export { Rental, RentalPrice, RentalRepository, RentalPriceRepository };
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
+ };
@@ -1,4 +1,5 @@
1
- import { IRentalAttr } from './rental-attr.interface';
2
- import { IRentalPriceAttr } from './rental-price-attr.interface';
3
-
4
- export { IRentalAttr, IRentalPriceAttr };
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 };
@@ -1,21 +1,21 @@
1
- import { RentalStatusEnum } from '../enum/rental-status.enum';
2
-
3
- export interface IRentalAttr {
4
- RentalId: string;
5
- CustomerId: string;
6
- CustomerType: string;
7
- ItemId: string;
8
- ItemType: string;
9
- PriceId: string;
10
- StartDateTime: Date;
11
- EndDateTime: Date;
12
- CancelRemarks: string;
13
- TerminateRemarks: string;
14
- AgreementNo: string;
15
- Status: RentalStatusEnum;
16
- EscheatmentYN: string;
17
- CreatedById: string;
18
- CreatedAt: Date;
19
- UpdatedById: string;
20
- UpdatedAt: Date;
21
- }
1
+ import { RentalStatusEnum } from '../enum/rental-status.enum';
2
+
3
+ export interface IRentalAttr {
4
+ RentalId: string;
5
+ CustomerId: string;
6
+ CustomerType: string;
7
+ ItemId: string;
8
+ ItemType: string;
9
+ PriceId: string;
10
+ StartDateTime: Date;
11
+ EndDateTime: Date;
12
+ CancelRemarks: string;
13
+ TerminateRemarks: string;
14
+ AgreementNo: string;
15
+ Status: RentalStatusEnum;
16
+ EscheatmentYN: string;
17
+ CreatedById: string;
18
+ CreatedAt: Date;
19
+ UpdatedById: string;
20
+ UpdatedAt: Date;
21
+ }
@@ -0,0 +1,8 @@
1
+ import { RentalStatusEnum } from '../enum/rental-status.enum';
2
+
3
+ export interface IRentalFindAllSearchAttr {
4
+ Status?: RentalStatusEnum;
5
+ BoxNo?: string;
6
+ StartDateTime?: Date;
7
+ EndDateTime?: Date;
8
+ }
@@ -1,7 +1,7 @@
1
- export interface IRentalPriceAttr {
2
- PriceId: string;
3
- RetailPrice: number;
4
- Currency: string;
5
- PromoCode: string;
6
- Remarks: string;
7
- }
1
+ export interface IRentalPriceAttr {
2
+ PriceId: string;
3
+ RetailPrice: number;
4
+ Currency: string;
5
+ PromoCode: string;
6
+ Remarks: string;
7
+ }
@@ -1,4 +1,4 @@
1
- import { RentalModel } from './rental.entity';
2
- import { RentalPriceModel } from './rental-price.entity';
3
-
4
- export { RentalModel, RentalPriceModel };
1
+ import { RentalModel } from './rental.entity';
2
+ import { RentalPriceModel } from './rental-price.entity';
3
+
4
+ export { RentalModel, RentalPriceModel };
@@ -1,38 +1,38 @@
1
- import { Column, DataType, Table, Model } from 'sequelize-typescript';
2
-
3
- @Table({
4
- tableName: 'rental_Price',
5
- timestamps: false,
6
- createdAt: false,
7
- updatedAt: false,
8
- })
9
- export class RentalPriceModel extends Model {
10
- @Column({
11
- primaryKey: true,
12
- allowNull: false,
13
- type: DataType.STRING(30),
14
- })
15
- PriceId: string;
16
-
17
- @Column({
18
- allowNull: false,
19
- type: DataType.DECIMAL(10, 2),
20
- })
21
- RetailPrice: number;
22
-
23
- @Column({
24
- allowNull: false,
25
- type: DataType.CHAR(3),
26
- })
27
- Currency: string;
28
-
29
- @Column({
30
- type: DataType.STRING(10),
31
- })
32
- PromoCode: string;
33
-
34
- @Column({
35
- type: DataType.STRING(3000),
36
- })
37
- Remarks: string;
38
- }
1
+ import { Column, DataType, Table, Model } from 'sequelize-typescript';
2
+
3
+ @Table({
4
+ tableName: 'rental_Price',
5
+ timestamps: false,
6
+ createdAt: false,
7
+ updatedAt: false,
8
+ })
9
+ export class RentalPriceModel extends Model {
10
+ @Column({
11
+ primaryKey: true,
12
+ allowNull: false,
13
+ type: DataType.STRING(30),
14
+ })
15
+ PriceId: string;
16
+
17
+ @Column({
18
+ allowNull: false,
19
+ type: DataType.DECIMAL(10, 2),
20
+ })
21
+ RetailPrice: number;
22
+
23
+ @Column({
24
+ allowNull: false,
25
+ type: DataType.CHAR(3),
26
+ })
27
+ Currency: string;
28
+
29
+ @Column({
30
+ type: DataType.STRING(10),
31
+ })
32
+ PromoCode: string;
33
+
34
+ @Column({
35
+ type: DataType.STRING(3000),
36
+ })
37
+ Remarks: string;
38
+ }