mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
Finish denie logic, add deniedAt IsNull() to queries.
This commit is contained in:
parent
dabef05dc0
commit
853bfabd57
@ -18,6 +18,8 @@ export class Contribution {
|
|||||||
this.contributionDate = contribution.contributionDate
|
this.contributionDate = contribution.contributionDate
|
||||||
this.state = contribution.contributionStatus
|
this.state = contribution.contributionStatus
|
||||||
this.messagesCount = contribution.messages ? contribution.messages.length : 0
|
this.messagesCount = contribution.messages ? contribution.messages.length : 0
|
||||||
|
this.deniedAt = contribution.deniedAt
|
||||||
|
this.deniedBy = contribution.deniedBy
|
||||||
}
|
}
|
||||||
|
|
||||||
@Field(() => Number)
|
@Field(() => Number)
|
||||||
@ -47,6 +49,12 @@ export class Contribution {
|
|||||||
@Field(() => Number, { nullable: true })
|
@Field(() => Number, { nullable: true })
|
||||||
confirmedBy: number | null
|
confirmedBy: number | null
|
||||||
|
|
||||||
|
@Field(() => Date, { nullable: true })
|
||||||
|
deniedAt: Date | null
|
||||||
|
|
||||||
|
@Field(() => Number, { nullable: true })
|
||||||
|
deniedBy: number | null
|
||||||
|
|
||||||
@Field(() => Date)
|
@Field(() => Date)
|
||||||
contributionDate: Date
|
contributionDate: Date
|
||||||
|
|
||||||
|
|||||||
@ -146,6 +146,7 @@ export class ContributionResolver {
|
|||||||
@Ctx() context: Context,
|
@Ctx() context: Context,
|
||||||
): Promise<ContributionListResult> {
|
): Promise<ContributionListResult> {
|
||||||
const user = getUser(context)
|
const user = getUser(context)
|
||||||
|
// TODO: Check if deniedAt IsNull()
|
||||||
const where: {
|
const where: {
|
||||||
userId: number
|
userId: number
|
||||||
confirmedBy?: FindOperator<number> | null
|
confirmedBy?: FindOperator<number> | null
|
||||||
@ -214,7 +215,7 @@ export class ContributionResolver {
|
|||||||
const user = getUser(context)
|
const user = getUser(context)
|
||||||
|
|
||||||
const contributionToUpdate = await DbContribution.findOne({
|
const contributionToUpdate = await DbContribution.findOne({
|
||||||
where: { id: contributionId, confirmedAt: IsNull() },
|
where: { id: contributionId, confirmedAt: IsNull(), deniedAt: IsNull() },
|
||||||
})
|
})
|
||||||
if (!contributionToUpdate) {
|
if (!contributionToUpdate) {
|
||||||
logger.error('No contribution found to given id')
|
logger.error('No contribution found to given id')
|
||||||
@ -406,7 +407,7 @@ export class ContributionResolver {
|
|||||||
const moderator = getUser(context)
|
const moderator = getUser(context)
|
||||||
|
|
||||||
const contributionToUpdate = await DbContribution.findOne({
|
const contributionToUpdate = await DbContribution.findOne({
|
||||||
where: { id, confirmedAt: IsNull() },
|
where: { id, confirmedAt: IsNull(), deniedAt: IsNull() },
|
||||||
})
|
})
|
||||||
if (!contributionToUpdate) {
|
if (!contributionToUpdate) {
|
||||||
logger.error('No contribution found to given id.')
|
logger.error('No contribution found to given id.')
|
||||||
@ -472,6 +473,7 @@ export class ContributionResolver {
|
|||||||
.from(DbContribution, 'c')
|
.from(DbContribution, 'c')
|
||||||
.leftJoinAndSelect('c.messages', 'm')
|
.leftJoinAndSelect('c.messages', 'm')
|
||||||
.where({ confirmedAt: IsNull() })
|
.where({ confirmedAt: IsNull() })
|
||||||
|
.andWhere({ deniedAt: IsNull() })
|
||||||
.getMany()
|
.getMany()
|
||||||
|
|
||||||
if (contributions.length === 0) {
|
if (contributions.length === 0) {
|
||||||
@ -686,9 +688,29 @@ export class ContributionResolver {
|
|||||||
@Arg('id', () => Int) id: number,
|
@Arg('id', () => Int) id: number,
|
||||||
@Ctx() context: Context,
|
@Ctx() context: Context,
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const moderatorUser = getUser(context)
|
|
||||||
|
|
||||||
const contributionToUpdate = await DbContribution.findOne({ id })
|
const contributionToUpdate = await DbContribution.findOne({ id })
|
||||||
|
// TODO: Check
|
||||||
|
// - contribution exists
|
||||||
|
// - state has accept one
|
||||||
|
if (!contributionToUpdate) {
|
||||||
|
logger.error(`Contribution not found for given id: ${id}`)
|
||||||
|
throw new Error(`Contribution not found for given id.`)
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
contributionToUpdate.contributionStatus !== ContributionStatus.IN_PROGRESS &&
|
||||||
|
contributionToUpdate.contributionStatus !== ContributionStatus.PENDING
|
||||||
|
) {
|
||||||
|
logger.error(
|
||||||
|
`Contribution state (${contributionToUpdate.contributionStatus}) is not allowed.`,
|
||||||
|
)
|
||||||
|
throw new Error(`State of the contribution is not allowed.`)
|
||||||
|
}
|
||||||
|
const user = getUser(context)
|
||||||
|
|
||||||
|
contributionToUpdate.contributionStatus = ContributionStatus.DENIED
|
||||||
|
contributionToUpdate.deniedBy = user.id
|
||||||
|
contributionToUpdate.deniedAt = new Date()
|
||||||
|
await contributionToUpdate.save()
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user