- Booking Event (with email to user and admin)

- Cancel Event (with email to user and admin)
- Store into mongodb
This commit is contained in:
Paolo Arena
2019-10-05 20:01:56 +02:00
parent 507f465313
commit 8f69856c57
37 changed files with 758 additions and 46 deletions

54
server/models/booking.js Normal file
View File

@@ -0,0 +1,54 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
mongoose.level = "F";
const { ObjectID } = require('mongodb');
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
const bookingSchema = new Schema({
idapp: {
type: Number,
},
userId: {
type: String,
},
id_bookedevent: {
type: Number,
},
numpeople: {
type: Number,
},
infoevent: {
type: String,
},
msgbooking: {
type: String,
},
datebooked: {
type: Date,
},
booked: {
type: Boolean,
},
});
bookingSchema.statics.findAllByUserIdAndIdApp = function (userId, idapp) {
const Booking = this;
return Booking.find({userId, idapp, booked: true}, (err, arrbooked) => {
console.log('ris Booking:', arrbooked);
return arrbooked
});
};
var Booking = mongoose.model('Booking', bookingSchema);
module.exports = { Booking };

View File

@@ -42,6 +42,14 @@ var UserSchema = new mongoose.Schema({
minlength: 6,
unique: true,
},
name: {
type: String,
trim: true,
},
surname: {
type: String,
trim: true,
},
password: {
type: String,
require: true,
@@ -88,7 +96,7 @@ UserSchema.methods.toJSON = function () {
var user = this;
var userObject = user.toObject();
return _.pick(userObject, ['_id', 'email', 'verified_email', 'username', 'userId']);
return _.pick(userObject, ['_id', 'email', 'verified_email', 'username', 'userId', 'name', 'surname']);
};
UserSchema.methods.generateAuthToken = function (req) {