- ++Booking List
- ++Delete a Booking also for the Admin.
This commit is contained in:
@@ -43,16 +43,95 @@ const bookingSchema = new Schema({
|
||||
|
||||
});
|
||||
|
||||
bookingSchema.statics.findAllByUserIdAndIdApp = function (userId, idapp) {
|
||||
bookingSchema.statics.findAllByUserIdAndIdApp = function (userId, idapp, sall) {
|
||||
const Booking = this;
|
||||
|
||||
return Booking.find({userId, idapp, booked: true}, (err, arrbooked) => {
|
||||
// console.log('ris Booking:', arrbooked);
|
||||
return arrbooked
|
||||
let myfind = {};
|
||||
if (sall === '1')
|
||||
myfind = { idapp, booked: true };
|
||||
else
|
||||
myfind = { userId, idapp, booked: true };
|
||||
|
||||
return Booking.find(myfind, (err, arrbooked) => {
|
||||
// console.log('ris Booking:', arrbooked);
|
||||
return arrbooked
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
function getUsersByBooking(idapp) {
|
||||
const query = [
|
||||
{
|
||||
$match: { idapp }
|
||||
},
|
||||
{
|
||||
$group: { _id: "$userId" }
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
_id: {
|
||||
$toString: "$userId"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
$Lookup: {
|
||||
from: "users",
|
||||
localField: "userId", // field in my collection
|
||||
foreignField: "ObjectId(_id)", // field in the 'from' collection
|
||||
as: "fromItems"
|
||||
}
|
||||
},
|
||||
{
|
||||
$replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$fromItems", 0] },] } }
|
||||
},
|
||||
{ $project: { username: 1, name: 1, surname: 1 } }
|
||||
|
||||
];
|
||||
return query
|
||||
}
|
||||
|
||||
|
||||
bookingSchema.statics.findAllDistinctByBooking = function (idapp) {
|
||||
const Booking = this;
|
||||
|
||||
const query = getUsersByBooking(idapp);
|
||||
|
||||
return Booking.aggregate(query)
|
||||
.then(ris => {
|
||||
return ris
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
function getQueryBookingUser(filterMatchBefore = {}, userId) {
|
||||
|
||||
let filterMatchAfter = {
|
||||
$or: getQueryFilterTodo(userId)
|
||||
};
|
||||
|
||||
let myobjField = getobjFieldTodo(true);
|
||||
|
||||
const query = [
|
||||
{ $match: filterMatchBefore },
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
localField: "userId", // field in my collection
|
||||
foreignField: "_id", // field in the 'from' collection
|
||||
as: "fromItems"
|
||||
}
|
||||
},
|
||||
{
|
||||
$replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$fromItems", 0] }, "$$ROOT"] } }
|
||||
},
|
||||
{ $match: filterMatchAfter },
|
||||
{ $project: myobjField }];
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
|
||||
var Booking = mongoose.model('Booking', bookingSchema);
|
||||
|
||||
module.exports = { Booking };
|
||||
|
||||
59
server/models/sendmsg.js
Normal file
59
server/models/sendmsg.js
Normal file
@@ -0,0 +1,59 @@
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
});
|
||||
|
||||
const sendmsgSchema = new Schema({
|
||||
idapp: {
|
||||
type: Number,
|
||||
},
|
||||
userId: {
|
||||
type: String,
|
||||
},
|
||||
idappDest: {
|
||||
type: Number,
|
||||
},
|
||||
usernameDest: {
|
||||
type: String,
|
||||
},
|
||||
msg: {
|
||||
type: String,
|
||||
},
|
||||
date: {
|
||||
type: Date,
|
||||
},
|
||||
read: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
deleted: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
originpage: {
|
||||
type: String,
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
sendmsgSchema.statics.findAllByUserIdAndIdApp = function (userId, idapp) {
|
||||
const SendMsg = this;
|
||||
|
||||
return SendMsg.find({userId, idapp}, (err, arrmsg) => {
|
||||
console.log('ris arrmsg:', arrmsg);
|
||||
return arrmsg
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
var SendMsg = mongoose.model('SendMsg', sendMsgSchema);
|
||||
|
||||
module.exports = { SendMsg };
|
||||
@@ -32,7 +32,7 @@ var UserSchema = new mongoose.Schema({
|
||||
}*/
|
||||
},
|
||||
idapp: {
|
||||
type: Number,
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
username: {
|
||||
|
||||
Reference in New Issue
Block a user