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.

This commit is contained in:
elweyn 2022-01-27 11:04:32 +01:00
parent e4900e03a5
commit 6c81673a4b

View File

@ -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])