From 537ec07f2937346c8ccf6d853fc96c22d6ca3db1 Mon Sep 17 00:00:00 2001 From: trivernis Date: Thu, 23 Jan 2020 15:43:13 +0100 Subject: [PATCH] Add deletion of media to deletePost --- src/routes/graphql/MutationResolver.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/routes/graphql/MutationResolver.ts b/src/routes/graphql/MutationResolver.ts index edf8f60..ac30772 100644 --- a/src/routes/graphql/MutationResolver.ts +++ b/src/routes/graphql/MutationResolver.ts @@ -171,6 +171,14 @@ export class MutationResolver extends BaseResolver { }); const isAdmin = (await User.findOne({where: {id: request.session.userId}})).isAdmin; if (post.rAuthor.id === request.session.userId || isAdmin) { + if (post.mediaUrl) { + try { + await this.uploadManager.deleteWebFile(post.mediaUrl); + } catch (err) { + globals.logger.error(err.message); + globals.logger.debug(err.stack); + } + } return await dataaccess.deletePost(post.id); } else { throw new GraphQLError("User is not author of the post.");