@tomei/rental 0.6.4 → 0.7.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 (46) hide show
  1. package/dist/src/components/agreement/agreement.d.ts +14 -0
  2. package/dist/src/components/agreement/agreement.js +48 -0
  3. package/dist/src/components/agreement/agreement.js.map +1 -0
  4. package/dist/src/components/agreement/agreement.repository.d.ts +8 -0
  5. package/dist/src/components/agreement/agreement.repository.js +67 -0
  6. package/dist/src/components/agreement/agreement.repository.js.map +1 -0
  7. package/dist/src/components/rental/rental.d.ts +2 -0
  8. package/dist/src/components/rental/rental.js +8 -0
  9. package/dist/src/components/rental/rental.js.map +1 -1
  10. package/dist/src/database.js +2 -0
  11. package/dist/src/database.js.map +1 -1
  12. package/dist/src/enum/rental-status.enum.d.ts +3 -1
  13. package/dist/src/enum/rental-status.enum.js +2 -0
  14. package/dist/src/enum/rental-status.enum.js.map +1 -1
  15. package/dist/src/index.d.ts +3 -1
  16. package/dist/src/index.js +5 -1
  17. package/dist/src/index.js.map +1 -1
  18. package/dist/src/interfaces/agreement-attr.interface.d.ts +4 -0
  19. package/dist/src/interfaces/agreement-attr.interface.js +3 -0
  20. package/dist/src/interfaces/agreement-attr.interface.js.map +1 -0
  21. package/dist/src/interfaces/index.d.ts +2 -1
  22. package/dist/src/models/agreement.entity.d.ts +7 -0
  23. package/dist/src/models/agreement.entity.js +45 -0
  24. package/dist/src/models/agreement.entity.js.map +1 -0
  25. package/dist/src/models/index.d.ts +2 -1
  26. package/dist/src/models/index.js +3 -1
  27. package/dist/src/models/index.js.map +1 -1
  28. package/dist/src/models/rental.entity.d.ts +2 -0
  29. package/dist/src/models/rental.entity.js +6 -0
  30. package/dist/src/models/rental.entity.js.map +1 -1
  31. package/dist/tsconfig.tsbuildinfo +1 -1
  32. package/migrations/rental-aggrement-table-migration.js +22 -0
  33. package/migrations/rental-table-migrations.js +6 -0
  34. package/package.json +1 -1
  35. package/src/components/agreement/agreement.repository.ts +54 -0
  36. package/src/components/agreement/agreement.ts +43 -0
  37. package/src/components/rental/rental.ts +20 -3
  38. package/src/database.ts +2 -0
  39. package/src/enum/rental-status.enum.ts +10 -0
  40. package/src/index.ts +4 -0
  41. package/src/interfaces/agreement-attr.interface.ts +4 -0
  42. package/src/interfaces/index.ts +2 -0
  43. package/src/models/agreement.entity.ts +26 -0
  44. package/src/models/index.ts +8 -1
  45. package/src/models/rental.entity.ts +5 -0
  46. package/tsconfig.json +1 -1
@@ -0,0 +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
+ }
@@ -0,0 +1,43 @@
1
+ import { ObjectBase } from '@tomei/general';
2
+ import { IAgreementAttr } from '../../interfaces/agreement-attr.interface';
3
+ import { AgreementRepository } from './agreement.repository';
4
+
5
+ export class Agreement extends ObjectBase {
6
+ ObjectId: string;
7
+ ObjectName: string;
8
+ ObjectType: string = 'Agreement';
9
+ TableName = 'rental_Agreement';
10
+ Status: string;
11
+ private static _Repo = new AgreementRepository();
12
+
13
+ get AgreementNo(): string {
14
+ return this.ObjectId;
15
+ }
16
+
17
+ set AgreementNo(value: string) {
18
+ this.ObjectId = value;
19
+ }
20
+
21
+ protected constructor(agreementAttr?: IAgreementAttr) {
22
+ super();
23
+ if (agreementAttr) {
24
+ this.ObjectId = agreementAttr.AgreementNo;
25
+ this.Status = agreementAttr.Status;
26
+ }
27
+ }
28
+
29
+ public static async init(
30
+ agreementNo?: string,
31
+ dbTransaction?: any,
32
+ ): Promise<Agreement> {
33
+ try {
34
+ if (agreementNo) {
35
+ const agreement = await this._Repo.findByPk(agreementNo, dbTransaction);
36
+ return new Agreement(agreement?.get({ plain: true }));
37
+ }
38
+ return new Agreement();
39
+ } catch (error) {
40
+ throw error;
41
+ }
42
+ }
43
+ }
@@ -11,6 +11,7 @@ import { IRentalFindAllSearchAttr } from '../../interfaces/rental-find-all-searc
11
11
  import { RentalAccountTypeEnum } from '../../enum/account-type.enum';
