UNPKG

@tomei/rental

Version:
137 lines 5.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.JointHirer = void 0; const general_1 = require("@tomei/general"); const joint_hirer_repository_1 = require("./joint-hirer.repository"); const config_1 = require("@tomei/config"); const activity_history_1 = require("@tomei/activity-history"); class JointHirer extends general_1.ObjectBase { get HirerId() { return this.ObjectId; } set HirerId(value) { this.ObjectId = value; } constructor(jointHirerAttr) { super(); this.ObjectType = 'JointHirer'; this.TableName = 'rental_JointHirer'; this.Status = 'Active'; if (jointHirerAttr) { this.HirerId = jointHirerAttr.HirerId; this.RentalId = jointHirerAttr.RentalId; this.CustomerId = jointHirerAttr.CustomerId; this.CustomerType = jointHirerAttr.CustomerType; this.Status = jointHirerAttr.Status; this.CreatedById = jointHirerAttr.CreatedById; this.CreatedAt = jointHirerAttr.CreatedAt; this.UpdatedById = jointHirerAttr.UpdatedById; this.UpdatedAt = jointHirerAttr.UpdatedAt; } } toJSON() { return { HirerId: this.HirerId, RentalId: this.RentalId, CustomerId: this.CustomerId, CustomerType: this.CustomerType, Status: this.Status, CreatedById: this.CreatedById, CreatedAt: this.CreatedAt, UpdatedById: this.UpdatedById, UpdatedAt: this.UpdatedAt, }; } static async init(hirerId, dbTransaction) { try { if (hirerId) { const jr = await JointHirer._Repository.findByPk(hirerId, dbTransaction); if (jr) { return new JointHirer(jr.get({ plain: true })); } else { throw new general_1.ClassError('JointHirer', 'JointHirerErrMsg01', 'JointHirer not found'); } } return new JointHirer(); } catch (error) { throw error; } } async create(loginUser, dbTransaction) { try { const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code'); const isPrivileged = await loginUser.checkPrivileges(systemCode, 'JointHirer - Create'); if (!isPrivileged) { throw new general_1.ClassError('JointHirer', 'JointHirerErrMsg00', "You do not have 'JointHirer - Create' privilege."); } if (!this.RentalId || !this.CustomerId || !this.CustomerType) { throw new general_1.ClassError('JointHirer', 'JointHirerErrMsg03', 'RentalId, CustomerId and CustomerType are required.'); } this.ObjectId = this.createId(); this.CreatedById = loginUser.ObjectId; this.CreatedAt = new Date(); this.UpdatedById = loginUser.ObjectId; this.UpdatedAt = new Date(); const entityValueAfter = { HirerId: this.HirerId, RentalId: this.RentalId, CustomerId: this.CustomerId, CustomerType: this.CustomerType, Status: this.Status, CreatedById: this.CreatedById, CreatedAt: this.CreatedAt, UpdatedById: this.UpdatedById, UpdatedAt: this.UpdatedAt, }; await JointHirer._Repository.create(entityValueAfter, { transaction: dbTransaction, }); const activity = new activity_history_1.Activity(); activity.ObjectId = this._createId(); activity.Action = activity_history_1.ActionEnum.CREATE; activity.Description = 'Add Joint Hirer'; activity.EntityId = this.ObjectId; activity.EntityType = this.ObjectType; activity.EntityValueBefore = JSON.stringify({}); activity.EntityValueAfter = JSON.stringify(entityValueAfter); await activity.create(loginUser.ObjectId, dbTransaction); return this; } catch (error) { throw error; } } async remove(loginUser, dbTransaction) { try { const entityValueBefore = this.toJSON(); this.Status = 'Inactive'; this.UpdatedById = loginUser.ObjectId; this.UpdatedAt = new Date(); const entityValueAfter = this.toJSON(); await JointHirer._Repository.update(entityValueAfter, { where: { HirerId: this.HirerId, }, transaction: dbTransaction, }); const activity = new activity_history_1.Activity(); activity.ObjectId = this._createId(); activity.Action = activity_history_1.ActionEnum.UPDATE; activity.Description = 'Mark Joint Hirer as Inactive'; activity.EntityId = this.ObjectId; activity.EntityType = this.ObjectType; activity.EntityValueBefore = JSON.stringify(entityValueBefore); activity.EntityValueAfter = JSON.stringify(entityValueAfter); await activity.create(loginUser.ObjectId, dbTransaction); return this; } catch (error) { throw error; } } } exports.JointHirer = JointHirer; JointHirer._Repository = new joint_hirer_repository_1.JointHirerRepository(); //# sourceMappingURL=joint-hirer.js.map