diff --git a/backend/src/seeds/creation/ContributionInterface.ts b/backend/src/seeds/creation/ContributionInterface.ts new file mode 100644 index 000000000..34ac6be0e --- /dev/null +++ b/backend/src/seeds/creation/ContributionInterface.ts @@ -0,0 +1,10 @@ +export interface ContributionInterface { + startDate: string + endDate: string + name: string + amount: string + memo: string + cycle: string + repetition: string + maxAmount: string +} diff --git a/backend/src/seeds/factory/contribution.ts b/backend/src/seeds/factory/contribution.ts new file mode 100644 index 000000000..63327a971 --- /dev/null +++ b/backend/src/seeds/factory/contribution.ts @@ -0,0 +1,59 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ + +import { createContributionLink } from '@/seeds/graphql/mutations' +// import { User } from '@entity/User' +import { login } from '@/seeds/graphql/queries' +import { ContributionInterface } from '@/seeds/creation/ContributionInterface' +import { ApolloServerTestClient } from 'apollo-server-testing' +import { ContributionLink } from '@/graphql/model/ContributionLink' +// import { ContributionLinks } from '@entity/ContributionLinks' + +// import CONFIG from '@/config/index' + +export const nMonthsBefore = (date: Date, months = 1): string => { + return new Date(date.getFullYear(), date.getMonth() - months, 1).toISOString() +} + +export const contributionFactory = async ( + client: ApolloServerTestClient, + contribution: ContributionInterface, +): Promise => { + const { mutate, query } = client + + await query({ query: login, variables: { email: 'peter@lustig.de', password: 'Aa12345_' } }) + + // let contributionLink: ContributionLink + // TODO it would be nice to have this mutation return the id + const contributionLink = await mutate({ + mutation: createContributionLink, + variables: { ...contribution }, + }) + + // const user = await User.findOneOrFail({ where: { email: creation.email } }) + + /* + if (contribution.linkEnabled) { + await mutate({ mutation: confirmPendingCreation, variables: { id: pendingCreation.id } }) + + if (creation.moveCreationDate) { + const transaction = await Transaction.findOneOrFail({ + where: { userId: user.id, creationDate: new Date(creation.creationDate) }, + order: { balanceDate: 'DESC' }, + }) + if (transaction.decay.equals(0) && transaction.creationDate) { + transaction.creationDate = new Date( + nMonthsBefore(transaction.creationDate, creation.moveCreationDate), + ) + transaction.balanceDate = new Date( + nMonthsBefore(transaction.balanceDate, creation.moveCreationDate), + ) + await transaction.save() + } + } + } else { + return pendingCreation + } + */ + return contributionLink +} diff --git a/backend/src/seeds/graphql/mutations.ts b/backend/src/seeds/graphql/mutations.ts index e66827566..02d20ee2a 100644 --- a/backend/src/seeds/graphql/mutations.ts +++ b/backend/src/seeds/graphql/mutations.ts @@ -137,3 +137,13 @@ export const deletePendingCreation = gql` deletePendingCreation(id: $id) } ` + +export const createContributionLink = gql` + mutation ($pendingCreations: [CreateContributionLinkArgs!]!) { + createContributionLink(pendingCreations: $pendingCreations) { + success + successfulCreation + failedCreation + } + } +`