12
12
  import { JointHirer } from '../joint-hirer/joint-hirer';
13
13
  import { JointHirerModel } from '../../models/joint-hirer.entity';
14
+ import { AgreementRepository } from '../agreement/agreement.repository';
14
15
 
15
16
  export class Rental extends ObjectBase {
16
17
  ObjectId: string;
@@ -36,6 +37,7 @@ export class Rental extends ObjectBase {
36
37
  protected _UpdatedById: string;
37
38
  protected _UpdatedAt: Date;
38
39
  protected static _Repo = new RentalRepository();
40
+ protected static _AgreementRepo = new AgreementRepository();
39
41
 
40
42
  get RentalId(): string {
41
43
  return this.ObjectId;
@@ -167,7 +169,22 @@ export class Rental extends ObjectBase {
167
169
  );
168
170
  }
169
171
 
170
- /*Part 3: Insert Rental & The Agreed Rental Price*/
172
+ // Part 3: Create Rental Agreement Record
173
+ // Call Rental._AgreementRepo create method by passing:
174
+ // AgreementNo: this.AgreementNo
175
+ // Status: "Not Generated"
176
+ // dbTransaction
177
+ await Rental._AgreementRepo.create(
178
+ {
179
+ AgreementNo: this.AgreementNo,
180
+ Status: 'Not Generated',
181
+ },
182
+ {
183
+ transaction: dbTransaction,
184
+ },
185
+ );
186
+
187
+ /*Part 4: Insert Rental & The Agreed Rental Price*/
171
188
  await rentalPrice.create(loginUser, dbTransaction);
172
189
 
173
190
  this.PriceId = rentalPrice.PriceId;
@@ -213,7 +230,7 @@ export class Rental extends ObjectBase {
213
230
  }
214
231
  }
215
232
 
216
- /*Part 4: Record Create Rental Activity*/
233
+ /*Part 5: Record Create Rental Activity*/
217
234
  const activity = new Activity();
218
235
  activity.ActivityId = activity.createId();
219
236
  activity.Action = ActionEnum.ADD;
@@ -224,7 +241,7 @@ export class Rental extends ObjectBase {
224
241
  activity.EntityValueAfter = JSON.stringify(data);
225
242
  await activity.create(loginUser.ObjectId, dbTransaction);
226
243
 
227
- /*Part 5: Return Result*/
244
+ /*Part 6: Return Result*/
228
245
  return this;
229
246
  } catch (error) {
230
247
  throw error;
package/src/database.ts CHANGED
@@ -3,6 +3,7 @@ import { RentalModel } from './models/rental.entity';
3
3
  import { RentalPriceModel } from './models/rental-price.entity';
4
4
  import { BookingModel } from './models/booking.entity';
5
5
  import { JointHirerModel } from './models/joint-hirer.entity';
6
+ import { AgreementModel } from './models/agreement.entity';
6
7
 
7
8
  let sequelize: Sequelize;
8
9
 
@@ -15,6 +16,7 @@ function init(sequelizeOptions: SequelizeOptions) {
15
16
  RentalPriceModel,
16
17
  BookingModel,
17
18
  JointHirerModel,
19
+ AgreementModel,
18
20
  ]);
19
21
  }
20
22
 
@@ -26,4 +26,14 @@ export enum RentalStatusEnum {
26
26
  * Rental has been terminated by the customer.
27
27
  */
28
28
  TERMINATED = 'Terminated',
29
+
30
+ /**
31
+ * Customer is pending signing rental agreement
32
+ */
33
+ PENDING_SIGNING = 'Pending Signing',
34
+
35
+ /**
36
+ * Customer already signed and now needs to collect the rental key.
37
+ */
38
+ PENDING_KEY_COLLECTION = 'Pending Key Collection',
29
39
  }
package/src/index.ts CHANGED
@@ -6,6 +6,8 @@ import { Booking } from './components/booking/booking';
6
6
  import { BookingRepository } from './components/booking/booking.repository';
7
7
  import { JointHirer } from './components/joint-hirer/joint-hirer';
