mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Implemented a method to add back the summ to the creations array.
This commit is contained in:
parent
c27d43a219
commit
afbc52c2aa
@ -23,6 +23,7 @@ import { UserTransactionRepository } from '../../typeorm/repository/UserTransact
|
||||
import { BalanceRepository } from '../../typeorm/repository/Balance'
|
||||
import { calculateDecay } from '../../util/decay'
|
||||
import { LoginUserRepository } from '../../typeorm/repository/LoginUser'
|
||||
import { LoginPendingTasksAdmin } from '@entity/LoginPendingTasksAdmin'
|
||||
|
||||
@Resolver()
|
||||
export class AdminResolver {
|
||||
@ -120,7 +121,8 @@ export class AdminResolver {
|
||||
}
|
||||
|
||||
const creationDateObj = new Date(creationDate)
|
||||
const creations = await getUserCreations(user.id)
|
||||
let creations = await getUserCreations(user.id)
|
||||
creations = updateCreations(creations, pendingCreationToUpdate)
|
||||
|
||||
if (isCreationValid(creations, amount, creationDateObj)) {
|
||||
// TODO Check if open creation (of creationDate) + amount * 10000 <= 1000
|
||||
@ -332,6 +334,28 @@ async function getUserCreations(id: number): Promise<number[]> {
|
||||
]
|
||||
}
|
||||
|
||||
function updateCreations(creations: number[], pendingCreation: LoginPendingTasksAdmin): number[] {
|
||||
const dateMonth = moment().format('YYYY-MM')
|
||||
const dateLastMonth = moment().subtract(1, 'month').format('YYYY-MM')
|
||||
const dateBeforeLastMonth = moment().subtract(2, 'month').format('YYYY-MM')
|
||||
const creationDateMonth = moment(pendingCreation.date).format('YYYY-MM')
|
||||
|
||||
switch (creationDateMonth) {
|
||||
case dateMonth:
|
||||
creations[2] += parseInt(pendingCreation.amount.toString())
|
||||
break
|
||||
case dateLastMonth:
|
||||
creations[1] += parseInt(pendingCreation.amount.toString())
|
||||
break
|
||||
case dateBeforeLastMonth:
|
||||
creations[0] += parseInt(pendingCreation.amount.toString())
|
||||
break
|
||||
default:
|
||||
throw new Error('UpdatedCreationDate is not in the last three months')
|
||||
}
|
||||
return creations
|
||||
}
|
||||
|
||||
function isCreationValid(creations: number[], amount: number, creationDate: Date) {
|
||||
const dateMonth = moment().format('YYYY-MM')
|
||||
const dateLastMonth = moment().subtract(1, 'month').format('YYYY-MM')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user