From 6a152a8791612a2c08ea16325f75819b2f388df0 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 13:31:27 +0100 Subject: [PATCH] Change query to query builder. --- backend/src/graphql/resolver/AdminResolver.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 36e31c21e..089ce870d 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -44,10 +44,14 @@ export class AdminResolver { async function getUserCreations(id: number): Promise { // TODO: NOW()-ActualDays - 2 Monate - const transactionCreations = await getCustomRepository(TransactionCreationRepository).find({ - userId: id, - targetDate: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }), - }) + // const transactionCreations = await getCustomRepository(TransactionCreationRepository).find({ + // userId: id, + // targetDate: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }), + // }) + const transactionCreations = await getCustomRepository(TransactionCreationRepository) + .createQueryBuilder() + .select(['SUM(login_pending_tasks_admin.amount)']) + .where('login_pending_tasks_admin.userId = :id', { id }) console.log('transactionCreations', transactionCreations) // SELECT * FROM pending_creations WHERE userId = id const pendingCreations = await getCustomRepository(PendingCreationRepository).find({ @@ -55,6 +59,12 @@ async function getUserCreations(id: number): Promise { date: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }), }) console.log('pendingCreations', pendingCreations) + // const createdAmountBeforeLastMonth = transactionCreations.forEach(element => { + // element.targetDate + // }) + // const createdAmountLastMonth = ... + // const createdAmountCurrentMonth = ... + // COUNT amount from 2 tables // if amount < 3000 => Store in pending_creations return [