2025-07-16 21:20:46 +00:00

88 lines
1.6 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 trips = sequelize.define(
'trips',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
pickup_location: {
type: DataTypes.TEXT,
},
dropoff_location: {
type: DataTypes.TEXT,
},
pickup_time: {
type: DataTypes.DATE,
},
dropoff_time: {
type: DataTypes.DATE,
},
fare: {
type: DataTypes.DECIMAL,
},
status: {
type: DataTypes.ENUM,
values: ['requested', 'accepted', 'completed', 'cancelled'],
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
trips.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
//end loop
db.trips.belongsTo(db.riders, {
as: 'rider',
foreignKey: {
name: 'riderId',
},
constraints: false,
});
db.trips.belongsTo(db.drivers, {
as: 'driver',
foreignKey: {
name: 'driverId',
},
constraints: false,
});
db.trips.belongsTo(db.users, {
as: 'createdBy',
});
db.trips.belongsTo(db.users, {
as: 'updatedBy',
});
};
return trips;
};