diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index d36816215..9944e726c 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -48,27 +48,41 @@ async function getUserCreations(id: number): Promise { // userId: id, // targetDate: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }), // }) - const findAllUserTransactionCreations = await getCustomRepository(TransactionCreationRepository) + const createdAmountBeforeLastMonth = await getCustomRepository(TransactionCreationRepository) .createQueryBuilder('transaction_creations') .select('SUM(transaction_creations.amount)', 'sum') .where('transaction_creations.state_user_id = :id', { id }) .andWhere({ targetDate: Raw((alias) => `${alias} > :date and ${alias} < :enddate`, { date: "2021-09-01", enddate: "2021-10-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) }) - const createdAmountBeforeLastMonth = await findAllUserTransactionCreations.getRawOne() + .getRawOne() console.log('createdAmountBeforeLastMonth', createdAmountBeforeLastMonth) - - const transactionCreationsLastMonthQuery = await findAllUserTransactionCreations.andWhere({ - targetDate: Raw((alias) => `${alias} > :date and ${alias} < :enddate`, { date: "2021-10-01", enddate: "2021-11-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) - }) - const createdAmountLastMonth = await transactionCreationsLastMonthQuery.getRawOne() + + const createdAmountLastMonth = await getCustomRepository(TransactionCreationRepository) + .createQueryBuilder('transaction_creations') + .select('SUM(transaction_creations.amount)', 'sum') + .where('transaction_creations.state_user_id = :id', { id }) + .andWhere({ + targetDate: Raw((alias) => `${alias} > :date and ${alias} < :enddate`, { date: "2021-10-01", enddate: "2021-11-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) + }) + .getRawOne() console.log('createdAmountLastMonth', createdAmountLastMonth) - const transactionCreationsMonthQuery = await findAllUserTransactionCreations.andWhere({ + const createdAmountMonth = await getCustomRepository(TransactionCreationRepository) + .createQueryBuilder('transaction_creations') + .select('SUM(transaction_creations.amount)', 'sum') + .where('transaction_creations.state_user_id = :id', { id }) + .andWhere({ targetDate: Raw((alias) => `${alias} > :date and ${alias} < :enddate`, { date: "2021-11-01", enddate: "2021-12-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) }) - const createdAmountMonth = await transactionCreationsMonthQuery.getRawOne() + .getRawOne() console.log('createdAmountMonth', createdAmountMonth) + + // const transactionCreationsMonthQuery = await findAllUserTransactionCreations.andWhere({ + // targetDate: Raw((alias) => `${alias} > :date and ${alias} < :enddate`, { date: "2021-11-01", enddate: "2021-12-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) + // }) + // const createdAmountMonth = await transactionCreationsMonthQuery.getRawOne() + // console.log('createdAmountMonth', createdAmountMonth) // const transactionCreationsLastThreeMonth = await transactionCreationsQuery.getRawOne() // console.log('transactionCreations', transactionCreations) // SELECT * FROM pending_creations WHERE userId = id