mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
less db calls for get pending creations
This commit is contained in:
parent
99f641f1f9
commit
c0c5510903
@ -2,7 +2,7 @@
|
|||||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||||
|
|
||||||
import { Resolver, Query, Arg, Args, Authorized, Mutation, Ctx } from 'type-graphql'
|
import { Resolver, Query, Arg, Args, Authorized, Mutation, Ctx } from 'type-graphql'
|
||||||
import { getCustomRepository, ObjectLiteral, getConnection } from '@dbTools/typeorm'
|
import { getCustomRepository, ObjectLiteral, getConnection, In } from '@dbTools/typeorm'
|
||||||
import { UserAdmin, SearchUsersResult } from '../model/UserAdmin'
|
import { UserAdmin, SearchUsersResult } from '../model/UserAdmin'
|
||||||
import { PendingCreation } from '../model/PendingCreation'
|
import { PendingCreation } from '../model/PendingCreation'
|
||||||
import { CreatePendingCreations } from '../model/CreatePendingCreations'
|
import { CreatePendingCreations } from '../model/CreatePendingCreations'
|
||||||
@ -201,27 +201,23 @@ export class AdminResolver {
|
|||||||
@Query(() => [PendingCreation])
|
@Query(() => [PendingCreation])
|
||||||
async getPendingCreations(): Promise<PendingCreation[]> {
|
async getPendingCreations(): Promise<PendingCreation[]> {
|
||||||
const pendingCreations = await AdminPendingCreation.find()
|
const pendingCreations = await AdminPendingCreation.find()
|
||||||
|
const userIds = pendingCreations.map((p) => p.userId)
|
||||||
|
const userCreations = await getUserCreations(userIds)
|
||||||
|
const users = await User.find({ id: In(userIds) })
|
||||||
|
|
||||||
const pendingCreationsPromise = await Promise.all(
|
return pendingCreations.map((pendingCreation) => {
|
||||||
pendingCreations.map(async (pendingCreation) => {
|
const user = users.find((u) => u.id === pendingCreation.userId)
|
||||||
const userRepository = getCustomRepository(UserRepository)
|
const creation = userCreations.find((c) => c.id === pendingCreation.id)
|
||||||
const user = await userRepository.findOneOrFail({ id: pendingCreation.userId })
|
|
||||||
|
|
||||||
const parsedAmount = Number(parseInt(pendingCreation.amount.toString()) / 10000)
|
return {
|
||||||
// pendingCreation.amount = parsedAmount
|
...pendingCreation,
|
||||||
const newPendingCreation = {
|
amount: Number(parseInt(pendingCreation.amount.toString()) / 10000),
|
||||||
...pendingCreation,
|
firstName: user ? user.firstName : '',
|
||||||
amount: parsedAmount,
|
lastName: user ? user.lastName : '',
|
||||||
firstName: user.firstName,
|
email: user ? user.email : '',
|
||||||
lastName: user.lastName,
|
creation: creation ? creation.creations : [1000, 1000, 1000],
|
||||||
email: user.email,
|
}
|
||||||
creation: await getUserCreation(user.id),
|
})
|
||||||
}
|
|
||||||
|
|
||||||
return newPendingCreation
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
return pendingCreationsPromise.reverse()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Authorized([RIGHTS.DELETE_PENDING_CREATION])
|
@Authorized([RIGHTS.DELETE_PENDING_CREATION])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user