Add denied_at is null to query, change variable name of query.

This commit is contained in:
elweyn 2022-09-21 11:47:24 +02:00
parent 4e72aafe4d
commit e097c30003

View File

@ -1,4 +1,3 @@
import { TransactionTypeId } from '@/graphql/enum/TransactionTypeId'
import { backendLogger as logger } from '@/server/logger' import { backendLogger as logger } from '@/server/logger'
import { getConnection } from '@dbTools/typeorm' import { getConnection } from '@dbTools/typeorm'
import { Contribution } from '@entity/Contribution' import { Contribution } from '@entity/Contribution'
@ -49,10 +48,11 @@ export const getUserCreations = async (
where user_id = 776 where user_id = 776
and contribution_date >= last_day(curdate() - interval 3 month) + interval 1 day and contribution_date >= last_day(curdate() - interval 3 month) + interval 1 day
and deleted_at IS NULL and deleted_at IS NULL
and denied_at IS NULL
if(!includePending) and confirmed_at IS NOT NULL if(!includePending) and confirmed_at IS NOT NULL
group by month, user_id; group by month, user_id;
*/ */
const bookedCreationQuery = queryRunner.manager const sumAmountContributionPerUserAndLast3MonthQuery = queryRunner.manager
.createQueryBuilder(Contribution, 'c') .createQueryBuilder(Contribution, 'c')
.select('month(contribution_date)', 'month') .select('month(contribution_date)', 'month')
.addSelect('user_id', 'userId') .addSelect('user_id', 'userId')
@ -60,21 +60,22 @@ export const getUserCreations = async (
.where(`user_id in (${ids.toString()})`) .where(`user_id in (${ids.toString()})`)
.andWhere(`contribution_date >= ${dateFilter}`) .andWhere(`contribution_date >= ${dateFilter}`)
.andWhere('deleted_at IS NULL') .andWhere('deleted_at IS NULL')
.andWhere('denied_at IS NULL')
.groupBy('month') .groupBy('month')
.addGroupBy('userId') .addGroupBy('userId')
if (!includePending) { if (!includePending) {
bookedCreationQuery.andWhere('confirmed_at IS NOT NULL') sumAmountContributionPerUserAndLast3MonthQuery.andWhere('confirmed_at IS NOT NULL')
} }
const bookedCreation = await bookedCreationQuery.getRawMany() const sumAmountContributionPerUserAndLast3Month =
// eslint-disable-next-line no-console await sumAmountContributionPerUserAndLast3MonthQuery.getRawMany()
console.log('openCreation', bookedCreation)
await queryRunner.release() await queryRunner.release()
return ids.map((id) => { return ids.map((id) => {
return { return {
id, id,
creations: months.map((month) => { creations: months.map((month) => {
const creation = bookedCreation.find( const creation = sumAmountContributionPerUserAndLast3Month.find(
(raw: { month: string; userId: string; creation: number[] }) => (raw: { month: string; userId: string; creation: number[] }) =>
parseInt(raw.month) === month && parseInt(raw.userId) === id, parseInt(raw.month) === month && parseInt(raw.userId) === id,
) )