mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
fix backend tests and lint
This commit is contained in:
parent
bdea98ef94
commit
8feb2a1a22
@ -12,7 +12,7 @@ export class Contribution extends UnconfirmedContribution {
|
||||
this.confirmedAt = contribution.confirmedAt
|
||||
this.confirmedBy = contribution.confirmedBy
|
||||
this.contributionDate = contribution.contributionDate
|
||||
|
||||
|
||||
this.deniedAt = contribution.deniedAt
|
||||
this.deniedBy = contribution.deniedBy
|
||||
this.deletedAt = contribution.deletedAt
|
||||
@ -50,7 +50,7 @@ export class Contribution extends UnconfirmedContribution {
|
||||
updatedBy: number | null
|
||||
|
||||
@Field(() => Date)
|
||||
contributionDate: Date
|
||||
contributionDate: Date
|
||||
|
||||
@Field(() => Date, { nullable: true })
|
||||
resubmissionAt: Date | null
|
||||
|
||||
@ -5,7 +5,7 @@ import { Decimal } from 'decimal.js-light'
|
||||
import { Field, Int, ObjectType } from 'type-graphql'
|
||||
|
||||
import { ContributionMessage } from './ContributionMessage'
|
||||
import { User } from './User'
|
||||
import { User } from './User'
|
||||
|
||||
@ObjectType()
|
||||
export class UnconfirmedContribution {
|
||||
|
||||
@ -86,7 +86,7 @@ describe('ContributionMessageResolver', () => {
|
||||
variables: {
|
||||
amount: 100.0,
|
||||
memo: 'Test env contribution',
|
||||
creationDate: new Date().toString(),
|
||||
contributionDate: new Date().toString(),
|
||||
},
|
||||
})
|
||||
await mutate({
|
||||
@ -139,7 +139,7 @@ describe('ContributionMessageResolver', () => {
|
||||
variables: {
|
||||
amount: 100.0,
|
||||
memo: 'Test env contribution',
|
||||
creationDate: new Date().toString(),
|
||||
contributionDate: new Date().toString(),
|
||||
},
|
||||
})
|
||||
const mutationResult = await mutate({
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -145,11 +145,15 @@ export class ContributionResolver {
|
||||
async listContributions(
|
||||
@Ctx() context: Context,
|
||||
@Arg('pagination') pagination: Paginated,
|
||||
@Arg('messagePagination') messagePagination: Paginated,
|
||||
@Arg('messagePagination', { nullable: true }) messagePagination?: Paginated,
|
||||
): Promise<ContributionListResult> {
|
||||
const user = getUser(context)
|
||||
const [dbContributions, count] = await loadUserContributions(user.id, pagination, messagePagination)
|
||||
|
||||
const [dbContributions, count] = await loadUserContributions(
|
||||
user.id,
|
||||
pagination,
|
||||
messagePagination,
|
||||
)
|
||||
|
||||
// show contributions in progress first
|
||||
const inProgressContributions = dbContributions.filter(
|
||||
(contribution) => contribution.contributionStatus === ContributionStatus.IN_PROGRESS,
|
||||
@ -163,10 +167,10 @@ export class ContributionResolver {
|
||||
[...inProgressContributions, ...notInProgressContributions].map((contribution) => {
|
||||
// we currently expect not much contribution messages for needing pagination
|
||||
// but if we get more than expected, we should get warned
|
||||
if ((contribution.messages?.length || 0) > messagePagination.pageSize) {
|
||||
if ((contribution.messages?.length || 0) > (messagePagination?.pageSize || 10)) {
|
||||
logger.warn('more contribution messages as expected, consider pagination', {
|
||||
contributionId: contribution.id,
|
||||
expected: messagePagination.pageSize,
|
||||
expected: messagePagination?.pageSize || 10,
|
||||
actual: contribution.messages?.length || 0,
|
||||
})
|
||||
}
|
||||
|
||||
@ -467,7 +467,7 @@ describe('TransactionLinkResolver', () => {
|
||||
variables: {
|
||||
amount: new Decimal(1000),
|
||||
memo: 'I was brewing potions for the community the whole month',
|
||||
creationDate: now.toISOString(),
|
||||
contributionDate: now.toISOString(),
|
||||
},
|
||||
})
|
||||
contribution = result.data.createContribution
|
||||
@ -510,7 +510,7 @@ describe('TransactionLinkResolver', () => {
|
||||
contributionId: contribution ? contribution.id : -1,
|
||||
amount: new Decimal(800),
|
||||
memo: 'I was brewing potions for the community the whole month',
|
||||
creationDate: now.toISOString(),
|
||||
contributionDate: now.toISOString(),
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
@ -342,7 +342,7 @@ describe('send coins', () => {
|
||||
// create contribution as user bob
|
||||
const contribution = await mutate({
|
||||
mutation: createContribution,
|
||||
variables: { amount: 1000, memo: 'testing', creationDate: new Date().toISOString() },
|
||||
variables: { amount: 1000, memo: 'testing', contributionDate: new Date().toISOString() },
|
||||
})
|
||||
|
||||
// login as admin
|
||||
|
||||
@ -456,7 +456,11 @@ describe('UserResolver', () => {
|
||||
// create contribution as user bob
|
||||
contribution = await mutate({
|
||||
mutation: createContribution,
|
||||
variables: { amount: 1000, memo: 'testing', creationDate: new Date().toISOString() },
|
||||
variables: {
|
||||
amount: 1000,
|
||||
memo: 'testing',
|
||||
contributionDate: new Date().toISOString(),
|
||||
},
|
||||
})
|
||||
|
||||
// login as admin
|
||||
|
||||
@ -72,14 +72,14 @@ describe('semaphore', () => {
|
||||
email: 'bibi@bloxberg.de',
|
||||
amount: 1000,
|
||||
memo: 'Herzlich Willkommen bei Gradido!',
|
||||
creationDate: nMonthsBefore(new Date()),
|
||||
contributionDate: nMonthsBefore(new Date()),
|
||||
confirmed: true,
|
||||
})
|
||||
await creationFactory(testEnv, {
|
||||
email: 'bob@baumeister.de',
|
||||
amount: 1000,
|
||||
memo: 'Herzlich Willkommen bei Gradido!',
|
||||
creationDate: nMonthsBefore(new Date()),
|
||||
contributionDate: nMonthsBefore(new Date()),
|
||||
confirmed: true,
|
||||
})
|
||||
await mutate({
|
||||
@ -121,7 +121,7 @@ describe('semaphore', () => {
|
||||
} = await mutate({
|
||||
mutation: createContribution,
|
||||
variables: {
|
||||
creationDate: contributionDateFormatter(new Date()),
|
||||
contributionDate: contributionDateFormatter(new Date()),
|
||||
amount: 200,
|
||||
memo: 'Bobs Contribution',
|
||||
},
|
||||
@ -144,7 +144,7 @@ describe('semaphore', () => {
|
||||
} = await mutate({
|
||||
mutation: createContribution,
|
||||
variables: {
|
||||
creationDate: contributionDateFormatter(new Date()),
|
||||
contributionDate: contributionDateFormatter(new Date()),
|
||||
amount: 200,
|
||||
memo: 'Bibis Contribution',
|
||||
},
|
||||
|
||||
@ -98,7 +98,7 @@ describe('util/creation', () => {
|
||||
variables: {
|
||||
amount: 400.0,
|
||||
memo: 'Contribution for this month',
|
||||
creationDate: contributionDateFormatter(now),
|
||||
contributionDate: contributionDateFormatter(now),
|
||||
},
|
||||
})
|
||||
await mutate({
|
||||
@ -106,7 +106,7 @@ describe('util/creation', () => {
|
||||
variables: {
|
||||
amount: 500.0,
|
||||
memo: 'Contribution for the last month',
|
||||
creationDate: contributionDateFormatter(
|
||||
contributionDate: contributionDateFormatter(
|
||||
new Date(now.getFullYear(), now.getMonth() - 1, 1),
|
||||
),
|
||||
},
|
||||
|
||||
@ -73,7 +73,6 @@ export const getUserCreations = async (
|
||||
await sumAmountContributionPerUserAndLast3MonthQuery.getRawMany()
|
||||
|
||||
logger.trace(sumAmountContributionPerUserAndLast3Month)
|
||||
console.log(JSON.stringify(sumAmountContributionPerUserAndLast3Month, null, 2))
|
||||
|
||||
await queryRunner.release()
|
||||
|
||||
|
||||
@ -18,10 +18,10 @@ function buildBaseOptions(paginated: Paginated): FindManyOptions<DbContribution>
|
||||
export const loadUserContributions = async (
|
||||
userId: number,
|
||||
paginated: Paginated,
|
||||
messagePagination: Paginated,
|
||||
messagePagination?: Paginated,
|
||||
): Promise<[DbContribution[], number]> => {
|
||||
const { order } = paginated
|
||||
const { order: messageOrder } = messagePagination
|
||||
const { order: messageOrder } = messagePagination || { order: 'ASC' }
|
||||
return DbContribution.findAndCount({
|
||||
where: { userId },
|
||||
withDeleted: true,
|
||||
@ -41,7 +41,7 @@ export const loadAllContributions = async (
|
||||
const { order } = paginated
|
||||
return DbContribution.findAndCount({
|
||||
relations: { user: { emailContact: true } },
|
||||
order: { createdAt: order, id: order},
|
||||
order: { createdAt: order, id: order },
|
||||
...buildBaseOptions(paginated),
|
||||
})
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ export interface CreationInterface {
|
||||
email: string
|
||||
amount: number
|
||||
memo: string
|
||||
creationDate: string
|
||||
contributionDate: string
|
||||
confirmed?: boolean
|
||||
// number of months to move the confirmed creation to the past
|
||||
moveCreationDate?: number
|
||||
|
||||
@ -122,7 +122,7 @@ bobsSendings.forEach((sending) => {
|
||||
email: 'bob@baumeister.de',
|
||||
amount: sending.amount,
|
||||
memo: sending.memo,
|
||||
creationDate: nMonthsBefore(new Date()),
|
||||
contributionDate: nMonthsBefore(new Date()),
|
||||
confirmed: true,
|
||||
})
|
||||
})
|
||||
@ -132,7 +132,7 @@ export const creations: CreationInterface[] = [
|
||||
email: 'bibi@bloxberg.de',
|
||||
amount: 1000,
|
||||
memo: 'Herzlich Willkommen bei Gradido!',
|
||||
creationDate: nMonthsBefore(new Date()),
|
||||
contributionDate: nMonthsBefore(new Date()),
|
||||
confirmed: true,
|
||||
moveCreationDate: 12,
|
||||
},
|
||||
@ -140,7 +140,7 @@ export const creations: CreationInterface[] = [
|
||||
email: 'bibi@bloxberg.de',
|
||||
amount: 1000,
|
||||
memo: '#Hexen',
|
||||
creationDate: nMonthsBefore(new Date()),
|
||||
contributionDate: nMonthsBefore(new Date()),
|
||||
confirmed: true,
|
||||
moveCreationDate: 12,
|
||||
},
|
||||
@ -149,7 +149,7 @@ export const creations: CreationInterface[] = [
|
||||
email: 'raeuber@hotzenplotz.de',
|
||||
amount: 1000,
|
||||
memo: 'Herzlich Willkommen bei Gradido!',
|
||||
creationDate: nMonthsBefore(new Date()),
|
||||
contributionDate: nMonthsBefore(new Date()),
|
||||
confirmed: true,
|
||||
},
|
||||
]
|
||||
|
||||
@ -34,7 +34,7 @@ export const creationFactory = async (
|
||||
|
||||
if (creation.moveCreationDate) {
|
||||
const transaction = await Transaction.findOneOrFail({
|
||||
where: { userId: user.id, creationDate: new Date(creation.creationDate) },
|
||||
where: { userId: user.id, creationDate: new Date(creation.contributionDate) },
|
||||
order: { balanceDate: 'DESC' },
|
||||
})
|
||||
|
||||
|
||||
@ -265,8 +265,8 @@ export const deleteContributionLink = gql`
|
||||
`
|
||||
|
||||
export const createContribution = gql`
|
||||
mutation ($amount: Decimal!, $memo: String!, $creationDate: String!) {
|
||||
createContribution(amount: $amount, memo: $memo, creationDate: $creationDate) {
|
||||
mutation ($amount: Decimal!, $memo: String!, $contributionDate: String!) {
|
||||
createContribution(amount: $amount, memo: $memo, contributionDate: $contributionDate) {
|
||||
id
|
||||
amount
|
||||
memo
|
||||
@ -276,12 +276,12 @@ export const createContribution = gql`
|
||||
`
|
||||
|
||||
export const updateContribution = gql`
|
||||
mutation ($contributionId: Int!, $amount: Decimal!, $memo: String!, $creationDate: String!) {
|
||||
mutation ($contributionId: Int!, $amount: Decimal!, $memo: String!, $contributionDate: String!) {
|
||||
updateContribution(
|
||||
contributionId: $contributionId
|
||||
amount: $amount
|
||||
memo: $memo
|
||||
creationDate: $creationDate
|
||||
contributionDate: $contributionDate
|
||||
) {
|
||||
id
|
||||
amount
|
||||
|
||||
@ -244,52 +244,47 @@ export const queryTransactionLink = gql`
|
||||
`
|
||||
|
||||
export const listContributions = gql`
|
||||
query (
|
||||
$currentPage: Int = 1
|
||||
$pageSize: Int = 5
|
||||
$order: Order
|
||||
$statusFilter: [ContributionStatus!]
|
||||
) {
|
||||
listContributions(
|
||||
currentPage: $currentPage
|
||||
pageSize: $pageSize
|
||||
order: $order
|
||||
statusFilter: $statusFilter
|
||||
) {
|
||||
query ($pagination: Paginated!) {
|
||||
listContributions(pagination: $pagination) {
|
||||
contributionCount
|
||||
contributionList {
|
||||
id
|
||||
amount
|
||||
memo
|
||||
createdAt
|
||||
contributionDate
|
||||
contributionStatus
|
||||
messagesCount
|
||||
createdAt
|
||||
confirmedAt
|
||||
confirmedBy
|
||||
deletedAt
|
||||
status
|
||||
messagesCount
|
||||
deniedAt
|
||||
deniedBy
|
||||
updatedBy
|
||||
updatedAt
|
||||
deletedAt
|
||||
moderatorId
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
export const listAllContributions = `
|
||||
query ($currentPage: Int = 1, $pageSize: Int = 5, $order: Order = DESC, $statusFilter: [ContributionStatus!]) {
|
||||
listAllContributions(currentPage: $currentPage, pageSize: $pageSize, order: $order, statusFilter: $statusFilter) {
|
||||
query ($pagination: Paginated!) {
|
||||
listAllContributions(pagination: $pagination) {
|
||||
contributionCount
|
||||
contributionList {
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
user {
|
||||
firstName
|
||||
lastName
|
||||
}
|
||||
amount
|
||||
memo
|
||||
createdAt
|
||||
confirmedAt
|
||||
confirmedBy
|
||||
contributionDate
|
||||
status
|
||||
contributionStatus
|
||||
messagesCount
|
||||
deniedAt
|
||||
deniedBy
|
||||
@ -318,7 +313,7 @@ export const adminListContributions = gql`
|
||||
confirmedAt
|
||||
confirmedBy
|
||||
contributionDate
|
||||
status
|
||||
contributionStatus
|
||||
messagesCount
|
||||
deniedAt
|
||||
deniedBy
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user