Skip to content

Commit

Permalink
impl of create event route
Browse files Browse the repository at this point in the history
  • Loading branch information
cmglezpdev committed Aug 3, 2022
1 parent a761cfa commit c616f32
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
23 changes: 17 additions & 6 deletions controllers/events.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
const { response } = require('express');
const Event = require('../models/Event');

const createEvent = async ( req, res = response ) => {

const createEvent = ( req, res = response ) => {
const event = new Event( req.body );

// verificar que tenga el evento
try {

event.user = req.uid;
const eventDB = await event.save();

res.json({
ok: true,
msg: "Create Event"
})
res.json({
ok: true,
msg: "Create Event",
event: eventDB
})

} catch (error) {
console.log(error);
res.status(500).json({ok:false, msg:"Please, Talk with the admin"});
}
}

const getEvents = ( req, res = response ) => {
Expand Down
16 changes: 12 additions & 4 deletions models/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,32 @@ const EventSchema = Schema({

title: {
type: String,
require: true
required: true
},
notes: {
type: String,
},
start: {
type: Date,
require: true
required: true
},
end: {
type: Date,
require: true
required: true
},
user: {
type:Schema.Types.ObjectId,
ref: 'User'
ref: 'User',
required: true
}

});

EventSchema.method('toJSON', function() {
const { __v, _id, ...object } = this.toObject();
object.id = _id;

return object;
})

module.exports = model('Event', EventSchema);
6 changes: 3 additions & 3 deletions models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ const { Schema, model } = require('mongoose');
const UserSchema = Schema({
name: {
type: String,
require: true
required: true
},
email: {
type: String,
require: true,
required: true,
unique: true
},
password: {
type: String,
require: true
required: true
}
});

Expand Down

0 comments on commit c616f32

Please sign in to comment.