Private Groups enabled based on the following assumptions: * There is only one private group. * The companies added to the private group is able to find private loads in the directory. * The companies added to the private group is able to find private companies in the directory. * The driver requires a new endpoint to read load resources no matter the privacy rules (as long as they are added to the load as driver). * The private group can be updated by anyone within the company. * The privacy is enabled on the company information by enabling `privacy=true`. * The privacy is enabled on the loads information by enabling `privacy=true`. * When looking for loads/companies by default the search is with `privacy=false` which returns public elements. When `privacy=true`is given, the results are limited to private elements only (not including public elements). Load-Templates enabled based on the following assumptions: * Anyone can CRUD the templates, there is no find feature (for now). It is assumed that the number of templates is limited.
99 lines
3.1 KiB
JavaScript
99 lines
3.1 KiB
JavaScript
const mongoose = require('mongoose');
|
|
const { Schema } = mongoose;
|
|
|
|
const address = new Schema({
|
|
company_name: { type: String },
|
|
|
|
street_address1: { type: String },
|
|
street_address2: { type: String },
|
|
city: { type: String },
|
|
state: { type: String },
|
|
country: { type: String },
|
|
zipcode: { type: String },
|
|
|
|
landmark: { type: String },
|
|
|
|
lat: { type: String },
|
|
lng: { type: String },
|
|
});
|
|
|
|
|
|
const pointSchema = new Schema({
|
|
type: {
|
|
type: String,
|
|
enum: ['Point'],
|
|
required: true
|
|
},
|
|
coordinates: {
|
|
type: [Number],
|
|
required: true
|
|
}
|
|
});
|
|
|
|
|
|
const schema = new Schema({
|
|
shipment_code: { type: String },
|
|
company: { type: Schema.Types.ObjectId, ref: 'companies', required: true }, //shipper
|
|
carrier: { type: Schema.Types.ObjectId, ref: 'companies' }, // carrier
|
|
vehicle: { type: Schema.Types.ObjectId, ref: 'vehicles' },
|
|
driver: { type: Schema.Types.ObjectId, ref: 'users' },
|
|
posted_by: { type: Schema.Types.ObjectId, ref: 'users' }, // shipper
|
|
posted_by_name: { type: String }, // search purpose
|
|
bidder: { type: Schema.Types.ObjectId, ref: 'users' }, // who sent the proposal (carrier user)
|
|
|
|
alert_list: [{ type: String, lowercase: true }],
|
|
|
|
origin_warehouse : { type: Schema.Types.ObjectId, ref: 'branches' },
|
|
destination_warehouse : { type: Schema.Types.ObjectId, ref: 'branches' },
|
|
|
|
origin: address,
|
|
origin_geo: {
|
|
type: pointSchema,
|
|
},
|
|
destination: address,
|
|
destination_geo: {
|
|
type: pointSchema,
|
|
},
|
|
|
|
categories: [{ type: Schema.Types.ObjectId, ref: 'productcategories' }],
|
|
product: { type: Schema.Types.ObjectId, ref: 'products' },
|
|
|
|
truck_type: { type: String },
|
|
tyre_type: { type: String },
|
|
weight: { type: Number },
|
|
estimated_cost: { type: Number },
|
|
|
|
distance: { type: Number },
|
|
actual_cost: { type: Number },
|
|
|
|
// 1. Posted Shipments (Posted)
|
|
// 2. Shipments Loading (Loading)
|
|
// 3. Enroute Shipments (In Transit)
|
|
// 4. Shipments in Unloading (Unloading)
|
|
// 5. Shipments pending finding truck
|
|
status: { type: String, default: 'Draft', enum: ['Draft', 'Published', 'Completed', 'Closed'] },//When completed => Publication is done, awaiting for the load transit to finish (load_status set tot Delivered).
|
|
load_status: { type: String, enum: ['Published', 'Loading', 'Transit', 'Downloading', 'Delivered'] },
|
|
|
|
|
|
contract_start_date: { type: Date },
|
|
contract_end_date: { type: Date },
|
|
|
|
est_loading_date: { type: Date },
|
|
est_unloading_date: { type: Date },
|
|
|
|
published_date: { type: Date },
|
|
loaded_date: { type: Date },
|
|
transit_date: { type: Date },
|
|
delivered_date: { type: Date },
|
|
load_status_updated: { type: Date, default: () => Date.now() },
|
|
notes: { type: String },
|
|
|
|
payment_term: { type: String },
|
|
terms_and_conditions: { type: String },
|
|
createdAt: { type : Date, required : true, default : () => { return Date.now(); } },
|
|
|
|
privacy: { type: Boolean, default: false }, /// Disables visibility on the directory, only enabled for private groups.
|
|
});
|
|
|
|
module.exports = mongoose.model( "loads", schema );
|