move date pick logic by contribution state into backend

This commit is contained in:
einhornimmond 2025-12-19 11:56:01 +01:00
parent 4d1eaba6cf
commit 8b8e6cfa0d
5 changed files with 44 additions and 70 deletions

View File

@ -99,9 +99,6 @@
</BButton>
</div>
</template>
<template #cell(closed)="row">
{{ formatDateOrDash(getClosedDate(row.item)) }}
</template>
<template #row-details="row">
<row-details
:row="row"
@ -214,16 +211,6 @@ export default {
if (item.contributionStatus === 'IN_PROGRESS') return 'table-primary'
if (item.contributionStatus === 'PENDING') return 'table-primary'
},
getClosedDate(item) {
if (item.contributionStatus === 'CONFIRMED') {
return item.confirmedAt
} else if (item.contributionStatus === 'DENIED') {
return item.deniedAt
} else if (item.contributionStatus === 'DELETED') {
return item.deletedAt
}
return null
},
updateStatus(id) {
this.$emit('update-status', id)
},
@ -251,22 +238,18 @@ export default {
}
},
isAddCommentToMemo(item) {
return (
item.updatedBy > 0 ||
item.confirmedBy > 0 ||
item.deletedBy > 0 ||
item.deniedBy > 0 ||
item.moderatorId > 0
)
return item.closedBy > 0 || item.moderatorId > 0 || item.updatedBy > 0
},
getMemoComment(item) {
let comment = ''
if (item.confirmedBy > 0) {
comment = this.$t('contribution.confirmedBy', { name: item.confirmedByUserName })
} else if (item.deletedBy > 0) {
comment = this.$t('contribution.deletedBy', { name: item.deletedByUserName })
} else if (item.deniedBy > 0) {
comment = this.$t('contribution.deniedBy', { name: item.deniedByUserName })
if (item.closedBy > 0) {
if (item.contributionStatus === 'CONFIRMED') {
comment = this.$t('contribution.confirmedBy', { name: item.closedByUserName })
} else if (item.contributionStatus === 'DENIED') {
comment = this.$t('contribution.deniedBy', { name: item.closedByUserName })
} else if (item.contributionStatus === 'DELETED') {
comment = this.$t('contribution.deletedBy', { name: item.closedByUserName })
}
}
if (item.updatedBy > 0) {

View File

@ -19,22 +19,16 @@ query adminListContributions(
}
amount
memo
createdAt
closedAt
closedBy
closedByUserName
contributionDate
confirmedAt
confirmedBy
confirmedByUserName
createdAt
updatedAt
updatedBy
updatedByUserName
contributionStatus
messagesCount
deniedAt
deniedBy
deniedByUserName
deletedAt
deletedBy
deletedByUserName
moderatorId
moderatorUserName
userId

View File

@ -154,9 +154,9 @@ const baseFields = {
class: 'no-select',
formatter: formatDateOrDash,
},
confirmedAt: {
key: 'confirmedAt',
label: t('contributions.confirms'),
closedAt: {
key: 'closedAt',
label: t('contributions.closed'),
class: 'no-select',
formatter: formatDateOrDash,
},
@ -185,7 +185,7 @@ const fields = computed(
baseFields.memo,
baseFields.contributionDate,
baseFields.createdAt,
baseFields.confirmedAt,
baseFields.closedAt,
{ key: 'chatCreation', label: t('details') },
],
// denied contributions
@ -196,11 +196,7 @@ const fields = computed(
baseFields.memo,
baseFields.contributionDate,
baseFields.createdAt,
{
key: 'deniedAt',
label: t('contributions.denied'),
formatter: formatDateOrDash,
},
baseFields.closedAt,
{ key: 'chatCreation', label: t('details') },
],
// deleted contributions
@ -211,11 +207,7 @@ const fields = computed(
baseFields.memo,
baseFields.contributionDate,
baseFields.createdAt,
{
key: 'deletedAt',
label: t('contributions.deleted'),
formatter: formatDateOrDash,
},
baseFields.closedAt,
{ key: 'chatCreation', label: t('details') },
],
// all contributions
@ -227,11 +219,7 @@ const fields = computed(
baseFields.memo,
baseFields.contributionDate,
baseFields.createdAt,
{
key: 'closed',
label: t('contributions.closed'),
class: 'no-select',
},
baseFields.closedAt,
{ key: 'chatCreation', label: t('details') },
],
][tabIndex.value],

View File

@ -1,3 +1,4 @@
import { ContributionStatus } from '@enum/ContributionStatus'
import { Contribution as DbContribution } from 'database'
import { Field, Int, ObjectType } from 'type-graphql'
import { UnconfirmedContribution } from './UnconfirmedContribution'
@ -19,7 +20,27 @@ export class Contribution extends UnconfirmedContribution {
this.updatedAt = dbContribution.updatedAt
this.updatedBy = dbContribution.updatedBy
this.resubmissionAt = dbContribution.resubmissionAt
if( ContributionStatus.CONFIRMED === dbContribution.contributionStatus) {
this.closedAt = dbContribution.confirmedAt
this.closedBy = dbContribution.confirmedBy
} else if (ContributionStatus.DELETED === dbContribution.contributionStatus) {
this.closedAt = dbContribution.deletedAt
this.closedBy = dbContribution.deletedBy
} else if (ContributionStatus.DENIED === dbContribution.contributionStatus ) {
this.closedAt = dbContribution.deniedAt
this.closedBy = dbContribution.deniedBy
}
}
@Field(() => Date, { nullable: true })
closedAt?: Date | null
@Field(() => Int, { nullable: true })
closedBy?: number | null
@Field(() => String, { nullable: true })
closedByUserName?: string | null
@Field(() => Date)
createdAt: Date
@ -36,27 +57,18 @@ export class Contribution extends UnconfirmedContribution {
@Field(() => Int, { nullable: true })
confirmedBy: number | null
@Field(() => String, { nullable: true })
confirmedByUserName?: string | null
@Field(() => Date, { nullable: true })
deniedAt: Date | null
@Field(() => Int, { nullable: true })
deniedBy: number | null
@Field(() => String, { nullable: true })
deniedByUserName?: string | null
@Field(() => Date, { nullable: true })
deletedAt: Date | null
@Field(() => Int, { nullable: true })
deletedBy: number | null
@Field(() => String, { nullable: true })
deletedByUserName?: string | null
@Field(() => Date, { nullable: true })
updatedAt: Date | null

View File

@ -372,27 +372,24 @@ export class ContributionResolver {
},
countOnly,
)
console.log(dbContributions)
const result = new ContributionListResult(count, dbContributions)
const uniqueUserIds = new Set<number>()
const addIfExist = (userId?: number | null) => (userId ? uniqueUserIds.add(userId) : null)
for (const contribution of result.contributionList) {
addIfExist(contribution.confirmedBy)
addIfExist(contribution.updatedBy)
addIfExist(contribution.moderatorId)
addIfExist(contribution.deletedBy)
addIfExist(contribution.deniedBy)
addIfExist(contribution.closedBy)
}
const users = await findUserNamesByIds(Array.from(uniqueUserIds))
const getNameById = (userId?: number | null) => (userId ? (users.get(userId) ?? null) : null)
for (const contribution of result.contributionList) {
contribution.confirmedByUserName = getNameById(contribution.confirmedBy)
contribution.updatedByUserName = getNameById(contribution.updatedBy)
contribution.moderatorUserName = getNameById(contribution.moderatorId)
contribution.deletedByUserName = getNameById(contribution.deletedBy)
contribution.deniedByUserName = getNameById(contribution.deniedBy)
contribution.closedByUserName = getNameById(contribution.closedBy)
}
return result
}