%PDF- %PDF-
Direktori : /home/opti/workflow/src/models/ |
Current File : /home/opti/workflow/src/models/itemmovement.js |
'use strict'; module.exports = (sequelize, DataTypes) => { const ItemMovement = sequelize.define('ItemMovement', { uuid: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4 }, itemId: DataTypes.INTEGER, orgId: DataTypes.INTEGER, current: DataTypes.BOOLEAN, pieces: {type:DataTypes.INTEGER, defaultValue: 1}, location: DataTypes.ENUM('Store', 'Region', 'Branch', 'Company Structure', 'Employee'),//receiverType receiverId: DataTypes.INTEGER, moverId: DataTypes.INTEGER, moverType: DataTypes.ENUM('Store', 'Region', 'Branch', 'Company Structure', 'Employee'), createdBy: DataTypes.INTEGER, remarks: DataTypes.STRING, }, {}); // Class Method ItemMovement.prototype.getMoverName = async function () { var name = ""; switch(this.moverType){ case 'Store': await this.sequelize.models.Store.findOne({where:{id:this.moverId}}) .then(store=>{ // console.log(store, "store") // return store.name this.receiverName = store.name }) // name = store.name; break; case 'Region': await this.sequelize.models.Region.findOne({where:{id:this.moverId}}) .then(region=>{ this.receiverName = region.name // return region.name }) // console.log(region) break; case 'Branch': await this.sequelize.models.Branch.findOne({where:{id:this.moverId}}) .then(branch=>{ this.receiverName = branch.name // return branch.name }) break; case 'Company Structure': await this.sequelize.models.Structure.findOne({where:{id:this.moverId}}) .then(structure=>{ this.receiverName = structure.name // return branch.name }) case 'Employee': await this.sequelize.models.User.findOne({where:{id:this.moverId}}) .then(employee=>{ this.receiverName = employee.name // return branch.name }) break; // break; // return name } }; ItemMovement.associate = function(models) { // associations can be defined here ItemMovement.belongsTo(models.Item, {foreignKey: 'itemId', as: 'item'}); ItemMovement.belongsTo(models.User, {foreignKey: 'createdBy', as: 'moveBy'}); }; return ItemMovement; };