Event changes

- changed creation to group-admins only
pull/5/head
Trivernis 5 years ago
parent f7dae45ab9
commit 05e69aacf3

@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- changed the running behaviour to run in cluster threads via node.js cluster api - changed the running behaviour to run in cluster threads via node.js cluster api
- gql field userVote requires a userId - gql field userVote requires a userId
- default findUser param limit to 20 - default findUser param limit to 20
- only group admins can create group events
### Fixed ### Fixed

@ -441,8 +441,13 @@ export function resolver(req: any, res: any): any {
async createEvent({name, dueDate, groupId}: { name: string, dueDate: string, groupId: number }) { async createEvent({name, dueDate, groupId}: { name: string, dueDate: string, groupId: number }) {
if (req.session.userId) { if (req.session.userId) {
const date = new Date(Number(dueDate)); const date = new Date(Number(dueDate));
const group = await models.Group.findByPk(groupId); const group = await models.Group.findByPk(groupId, {include: [{association: "rAdmins"}]});
if (group.rAdmins.find((x) => x.id === req.session.userId)) {
return group.$create<models.Event>("rEvent", {name, dueDate: date}); return group.$create<models.Event>("rEvent", {name, dueDate: date});
} else {
res.status(status.FORBIDDEN);
return new GraphQLError("You are not a group admin!");
}
} else { } else {
res.status(status.UNAUTHORIZED); res.status(status.UNAUTHORIZED);
return new NotLoggedInGqlError(); return new NotLoggedInGqlError();

Loading…
Cancel
Save