@tomei/rental 0.13.2 → 0.15.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.
- package/dist/src/components/agreement-history/agreement-history.d.ts +17 -0
- package/dist/src/components/agreement-history/agreement-history.js +51 -0
- package/dist/src/components/agreement-history/agreement-history.js.map +1 -0
- package/dist/src/components/agreement-history/agreement-history.repository.d.ts +8 -0
- package/dist/src/components/agreement-history/agreement-history.repository.js +67 -0
- package/dist/src/components/agreement-history/agreement-history.repository.js.map +1 -0
- package/dist/src/components/rental/rental.d.ts +2 -0
- package/dist/src/components/rental/rental.js +18 -0
- package/dist/src/components/rental/rental.js.map +1 -1
- package/dist/src/database.js +2 -0
- package/dist/src/database.js.map +1 -1
- package/dist/src/index.d.ts +3 -1
- package/dist/src/index.js +5 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/interfaces/agreement-history-attr.interface.d.ts +7 -0
- package/dist/src/interfaces/agreement-history-attr.interface.js +3 -0
- package/dist/src/interfaces/agreement-history-attr.interface.js.map +1 -0
- package/dist/src/models/agreement-history.entity.d.ts +10 -0
- package/dist/src/models/agreement-history.entity.js +65 -0
- package/dist/src/models/agreement-history.entity.js.map +1 -0
- package/dist/src/models/agreement.entity.d.ts +2 -0
- package/dist/src/models/agreement.entity.js +5 -0
- package/dist/src/models/agreement.entity.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/migrations/rental-aggreement-history.js +41 -0
- package/package.json +1 -1
- package/src/components/agreement-history/agreement-history.repository.ts +54 -0
- package/src/components/agreement-history/agreement-history.ts +57 -0
- package/src/components/rental/rental.ts +43 -0
- package/src/database.ts +2 -0
- package/src/index.ts +4 -0
- package/src/interfaces/agreement-history-attr.interface.ts +7 -0
- package/src/models/agreement-history.entity.ts +51 -0
- package/src/models/agreement.entity.ts +4 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/** @type {import('sequelize-cli').Migration} */
|
|
4
|
+
module.exports = {
|
|
5
|
+
async up(queryInterface, Sequelize) {
|
|
6
|
+
await queryInterface.createTable('rental_AgreementHistory', {
|
|
7
|
+
BookingNo: {
|
|
8
|
+
type: Sequelize.INTEGER,
|
|
9
|
+
allowNull: false,
|
|
10
|
+
primaryKey: true,
|
|
11
|
+
autoIncrement: true,
|
|
12
|
+
},
|
|
13
|
+
MediaId: {
|
|
14
|
+
type: Sequelize.STRING(30),
|
|
15
|
+
allowNull: false,
|
|
16
|
+
},
|
|
17
|
+
ActivityCompleted: {
|
|
18
|
+
type: Sequelize.STRING(200),
|
|
19
|
+
allowNull: false,
|
|
20
|
+
},
|
|
21
|
+
AgreementNo: {
|
|
22
|
+
type: Sequelize.STRING(30),
|
|
23
|
+
allowNull: false,
|
|
24
|
+
references: {
|
|
25
|
+
model: 'rental_Agreement',
|
|
26
|
+
key: 'AgreementNo',
|
|
27
|
+
},
|
|
28
|
+
onUpdate: 'CASCADE',
|
|
29
|
+
onDelete: 'CASCADE',
|
|
30
|
+
},
|
|
31
|
+
CreatedAt: {
|
|
32
|
+
type: Sequelize.DATE,
|
|
33
|
+
allowNull: false,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
async down(queryInterface, Sequelize) {
|
|
39
|
+
await queryInterface.dropTable('rental_AgreementHistory');
|
|
40
|
+
},
|
|
41
|
+
};
|
package/package.json
CHANGED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { RepositoryBase, IRepositoryBase } from '@tomei/general';
|
|
2
|
+
import { AgreementHistoryModel } from '../../models/agreement-history.entity';
|
|
3
|
+
|
|
4
|
+
export class AgreementHistoryRepository
|
|
5
|
+
extends RepositoryBase<AgreementHistoryModel>
|
|
6
|
+
implements IRepositoryBase<AgreementHistoryModel>
|
|
7
|
+
{
|
|
8
|
+
constructor() {
|
|
9
|
+
super(AgreementHistoryModel);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async findByPk(
|
|
13
|
+
id: string,
|
|
14
|
+
transaction?: any,
|
|
15
|
+
): Promise<AgreementHistoryModel | null> {
|
|
16
|
+
try {
|
|
17
|
+
const result = await AgreementHistoryModel.findByPk(parseInt(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 AgreementHistoryModel.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 AgreementHistoryModel.findAndCountAll(options);
|
|
46
|
+
} else {
|
|
47
|
+
Agreements = await AgreementHistoryModel.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,57 @@
|
|
|
1
|
+
import { ObjectBase } from '@tomei/general';
|
|
2
|
+
import { AgreementHistoryRepository } from './agreement-history.repository';
|
|
3
|
+
import { AggrementStatusEnum } from '../../enum/aggrement-status.enum';
|
|
4
|
+
import { IAgreementHistoryAttr } from '../../interfaces/agreement-history-attr.interface';
|
|
5
|
+
|
|
6
|
+
export class AgreementHistory
|
|
7
|
+
extends ObjectBase
|
|
8
|
+
implements IAgreementHistoryAttr
|
|
9
|
+
{
|
|
10
|
+
ObjectId: string;
|
|
11
|
+
ObjectName: string;
|
|
12
|
+
ObjectType: string = 'AgreementHistory';
|
|
13
|
+
TableName = 'rental_AgreementHistory';
|
|
14
|
+
AgreementNo: string;
|
|
15
|
+
ActivityCompleted: string;
|
|
16
|
+
MediaId: string;
|
|
17
|
+
CreatedAt: Date;
|
|
18
|
+
|
|
19
|
+
private static _Repo = new AgreementHistoryRepository();
|
|
20
|
+
|
|
21
|
+
get HistoryId(): number {
|
|
22
|
+
return parseInt(this.ObjectId);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
set HistoryId(value: number) {
|
|
26
|
+
this.ObjectId = value.toString();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
protected constructor(agreementAttr?: IAgreementHistoryAttr) {
|
|
30
|
+
super();
|
|
31
|
+
if (agreementAttr) {
|
|
32
|
+
this.HistoryId = agreementAttr.HistoryId;
|
|
33
|
+
this.AgreementNo = agreementAttr.AgreementNo;
|
|
34
|
+
this.ActivityCompleted = agreementAttr.ActivityCompleted;
|
|
35
|
+
this.MediaId = agreementAttr.MediaId;
|
|
36
|
+
this.CreatedAt = agreementAttr.CreatedAt;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public static async init(
|
|
41
|
+
historyId: number,
|
|
42
|
+
dbTransaction?: any,
|
|
43
|
+
): Promise<AgreementHistory> {
|
|
44
|
+
try {
|
|
45
|
+
if (historyId) {
|
|
46
|
+
const ah = await this._Repo.findByPk(
|
|
47
|
+
historyId.toString(),
|
|
48
|
+
dbTransaction,
|
|
49
|
+
);
|
|
50
|
+
return new AgreementHistory(ah?.get({ plain: true }));
|
|
51
|
+
}
|
|
52
|
+
return new AgreementHistory();
|
|
53
|
+
} catch (error) {
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -21,6 +21,7 @@ import { AggrementStatusEnum } from '../../enum/aggrement-status.enum';
|
|
|
21
21
|
import { HirerSignatureRepository } from '../hirer-signature/hirer-signature.repository';
|
|
22
22
|
import { HirerSignatureStatusEnum } from '../../enum/hirer-signature-status.enum';
|
|
23
23
|
import { HirerTypeEnum } from '../../enum/hirer-type.enum';
|
|
24
|
+
import { AgreementHistoryRepository } from '../agreement-history/agreement-history.repository';
|
|
24
25
|
|
|
25
26
|
export class Rental extends ObjectBase {
|
|
26
27
|
ObjectId: string;
|
|
@@ -49,6 +50,7 @@ export class Rental extends ObjectBase {
|
|
|
49
50
|
protected static _AgreementRepo = new AgreementRepository();
|
|
50
51
|
protected static _JointHirerRepo = new JointHirerRepository();
|
|
51
52
|
protected static _HirerSignatureRepo = new HirerSignatureRepository();
|
|
53
|
+
protected static _AgreementHistoryRepo = new AgreementHistoryRepository();
|
|
52
54
|
|
|
53
55
|
get RentalId(): string {
|
|
54
56
|
return this.ObjectId;
|
|
@@ -1066,6 +1068,47 @@ export class Rental extends ObjectBase {
|
|
|
1066
1068
|
// dbTransaction
|
|
1067
1069
|
// userId: loginUser.ObjectId
|
|
1068
1070
|
await activity.create(loginUser.ObjectId, dbTransaction);
|
|
1071
|
+
|
|
1072
|
+
// Part 5: Add Record To Agreement History Table
|
|
1073
|
+
// Make sure there is a private static readonly _AgreementHistoryRepo variable.
|
|
1074
|
+
// Set newRecord to an object with below key-value:
|
|
1075
|
+
// AgreementNo: this.AgreementNo
|
|
1076
|
+
// MediaId: params.MediaId
|
|
1077
|
+
// ActivityCompleted: "Agreement Generated"
|
|
1078
|
+
// CreatedAt: Current Timestamp
|
|
1079
|
+
// Use _AgreementHistoryRepo.create() method and pass newRecord and dbTransaction.
|
|
1080
|
+
const agreementHistory = await Rental._AgreementHistoryRepo.create(
|
|
1081
|
+
{
|
|
1082
|
+
AgreementNo: this.AgreementNo,
|
|
1083
|
+
MediaId,
|
|
1084
|
+
ActivityCompleted: 'Agreement Generated',
|
|
1085
|
+
CreatedAt: new Date(),
|
|
1086
|
+
},
|
|
1087
|
+
{ transaction: dbTransaction },
|
|
1088
|
+
);
|
|
1089
|
+
|
|
1090
|
+
// Part 6: Record Agreement History Activity
|
|
1091
|
+
// Initialise EntityValueAfter variable and set to newRecord from previous part.
|
|
1092
|
+
// Instantiate new activity from Activity class, call createId() method, then set:
|
|
1093
|
+
// Action: ActionEnum.CREATE
|
|
1094
|
+
// Description: "Generate agreement."
|
|
1095
|
+
// EntityType: "RentalAgreementHistory"
|
|
1096
|
+
// EntityId: HistoryId from previous part.
|
|
1097
|
+
// EntityValueBefore: empty object.
|
|
1098
|
+
// EntityValueAfter: EntityValueAfter
|
|
1099
|
+
// Call new activity create method by passing:
|
|
1100
|
+
// dbTransaction
|
|
1101
|
+
// userId: loginUser.ObjectId
|
|
1102
|
+
const entityValueAfter = agreementHistory.get({ plain: true });
|
|
1103
|
+
const activityHistory = new Activity();
|
|
1104
|
+
activityHistory.ActivityId = activityHistory.createId();
|
|
1105
|
+
activityHistory.Action = ActionEnum.CREATE;
|
|
1106
|
+
activityHistory.Description = 'Generate agreement.';
|
|
1107
|
+
activityHistory.EntityType = 'RentalAgreementHistory';
|
|
1108
|
+
activityHistory.EntityId = agreementHistory.HistoryId.toString();
|
|
1109
|
+
activityHistory.EntityValueBefore = JSON.stringify({});
|
|
1110
|
+
activityHistory.EntityValueAfter = JSON.stringify(entityValueAfter);
|
|
1111
|
+
await activityHistory.create(loginUser.ObjectId, dbTransaction);
|
|
1069
1112
|
} catch (error) {
|
|
1070
1113
|
throw error;
|
|
1071
1114
|
}
|
package/src/database.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { BookingModel } from './models/booking.entity';
|
|
|
5
5
|
import { JointHirerModel } from './models/joint-hirer.entity';
|
|
6
6
|
import { AgreementModel } from './models/agreement.entity';
|
|
7
7
|
import { HirerSignatureModel } from './models/hirer-signature.entity';
|
|
8
|
+
import { AgreementHistoryModel } from './models/agreement-history.entity';
|
|
8
9
|
|
|
9
10
|
let sequelize: Sequelize;
|
|
10
11
|
|
|
@@ -19,6 +20,7 @@ function init(sequelizeOptions: SequelizeOptions) {
|
|
|
19
20
|
JointHirerModel,
|
|
20
21
|
AgreementModel,
|
|
21
22
|
HirerSignatureModel,
|
|
23
|
+
AgreementHistoryModel,
|
|
22
24
|
]);
|
|
23
25
|
}
|
|
24
26
|
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,8 @@ import { Agreement } from './components/agreement/agreement';
|
|
|
10
10
|
import { AgreementRepository } from './components/agreement/agreement.repository';
|
|
11
11
|
import { HirerSignature } from './components/hirer-signature/hirer-signature';
|
|
12
12
|
import { HirerSignatureRepository } from './components/hirer-signature/hirer-signature.repository';
|
|
13
|
+
import { AgreementHistory } from './components/agreement-history/agreement-history';
|
|
14
|
+
import { AgreementHistoryRepository } from './components/agreement-history/agreement-history.repository';
|
|
13
15
|
import * as rentalDb from './database';
|
|
14
16
|
export * from './interfaces';
|
|
15
17
|
export * from './models';
|
|
@@ -29,4 +31,6 @@ export {
|
|
|
29
31
|
AgreementRepository,
|
|
30
32
|
HirerSignature,
|
|
31
33
|
HirerSignatureRepository,
|
|
34
|
+
AgreementHistory,
|
|
35
|
+
AgreementHistoryRepository,
|
|
32
36
|
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Column,
|
|
3
|
+
DataType,
|
|
4
|
+
Table,
|
|
5
|
+
Model,
|
|
6
|
+
ForeignKey,
|
|
7
|
+
BelongsTo,
|
|
8
|
+
CreatedAt,
|
|
9
|
+
} from 'sequelize-typescript';
|
|
10
|
+
import { AgreementModel } from './agreement.entity';
|
|
11
|
+
|
|
12
|
+
@Table({
|
|
13
|
+
tableName: 'rental_Agreement',
|
|
14
|
+
createdAt: 'CreatedAt',
|
|
15
|
+
updatedAt: false,
|
|
16
|
+
timestamps: true,
|
|
17
|
+
})
|
|
18
|
+
export class AgreementHistoryModel extends Model {
|
|
19
|
+
@Column({
|
|
20
|
+
primaryKey: true,
|
|
21
|
+
allowNull: false,
|
|
22
|
+
autoIncrement: true,
|
|
23
|
+
type: DataType.INTEGER,
|
|
24
|
+
})
|
|
25
|
+
HistoryId: number;
|
|
26
|
+
|
|
27
|
+
@ForeignKey(() => AgreementModel)
|
|
28
|
+
@Column({
|
|
29
|
+
allowNull: false,
|
|
30
|
+
type: DataType.STRING(30),
|
|
31
|
+
})
|
|
32
|
+
AgreementNo: string;
|
|
33
|
+
|
|
34
|
+
@Column({
|
|
35
|
+
allowNull: false,
|
|
36
|
+
type: DataType.STRING(30),
|
|
37
|
+
})
|
|
38
|
+
MediaId: string;
|
|
39
|
+
|
|
40
|
+
@Column({
|
|
41
|
+
allowNull: false,
|
|
42
|
+
type: DataType.STRING(200),
|
|
43
|
+
})
|
|
44
|
+
ActivityCompleted: string;
|
|
45
|
+
|
|
46
|
+
@CreatedAt
|
|
47
|
+
CreatedAt?: Date;
|
|
48
|
+
|
|
49
|
+
@BelongsTo(() => AgreementModel)
|
|
50
|
+
Agreement: AgreementModel;
|
|
51
|
+
}
|
|
@@ -2,6 +2,7 @@ import { Column, DataType, Table, Model, HasMany } from 'sequelize-typescript';
|
|
|
2
2
|
import { RentalModel } from './rental.entity';
|
|
3
3
|
import { AggrementStatusEnum } from '../enum/aggrement-status.enum';
|
|
4
4
|
import { HirerSignatureModel } from './hirer-signature.entity';
|
|
5
|
+
import { AgreementHistoryModel } from './agreement-history.entity';
|
|
5
6
|
|
|
6
7
|
@Table({
|
|
7
8
|
tableName: 'rental_Agreement',
|
|
@@ -40,4 +41,7 @@ export class AgreementModel extends Model {
|
|
|
40
41
|
|
|
41
42
|
@HasMany(() => HirerSignatureModel)
|
|
42
43
|
HirerSignatures: HirerSignatureModel[];
|
|
44
|
+
|
|
45
|
+
@HasMany(() => AgreementHistoryModel)
|
|
46
|
+
History: AgreementHistoryModel[];
|
|
43
47
|
}
|