200 lines
2.8 KiB
JavaScript
200 lines
2.8 KiB
JavaScript
const config = require('../../config');
|
|
const providers = config.providers;
|
|
const crypto = require('crypto');
|
|
const bcrypt = require('bcrypt');
|
|
const moment = require('moment');
|
|
|
|
module.exports = function(sequelize, DataTypes) {
|
|
const crew_movements = sequelize.define(
|
|
'crew_movements',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
movement_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"arribo",
|
|
|
|
|
|
"desembarco"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
movement_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
origin_country: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
destination_country: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
embark_port: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"pendiente_documentacion",
|
|
|
|
|
|
"completo",
|
|
|
|
|
|
"observado",
|
|
|
|
|
|
"cancelado"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
remarks: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
crew_movements.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.crew_movements.hasMany(db.shore_pass_documents, {
|
|
as: 'shore_pass_documents_crew_movement',
|
|
foreignKey: {
|
|
name: 'crew_movementId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.crew_movements.belongsTo(db.airports, {
|
|
as: 'embark_airport',
|
|
foreignKey: {
|
|
name: 'embark_airportId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.crew_movements.belongsTo(db.flights, {
|
|
as: 'flight',
|
|
foreignKey: {
|
|
name: 'flightId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.crew_movements.belongsTo(db.vessels, {
|
|
as: 'vessel',
|
|
foreignKey: {
|
|
name: 'vesselId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.crew_movements.belongsTo(db.crew_members, {
|
|
as: 'crew_member',
|
|
foreignKey: {
|
|
name: 'crew_memberId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.crew_movements.belongsTo(db.users, {
|
|
as: 'registered_by',
|
|
foreignKey: {
|
|
name: 'registered_byId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.crew_movements.belongsTo(db.companies, {
|
|
as: 'companies',
|
|
foreignKey: {
|
|
name: 'companiesId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.crew_movements.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.crew_movements.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return crew_movements;
|
|
};
|
|
|
|
|