- Enable Edit Event into dialog form ... (and save to the db)

- Event: enabled drag and drop (date)
- Q-Select components in every table field external: Where, Operators, etc...
- CMyEditor: Add HTML Editor to the details field !
- Added button Color for change font color to the text.
- Complete insert Events Site
This commit is contained in:
Paolo Arena
2019-10-23 23:47:21 +02:00
parent 570bbf3744
commit 51ca2da45f
8 changed files with 386 additions and 49 deletions

View File

@@ -30,4 +30,27 @@ const authenticate = (req, res, next) => {
});
};
module.exports = {authenticate};
const authenticate_noerror = (req, res, next) => {
const token = req.header('x-auth');
const access = 'auth';
User.findByToken(token, access).then((user) => {
if (!user) {
req.user = null;
req.token = null;
req.access = null;
}else {
req.user = user;
req.token = token;
req.access = access;
}
next();
}).catch((e) => {
req.user = null;
req.token = null;
req.access = null;
});
};
module.exports = {authenticate, authenticate_noerror};

View File

@@ -42,7 +42,6 @@ const bookingSchema = new Schema({
booked: {
type: Boolean,
},
});
bookingSchema.statics.findAllByUserIdAndIdApp = function (userId, idapp, sall) {

View File

@@ -0,0 +1,43 @@
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 ContribtypeSchema = new Schema({
idapp: {
type: String,
},
label: {
type: String,
},
showprice: {
type: Boolean,
}
});
ContribtypeSchema.statics.executeQueryTable = function (idapp, params) {
return tools.executeQueryTable(this, idapp, params);
};
ContribtypeSchema.statics.findAllIdApp = function (idapp) {
const Contribtype = this;
const myfind = { idapp };
return Contribtype.find(myfind, (err, arrrec) => {
return arrrec
});
};
const Contribtype = mongoose.model('Contribtype', ContribtypeSchema);
module.exports = { Contribtype };

View File

@@ -50,8 +50,8 @@ const MyEventSchema = new Schema({
wherecode: {
type: String,
},
contribtype: { // TABLE
type: Number,
contribtype: {
type: String,
},
price: {
type: Number,
@@ -59,7 +59,7 @@ const MyEventSchema = new Schema({
infoafterprice: {
type: String,
},
teacher: { // TABLE ?!
teacher: {
type: String,
},
teacher2: {

View File

@@ -10,6 +10,7 @@ const { Booking } = require('../models/booking');
const { MyEvent } = require('../models/myevent');
const { Operator } = require('../models/operator');
const { Where } = require('../models/where');
const { Contribtype } = require('../models/contribtype');
const { ObjectID } = require('mongodb');
@@ -97,45 +98,41 @@ router.delete('/:id/:notify/:idapp', authenticate, (req, res) => {
});
router.get('/:userId/:idapp/:sall', authenticate, (req, res) => {
const userId = req.params.userId;
const idapp = req.params.idapp;
const sall = req.params.sall;
// var category = req.params.category;
// tools.mylog('GET BOOKINGS : ', req.params);
if (!ObjectID.isValid(userId)) {
return res.status(404).send();
}
if (userId !== String(req.user._id)) {
// I'm trying to write something not mine!
return res.status(404).send({ code: server_constants.RIS_CODE_TODO_CREATING_NOTMYUSER });
}
// Extract all the todos of the userId only
Booking.findAllByUserIdAndIdApp(userId, idapp, sall).then((bookedevent) => {
return MyEvent.findAllIdApp(idapp)
.then((eventlist) => {
return Operator.findAllIdApp(idapp)
.then((operators) => {
return Where.findAllIdApp(idapp)
.then((wheres) => {
res.send({ bookedevent, eventlist, operators, wheres });
})
})
})
}).catch((e) => {
console.log(e);
res.status(400).send(e);
});
});
// router.get('/:userId/:idapp/:sall', authenticate, (req, res) => {
// const userId = req.params.userId;
// const idapp = req.params.idapp;
// const sall = req.params.sall;
// // var category = req.params.category;
//
// // tools.mylog('GET BOOKINGS : ', req.params);
//
// if (!ObjectID.isValid(userId)) {
// return res.status(404).send();
// }
//
// if (userId !== String(req.user._id)) {
// // I'm trying to write something not mine!
// return res.status(404).send({ code: server_constants.RIS_CODE_TODO_CREATING_NOTMYUSER });
// }
//
// // Extract all the todos of the userId only
// const bookedevent = Booking.findAllByUserIdAndIdApp(userId, idapp, sall);
// const eventlist = MyEvent.findAllIdApp(idapp);
// const operators = Operator.findAllIdApp(idapp);
// const wheres = Where.findAllIdApp(idapp);
// const contribtype = Contribtype.findAllIdApp(idapp);
//
// return Promise.all([bookedevent, eventlist, operators, wheres, contribtype])
// .then((arrdata) => {
// console.table(arrdata);
// res.send({ bookedevent: arrdata[0], eventlist: arrdata[1], operators: arrdata[2], wheres: arrdata[3], contribtype: arrdata[4] });
// })
// .catch((e) => {
// console.log(e);
// res.status(400).send(e);
// });
//
// });
//
module.exports = router;

View File

@@ -1,7 +1,7 @@
const express = require('express');
const router = express.Router();
const { authenticate } = require('../middleware/authenticate');
const { authenticate, authenticate_noerror } = require('../middleware/authenticate');
const { ObjectID } = require('mongodb');
@@ -15,6 +15,7 @@ const { Booking } = require('../models/booking');
const { Operator } = require('../models/operator');
const { Where } = require('../models/where');
const { MyEvent } = require('../models/myevent');
const { Contribtype } = require('../models/contribtype');
const tools = require('../tools/general');
@@ -59,9 +60,9 @@ router.post(process.env.LINKVERIF_REG, (req, res) => {
// Faccio richiesta di una Nuova Password
router.post(process.env.LINK_REQUEST_NEWPASSWORD, (req, res) => {
var body = _.pick(req.body, ['idapp', 'email']);
var idapp = body.idapp;
var email = body.email;
const body = _.pick(req.body, ['idapp', 'email']);
const idapp = body.idapp;
const email = body.email;
console.log("POST " + process.env.LINK_REQUEST_NEWPASSWORD + " idapp= " + idapp + " email = " + email);
User.findByEmail(idapp, email).then((user) => {
@@ -84,6 +85,7 @@ router.post(process.env.LINK_REQUEST_NEWPASSWORD, (req, res) => {
});
router.get(process.env.LINK_CHECK_UPDATES, authenticate, (req, res) => {
const userId = req.user._id;
@@ -167,6 +169,8 @@ function getTableByTableName(tablename) {
mytable = Where;
else if (tablename === 'myevents')
mytable = MyEvent;
else if (tablename === 'contribtype')
mytable = Contribtype;
return mytable
}
@@ -325,5 +329,38 @@ function doOtherThingsAfterDeleted() {
}
router.get('/loadsite/:userId/:idapp/:sall', authenticate_noerror, (req, res) => {
const userId = req.params.userId;
const idapp = req.params.idapp;
const sall = req.params.sall;
// var category = req.params.category;
tools.mylog('loadsite : ', req.params);
let bookedevent = [];
if (userId !== '0') {
// LOGGED WITH USERID
bookedevent = Booking.findAllByUserIdAndIdApp(userId, idapp, sall);
}
// Extract all the todos of the userId only
const eventlist = MyEvent.findAllIdApp(idapp);
const operators = Operator.findAllIdApp(idapp);
const wheres = Where.findAllIdApp(idapp);
const contribtype = Contribtype.findAllIdApp(idapp);
return Promise.all([bookedevent, eventlist, operators, wheres, contribtype])
.then((arrdata) => {
console.table(arrdata);
res.send({ bookedevent: arrdata[0], eventlist: arrdata[1], operators: arrdata[2], wheres: arrdata[3], contribtype: arrdata[4] });
})
.catch((e) => {
console.log(e);
res.status(400).send(e);
});
});
module.exports = router;