- Added TablesList page

- Added Insert Record empty
This commit is contained in:
Paolo Arena
2019-10-20 01:21:54 +02:00
parent 3424b20e9a
commit 93eae51ab8
16 changed files with 568 additions and 88 deletions

View File

@@ -4,6 +4,8 @@ const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
mongoose.level = "F";
const tools = require('../tools/general');
const { ObjectID } = require('mongodb');
// Resolving error Unknown modifier: $pushAll
@@ -13,7 +15,7 @@ mongoose.plugin(schema => {
const bookingSchema = new Schema({
idapp: {
type: Number,
type: String,
},
userId: {
type: String,
@@ -104,34 +106,6 @@ bookingSchema.statics.findAllDistinctByBooking = function (idapp) {
};
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);
const Booking = mongoose.model('Booking', bookingSchema);
module.exports = { Booking };

173
server/models/myevent.js Normal file
View File

@@ -0,0 +1,173 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
mongoose.level = "F";
const tools = require('../tools/general');
const { ObjectID } = require('mongodb');
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
const MyEventSchema = new Schema({
idapp: {
type: String,
},
typol: {
type: String,
},
short_tit: {
type: String,
},
title: {
type: String,
},
details: {
type: String,
},
time: {
type: String,
},
dur: {
type: Number,
},
dur2: {
type: Number,
},
days: {
type: Number,
},
date: {
type: Date,
},
bgcolor: {
type: String,
},
icon: {
type: String,
},
img_small: {
type: String,
},
img: {
type: String,
},
where: {
type: String,
},
contribtype: { // TABLE
type: Number,
},
price: {
type: Number,
},
infoafterprice: {
type: String,
},
teacher: { // TABLE ?!
type: String,
},
teacher2: {
type: String,
},
infoextra: {
type: String,
},
linkpage: {
type: String,
},
linkpdf: {
type: String,
},
nobookable: {
type: Boolean,
},
news: {
type: Boolean,
},
canceled: {
type: Boolean,
},
deleted: {
type: Boolean,
},
dupId: {
type: mongoose.Schema.Types.ObjectId,
},
modified: {
type: Boolean,
},
});
MyEventSchema.statics.findAllByUserIdAndIdApp = function (userId, idapp, sall) {
const Event = this;
let myfind = {};
if (sall === '1')
myfind = { idapp, booked: true };
else
myfind = { userId, idapp, booked: true };
return Event.find(myfind, (err, arrbooked) => {
// console.log('ris MyEvent:', arrbooked);
return arrbooked
});
};
function getUsersByEvent(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
}
MyEventSchema.statics.findAllDistinctByEvent = function (idapp) {
const Event = this;
const query = getUsersByEvent(idapp);
return Event.aggregate(query)
.then(ris => {
return ris
});
};
MyEventSchema.statics.executeQueryTable = function (idapp, params) {
return tools.executeQueryTable(this, idapp, params);
};
const MyEvent = mongoose.model('MyEvent', MyEventSchema);
module.exports = { MyEvent };

63
server/models/operator.js Normal file
View File

@@ -0,0 +1,63 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const tools = require('../tools/general');
mongoose.Promise = global.Promise;
mongoose.level = "F";
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
const OperatorSchema = new Schema({
idapp: {
type: String,
},
username: {
type: String,
},
name: {
type: String,
},
surname: {
type: String,
},
email: {
type: String,
},
cell: {
type: String,
},
webpage: {
type: String,
},
img: {
type: String,
},
skype: {
type: String,
},
days_working: {
type: String,
},
facebook: {
type: String,
},
disciplines: {
type: String,
},
offers: {
type: String,
},
});
OperatorSchema.statics.executeQueryTable = function (idapp, params) {
return tools.executeQueryTable(this, idapp, params);
};
const Operator = mongoose.model('Operator', OperatorSchema);
module.exports = { Operator };

View File

@@ -13,7 +13,7 @@ mongoose.plugin(schema => {
const sendmsgSchema = new Schema({
idapp: {
type: Number,
type: String,
},
userId: {
type: String,

View File

@@ -330,45 +330,8 @@ UserSchema.statics.getUsersListByParams = function (params) {
* @returns {Object} Object -> `{ rows, count }`
*/
UserSchema.statics.queryTable = function (idapp, params) {
const User = this;
if (typeof params.startRow !== 'number') {
throw new Error('startRow must be number')
} else if (typeof params.endRow !== 'number') {
throw new Error('endRow must be number')
}
const query = [
{ $match: Object.assign({ idapp }, params.filter) }
];
if (params.sortBy) {
// maybe we want to sort by blog title or something
const mysort = { $sort: params.sortBy };
// console.log('sortBy', params.sortBy);
// console.table(mysort);
query.push(mysort)
}
query.push(
{ $group: {
_id: null,
// get a count of every result that matches until now
count: { $sum: 1 },
// keep our results for the next operation
results: { $push: '$$ROOT' }
} },
// and finally trim the results to within the range given by start/endRow
{ $project: {
count: 1,
rows: { $slice: ['$results', params.startRow, params.endRow] }
} }
);
return User
.aggregate(query)
.then(([{ count, rows }]) => ({ count, rows }))
UserSchema.statics.executeQueryTable = function (idapp, params) {
return tools.executeQueryTable(this, idapp, params);
};