Change calls to have query for last three months.

This commit is contained in:
Hannes Heine 2021-11-24 14:23:32 +01:00 committed by ogerly
parent 735a47779f
commit 9193eeb6a8

View File

@ -48,27 +48,41 @@ async function getUserCreations(id: number): Promise<number[]> {
// 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