Fix deletePost

pull/5/head
Trivernis 5 years ago
parent b1b5f82f95
commit a0ecb36064

@ -258,7 +258,12 @@ export function resolver(req: any, res: any): any {
}]});
const isAdmin = (await models.User.findOne({where: {id: req.session.userId}})).isAdmin;
if (post.rAuthor.id === req.session.userId || isAdmin) {
try {
return await dataaccess.deletePost(post.id);
} catch (err) {
res.status(status.BAD_REQUEST);
return err.graphqlError ?? new GraphQLError(err.message);
}
} else {
res.status(status.FORBIDDEN);
return new GraphQLError("User is not author of the post.");

@ -197,10 +197,15 @@ namespace dataaccess {
const post = await models.Post.findByPk(postId, {include: [{model: Activity}, {association: "rAuthor"}]});
const activity = await post.activity();
const author = await post.author();
if (activity && author) {
author.rankpoints -= activity.points;
await author.save();
}
await post.destroy();
} catch (err) {
return new PostNotFoundGqlError(postId);
globals.logger.error(err.message);
globals.logger.debug(err.stack);
throw new PostNotFoundGqlError(postId);
}
return true;
}

Loading…
Cancel
Save