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

- Add Where table
This commit is contained in:
Paolo Arena
2019-10-21 20:38:10 +02:00
parent 1a1348c563
commit 570bbf3744
7 changed files with 102 additions and 37 deletions

View File

@@ -2,7 +2,7 @@ var mongoose = require('mongoose');
const Subscription = mongoose.model('subscribers');
module.exports = {
doOtherThingsAfterDeleted: function (tablename, rec) {
doOtherThingsAfterDeleted: async function (tablename, rec) {
try {
if (tablename === 'users') {
// Delete also all the subscribers record of this User
@@ -13,12 +13,14 @@ module.exports = {
}
return true;
},
doOtherThingsAfterDuplicated: function (tablename, rec) {
doOtherThingsAfterDuplicated: async function (tablename, myrec, mynewrec) {
try {
if (tablename === 'users') {
// Delete also all the subscribers record of this User
}
return { myrec }
} catch (e) {
return false
}

View File

@@ -9,6 +9,7 @@ const { authenticate } = require('../middleware/authenticate');
const { Booking } = require('../models/booking');
const { MyEvent } = require('../models/myevent');
const { Operator } = require('../models/operator');
const { Where } = require('../models/where');
const { ObjectID } = require('mongodb');
@@ -121,7 +122,11 @@ router.get('/:userId/:idapp/:sall', authenticate, (req, res) => {
return Operator.findAllIdApp(idapp)
.then((operators) => {
res.send({ bookedevent, eventlist, operators });
return Where.findAllIdApp(idapp)
.then((wheres) => {
res.send({ bookedevent, eventlist, operators, wheres });
})
})
})

View File

@@ -13,6 +13,7 @@ const _ = require('lodash');
const { User } = require('../models/user');
const { Booking } = require('../models/booking');
const { Operator } = require('../models/operator');
const { Where } = require('../models/where');
const { MyEvent } = require('../models/myevent');
@@ -162,7 +163,9 @@ function getTableByTableName(tablename) {
mytable = Booking;
else if (tablename === 'operators')
mytable = Operator;
else if (tablename === 'events')
else if (tablename === 'wheres')
mytable = Where;
else if (tablename === 'myevents')
mytable = MyEvent;
return mytable
@@ -258,14 +261,16 @@ router.delete('/delrec/:table/:id', authenticate, (req, res) => {
tools.mylog('DELETED ', rec._id);
// Do extra things after deleted
actions.doOtherThingsAfterDeleted(tablename, rec).then((ris) => {
if (ris)
return actions.doOtherThingsAfterDeleted(tablename, rec).then((ris) => {
if (ris) {
tools.mylog('DELETED Others things ...');
return res.send({ code: server_constants.RIS_CODE_OK, msg: '' });
}
});
return res.send({ code: server_constants.RIS_CODE_OK, msg: '' });
}).catch((e) => {
console.log(e);
res.status(400).send();
});
});
@@ -285,26 +290,32 @@ router.post('/duprec/:table/:id', authenticate, (req, res) => {
return res.status(404).send({ code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: '' });
}
return mytable.find({ id }).then((mydata) => {
mydata._id = '';
const mynewrec = new mytable(mydata);
return mytable.findById(id).then((mydata) => {
return mynewrec.save().then((rec) => {
if (!rec) {
return res.status(404).send();
}
const datadup = tools.CloneRecordToNew(mydata);
const mynewrec = new mytable(datadup);
tools.mylog('DUPLICATED ', rec);
return mynewrec.save()
.then((rec) => {
if (!rec) {
return res.status(404).send();
}
// Do extra things after deleted
actions.doOtherThingsAfterDuplicated(tablename, rec).then((ris) => {
// ...
tools.mylog('DUPLICATED ', rec);
// Do extra things after deleted
return actions.doOtherThingsAfterDuplicated(tablename, rec).then(({ myrec }) => {
// ...
mytable.findById(myrec._id).then((record) => {
return res.send({ code: server_constants.RIS_CODE_OK, record, msg: '' });
});
});
}).catch((e) => {
console.error(e);
res.status(400).send();
});
return res.send({ code: server_constants.RIS_CODE_OK, record: rec, msg: '' });
}).catch((e) => {
res.status(400).send();
});
})
});