forked from PalisadoesFoundation/talawa-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13bc93b
commit dd0ac43
Showing
4 changed files
with
59 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"env" : { | ||
"MONGO_USER":"Laurell", | ||
"MONGO_PASSWORD":"ZcLvZYZshDa7Jt7j", | ||
"MONGO_USER":"devtest876", | ||
"MONGO_PASSWORD":"5zsHsI2TiuikxMud", | ||
"MONGO_DB":"tenten" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,50 @@ | ||
const User = require("../../models/User"); | ||
const Event = require("../../models/Event"); | ||
const Organization = require("../../models/Organization"); | ||
|
||
const createEvent = async (parent, args, context, info) => { | ||
//authentication check | ||
if (!context.isAuth) throw new Error("User is not authenticated"); | ||
//authentication check | ||
if (!context.isAuth) throw new Error("User is not authenticated"); | ||
|
||
try { | ||
//gets user in token - to be used later on | ||
let userFound = await User.findOne({ _id: context.userId }); | ||
if (!userFound) { | ||
throw new Error("User does not exist"); | ||
} | ||
try { | ||
//gets user in token - to be used later on | ||
let userFound = await User.findOne({ _id: context.userId }); | ||
if (!userFound) { | ||
throw new Error("User does not exist"); | ||
} | ||
|
||
let newEvent = new Event({ | ||
...args.data, | ||
creator: context.userId, | ||
registrants: [context.userId], | ||
admins: [context.userId], | ||
organization: args.data.organizationId | ||
}); | ||
await newEvent.save(); | ||
//ensure organization exists | ||
let org = await Organization.findOne({ _id: args.data.organizationId }); | ||
if (!org) throw new Error("Organization not found"); | ||
|
||
|
||
//add event to the user record | ||
await User.updateOne( | ||
{ _id: userFound.id }, | ||
{ | ||
// $set: { | ||
// createdEvents: [...userFound.createdEvents, newEvent], | ||
// eventAdmin: [...userFound.eventAdmin, newEvent], | ||
// }, | ||
$push: { | ||
eventAdmin: newEvent, | ||
let newEvent = new Event({ | ||
...args.data, | ||
creator: context.userId, | ||
registrants: [context.userId], | ||
admins: [context.userId], | ||
organization: args.data.organizationId, | ||
}); | ||
await newEvent.save(); | ||
|
||
//add event to the user record | ||
await User.updateOne( | ||
{ _id: userFound.id }, | ||
{ | ||
$push: { | ||
eventAdmin: newEvent, | ||
createdEvents: newEvent, | ||
registeredEvents: newEvent, | ||
}, | ||
} | ||
); | ||
}, | ||
} | ||
); | ||
|
||
return { | ||
...newEvent._doc, | ||
}; | ||
} catch (e) { | ||
throw e; | ||
} | ||
return { | ||
...newEvent._doc, | ||
}; | ||
} catch (e) { | ||
throw e; | ||
} | ||
}; | ||
|
||
module.exports = createEvent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters