Я хочу создать запрос, который дает мне вывод, такой как
{
"idOfUser":[Array of missions],
"idOfUser":[Array of mission]
}
, чтобы фактически сгруппировать миссии по пользователю, которые существуют в планировании
Каждому пользователю назначается одна миссия и дляпланирование может быть много миссии в одном планировании.
я уже сделал это
if (data["date"]) {
Planning.find({ start: { $eq: new Date(Number(data["date"])) } }).populate('mission').exec((err, doc) => {
if (!err)
return response(res, doc)
else
return throwError(err, 404, next)
})
}
, который дает мне вывод, как
{
start:"some date",
end:"some date"
mission:[array of mission]
}
Схема пользователя:
let UserSchema = new Schema({
name: {
type: Schema.Types.String,
required: [true, "name must be required"],
},
email: {
type: Schema.Types.String,
required: [true, "email must be required"],
unique: [true, "email already taken"],
},
password: {
type: Schema.Types.String,
required: true,
validate: {
validator: (pass) => pass.length >= 8,
message: 'password must be consist of 8 characters'
}
},
isAdmin: {
type: Schema.Types.Boolean,
default: false
}
});
Схема миссии
let MissionSchema = new Schema({
missionNotes: {
type: Schema.Types.String,
required: [true, "name is required"],
// unique: [true, "must be unique"]
},
startDate: {
type: Schema.Types.Date,
required: [true, "startDate is required"],
},
endDate: {
type: Schema.Types.Date,
required: [true, "endDate is required"],
},
repeatInterval: {
type: Schema.Types.Number,
required: [true, "duration is required"],
},
pickupTime: {
type: Schema.Types.Number,
required: [true, "pickuptime is required"],
},//minutes,
flightNo: {
type: Schema.Types.String,
// required: [true, "flightNo is required"],
},
who: {
type: Object,
required: [true, "who is required"],
},
journey: {
type: Object,
required: [true, "journey is required"],
},
user: {
type: Object,
default: null
},
isAssign: {
type: Schema.Types.Boolean,
default: false,
},
info: {
type: Schema.Types.String,
// required: [true, "info is required"],
},
companyNotes: {
type: Schema.Types.String
},
isCompleted: {
type: Schema.Types.Boolean,
default: false
},
car: {
type: Object,
default: null
},
fuel: {
type: Schema.Types.Number,
default: 0
},
extraExpense: {
type: Schema.Types.Number,
default: 0
},
crewInfo: {
type: Schema.Types.String,
default: ""
},
apt: {
type: Schema.Types.String,
default: ""
},//actualpickuptime
atad: {
type: Schema.Types.String,
default: ""
},//actualtimeatdestination
adt: {
type: Schema.Types.String,
default: ""
},//actualdrivingtime
acalpt: {
type: Schema.Types.String,
default: ""
},//actualcalculatedpickuptime
dap: {
type: Schema.Types.String,
default: ""
},//delayafterpickup
dacp: {
type: Schema.Types.String,
default: ""
},//delayaftercalcpickup,
isReminded: {
type: Schema.Types.Boolean,
default: false
},
});
Схема планирования
let PlanningSchema = new Schema({
title: {
type: Schema.Types.String,
// required: [true, "title is required"],
},
start: {
type: Date,
required: [true, "start is required"],
},
end: {
type: Date,
required: [true, "end is required"],
},
mission: [{ type: Schema.Types.ObjectId, ref: 'mission' }]
})