diff --git a/server/models/booking.js b/server/models/booking.js index 7f62f83..ae8274c 100644 --- a/server/models/booking.js +++ b/server/models/booking.js @@ -21,7 +21,7 @@ const bookingSchema = new Schema({ type: String, }, id_bookedevent: { - type: Number, + type: String, }, numpeople: { type: Number, diff --git a/server/models/myevent.js b/server/models/myevent.js index 93930a1..0cdba28 100644 --- a/server/models/myevent.js +++ b/server/models/myevent.js @@ -29,19 +29,10 @@ const MyEventSchema = new Schema({ details: { type: String, }, - withtime: { - type: Boolean, + dateTimeStart: { + type: Date, }, - dur: { - type: Number, - }, - dur2: { - type: Number, - }, - days: { - type: Number, - }, - date: { + dateTimeEnd: { type: Date, }, bgcolor: { @@ -56,7 +47,7 @@ const MyEventSchema = new Schema({ img: { type: String, }, - where: { + wherecode: { type: String, }, contribtype: { // TABLE diff --git a/server/models/where.js b/server/models/where.js new file mode 100644 index 0000000..308d281 --- /dev/null +++ b/server/models/where.js @@ -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 }; diff --git a/server/router/api/actions.js b/server/router/api/actions.js index 2cd4dd5..aaa8296 100644 --- a/server/router/api/actions.js +++ b/server/router/api/actions.js @@ -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 } diff --git a/server/router/booking_router.js b/server/router/booking_router.js index a04c1da..b6b73c8 100644 --- a/server/router/booking_router.js +++ b/server/router/booking_router.js @@ -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 }); + }) }) }) diff --git a/server/router/index_router.js b/server/router/index_router.js index f70d6a1..d50c7fd 100644 --- a/server/router/index_router.js +++ b/server/router/index_router.js @@ -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(); - }); }) }); diff --git a/server/tools/general.js b/server/tools/general.js index 0b49d64..018e307 100644 --- a/server/tools/general.js +++ b/server/tools/general.js @@ -6,6 +6,8 @@ require('../models/subscribers'); var Url = require('url-parse'); +const { ObjectID } = require('mongodb'); + const mongoose = require('mongoose'); const Subscription = mongoose.model('subscribers'); @@ -97,6 +99,14 @@ module.exports = { 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) { console.log('sendBackNotif:', subscription, payload);