8
8
  import { JointHirerRepository } from './components/joint-hirer/joint-hirer.repository';
9
+ import { Agreement } from './components/agreement/agreement';
10
+ import { AgreementRepository } from './components/agreement/agreement.repository';
9
11
  import * as rentalDb from './database';
10
12
  export * from './interfaces';
11
13
  export * from './models';
@@ -21,4 +23,6 @@ export {
21
23
  rentalDb,
22
24
  JointHirer,
23
25
  JointHirerRepository,
26
+ Agreement,
27
+ AgreementRepository,
24
28
  };
@@ -0,0 +1,4 @@
1
+ export interface IAgreementAttr {
2
+ AgreementNo: string;
3
+ Status: string;
4
+ }
@@ -2,10 +2,12 @@ import { IRentalAttr } from './rental-attr.interface';
2
2
  import { IRentalPriceAttr } from './rental-price-attr.interface';
3
3
  import { IRentalFindAllSearchAttr } from './rental-find-all-search-attr.interface';
4
4
  import { IBookingAttr } from './booking-attr.interface';
5
+ import { IAgreementAttr } from './agreement-attr.interface';
5
6
 
6
7
  export {
7
8
  IRentalAttr,
8
9
  IRentalPriceAttr,
9
10
  IRentalFindAllSearchAttr,
10
11
  IBookingAttr,
12
+ IAgreementAttr,
11
13
  };
@@ -0,0 +1,26 @@
1
+ import { Column, DataType, Table, Model, HasMany } from 'sequelize-typescript';
2
+ import { RentalModel } from './rental.entity';
3
+
4
+ @Table({
5
+ tableName: 'rental_Agreement',
6
+ createdAt: false,
7
+ updatedAt: false,
8
+ timestamps: false,
9
+ })
10
+ export class AgreementModel extends Model {
11
+ @Column({
12
+ primaryKey: true,
13
+ allowNull: false,
14
+ type: DataType.STRING(30),
15
+ })
16
+ AgreementNo: string;
17
+
18
+ @Column({
19
+ allowNull: false,
20
+ type: DataType.STRING(10),
21
+ })
22
+ Status: string;
23
+
24
+ @HasMany(() => RentalModel)
25
+ Rentals: RentalModel[];
26
+ }
@@ -2,5 +2,12 @@ import { RentalModel } from './rental.entity';
2
2
  import { RentalPriceModel } from './rental-price.entity';
3
3
  import { BookingModel } from './booking.entity';
4
4
  import { JointHirerModel } from './joint-hirer.entity';
5
+ import { AgreementModel } from './agreement.entity';
5
6
 
6
- export { RentalModel, RentalPriceModel, BookingModel, JointHirerModel };
7
+ export {
8
+ RentalModel,
9
+ RentalPriceModel,
10
+ BookingModel,
11
+ JointHirerModel,
12
+ AgreementModel,
13
+ };
@@ -13,6 +13,7 @@ import { RentalPriceModel } from './rental-price.entity';
13
13
  import { RentalStatusEnum } from '../enum/rental-status.enum';
14
14
  import { JointHirerModel } from './joint-hirer.entity';
15
15
  import { RentalAccountTypeEnum } from '../enum/account-type.enum';
16
+ import { AgreementModel } from './agreement.entity';
16
17
 
17
18
  @Table({
18
19
  tableName: 'rental_Rental',
@@ -89,6 +90,7 @@ export class RentalModel extends Model {
89
90
  })
90
91
  EscheatmentYN: string;
91
92
 
93
+ @ForeignKey(() => AgreementModel)
92
94
  @Column({
93
95
  allowNull: false,
94
96
  unique: true,
@@ -123,6 +125,9 @@ export class RentalModel extends Model {
123
125
  @BelongsTo(() => RentalPriceModel)
124
126
  RentalPrice: RentalPriceModel;
125
127
 
128
+ @BelongsTo(() => AgreementModel)
129
+ Agreement: AgreementModel;
130
+
126
131
  @HasMany(() => JointHirerModel)
127
132
  JointHirers: JointHirerModel[];
128
133
  }
package/tsconfig.json CHANGED
@@ -18,6 +18,6 @@
18
18
  "strictBindCallApply": false,
19
19
  "forceConsistentCasingInFileNames": false,
20
20
  "noFallthroughCasesInSwitch": false,
21
- "strictNullChecks": true
21
+ "strictNullChecks": false,
22
22
  },
23
23
  }