- Enable Edit Event into dialog form ... (and save to the db)
- Add Where table
This commit is contained in:
@@ -21,7 +21,7 @@ const bookingSchema = new Schema({
|
||||
type: String,
|
||||
},
|
||||
id_bookedevent: {
|
||||
type: Number,
|
||||
type: String,
|
||||
},
|
||||
numpeople: {
|
||||
type: Number,
|
||||
|
||||
@@ -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
|
||||
|
||||
46
server/models/where.js
Normal file
46
server/models/where.js
Normal 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 };
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 });
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user