- 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

@@ -21,7 +21,7 @@ const bookingSchema = new Schema({
type: String, type: String,
}, },
id_bookedevent: { id_bookedevent: {
type: Number, type: String,
}, },
numpeople: { numpeople: {
type: Number, type: Number,

View File

@@ -29,19 +29,10 @@ const MyEventSchema = new Schema({
details: { details: {
type: String, type: String,
}, },
withtime: { dateTimeStart: {
type: Boolean, type: Date,
}, },
dur: { dateTimeEnd: {
type: Number,
},
dur2: {
type: Number,
},
days: {
type: Number,
},
date: {
type: Date, type: Date,
}, },
bgcolor: { bgcolor: {
@@ -56,7 +47,7 @@ const MyEventSchema = new Schema({
img: { img: {
type: String, type: String,
}, },
where: { wherecode: {
type: String, type: String,
}, },
contribtype: { // TABLE contribtype: { // TABLE

46
server/models/where.js Normal file
View File

@@ -0,0 +1,46 @@
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 WhereSchema = new Schema({
idapp: {
type: String,
},
code: {
type: String,
},
placename: {
type: String,
},
whereicon: {
type: String,
},
});
WhereSchema.statics.executeQueryTable = function (idapp, params) {
return tools.executeQueryTable(this, idapp, params);
};
WhereSchema.statics.findAllIdApp = function (idapp) {
const Where = this;
const myfind = { idapp };
return Where.find(myfind, (err, arrrec) => {
return arrrec
});
};
const Where = mongoose.model('Where', WhereSchema);
module.exports = { Where };

View File

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

View File

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

View File

@@ -6,6 +6,8 @@ require('../models/subscribers');
var Url = require('url-parse'); var Url = require('url-parse');
const { ObjectID } = require('mongodb');
const mongoose = require('mongoose'); const mongoose = require('mongoose');
const Subscription = mongoose.model('subscribers'); const Subscription = mongoose.model('subscribers');
@@ -97,6 +99,14 @@ module.exports = {
return JSON.parse(JSON.stringify(src)) return JSON.parse(JSON.stringify(src))
}, },
CloneRecordToNew(src) {
const myrec = Object.assign({}, src);
delete myrec._doc['_id'];
myrec._id = new ObjectID();
return myrec._doc
},
sendBackNotif: function (subscription, payload) { sendBackNotif: function (subscription, payload) {
console.log('sendBackNotif:', subscription, payload); console.log('sendBackNotif:', subscription, payload);