From 6c81673a4b36153578e43eb0256071565040594c Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 27 Jan 2022 11:04:32 +0100 Subject: [PATCH] Update creations of a user only if the old pending creation has the same month as the updated month. Throw exception before end of file. --- backend/src/graphql/resolver/AdminResolver.ts | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 4e936a351..9ca558a9c 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -122,28 +122,27 @@ export class AdminResolver { const creationDateObj = new Date(creationDate) let creations = await getUserCreations(user.id) - creations = updateCreations(creations, pendingCreationToUpdate) + if (pendingCreationToUpdate.date.getMonth() === creationDateObj.getMonth()) { + creations = updateCreations(creations, pendingCreationToUpdate) + } - if (isCreationValid(creations, amount, creationDateObj)) { - // TODO Check if open creation (of creationDate) + amount * 10000 <= 1000 - - pendingCreationToUpdate.amount = BigInt(amount * 10000) - pendingCreationToUpdate.memo = memo - pendingCreationToUpdate.date = new Date(creationDate) - pendingCreationToUpdate.moderator = moderator - - await loginPendingTasksAdminRepository.save(pendingCreationToUpdate) - const result = new UpdatePendingCreation() - result.amount = parseInt(amount.toString()) - result.memo = pendingCreationToUpdate.memo - result.date = pendingCreationToUpdate.date - result.moderator = pendingCreationToUpdate.moderator - result.creation = await getUserCreations(user.id) - - return result - } else { + if (!isCreationValid(creations, amount, creationDateObj)) { throw new Error('Creation is not valid') } + pendingCreationToUpdate.amount = BigInt(amount * 10000) + pendingCreationToUpdate.memo = memo + pendingCreationToUpdate.date = new Date(creationDate) + pendingCreationToUpdate.moderator = moderator + + await loginPendingTasksAdminRepository.save(pendingCreationToUpdate) + const result = new UpdatePendingCreation() + result.amount = parseInt(amount.toString()) + result.memo = pendingCreationToUpdate.memo + result.date = pendingCreationToUpdate.date + result.moderator = pendingCreationToUpdate.moderator + result.creation = await getUserCreations(user.id) + + return result } @Authorized([RIGHTS.SEARCH_PENDING_CREATION])