From 5456e6dae4e3eaf33aa6290b46419588bd3fb90c Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 13 Jun 2022 13:19:03 +0200 Subject: [PATCH 01/17] add ContributionLink graphQL model --- backend/src/graphql/model/ContributionLink.ts | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 backend/src/graphql/model/ContributionLink.ts diff --git a/backend/src/graphql/model/ContributionLink.ts b/backend/src/graphql/model/ContributionLink.ts new file mode 100644 index 000000000..b60df37e2 --- /dev/null +++ b/backend/src/graphql/model/ContributionLink.ts @@ -0,0 +1,56 @@ +import { ObjectType, Field, Int } from 'type-graphql' +import Decimal from 'decimal.js-light' +import { ContributionLink as dbContributionLink } from '@entity/ContributionLink' + +@ObjectType() +export class ContributionLink { + constructor(contributionLink: dbContributionLink) { + this.id = contributionLink.id + this.amount = contributionLink.amount + this.name = contributionLink.name + this.memo = contributionLink.memo + this.createdAt = contributionLink.createdAt + this.deletedAt = contributionLink.deletedAt + this.validFrom = contributionLink.validFrom + this.validTo = contributionLink.validTo + this.maxAmountPerMonth = contributionLink.maxAmountPerMonth + this.cycle = contributionLink.cycle + this.maxPerCycle = contributionLink.maxPerCycle + } + + @Field(() => Number) + id: number + + @Field(() => Decimal) + amount: Decimal + + @Field(() => String) + name: string + + @Field(() => String) + memo: string + + @Field(() => String) + code: string + + @Field(() => Date) + createdAt: Date + + @Field(() => Date, { nullable: true }) + deletedAt: Date | null + + @Field(() => Date, { nullable: true }) + validFrom: Date | null + + @Field(() => Date, { nullable: true }) + validTo: Date | null + + @Field(() => Decimal) + maxAmountPerMonth: Decimal | null + + @Field(() => string) + cycle: string + + @Field(() => Int) + maxPerCycle: number +} From bd593e96ae3d4acb6ff3285d40b91e0ad607d373 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 14 Jun 2022 09:23:51 +0200 Subject: [PATCH 02/17] roles and args for contribution links --- backend/src/auth/RIGHTS.ts | 1 + .../src/graphql/arg/ContributionLinkArgs.ts | 29 +++++++++++++++++++ backend/src/graphql/model/ContributionLink.ts | 2 +- backend/src/graphql/resolver/AdminResolver.ts | 11 +++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 backend/src/graphql/arg/ContributionLinkArgs.ts diff --git a/backend/src/auth/RIGHTS.ts b/backend/src/auth/RIGHTS.ts index 8188b3daa..dcd0e44d6 100644 --- a/backend/src/auth/RIGHTS.ts +++ b/backend/src/auth/RIGHTS.ts @@ -37,4 +37,5 @@ export enum RIGHTS { UNDELETE_USER = 'UNDELETE_USER', CREATION_TRANSACTION_LIST = 'CREATION_TRANSACTION_LIST', LIST_TRANSACTION_LINKS_ADMIN = 'LIST_TRANSACTION_LINKS_ADMIN', + CREATE_CONTRIBUTION_LINK = 'CREATE_CONTRIBUTION_LINK', } diff --git a/backend/src/graphql/arg/ContributionLinkArgs.ts b/backend/src/graphql/arg/ContributionLinkArgs.ts new file mode 100644 index 000000000..f3d3f91df --- /dev/null +++ b/backend/src/graphql/arg/ContributionLinkArgs.ts @@ -0,0 +1,29 @@ +import { ArgsType, Field, Int } from 'type-graphql' +import Decimal from 'decimal.js-light' + +@ArgsType() +export default class ContributionLinkArgs { + @Field(() => Decimal) + amount: Decimal + + @Field(() => String) + name: string + + @Field(() => String) + memo: string + + @Field(() => String) + cycle: string + + @Field(() => Date, { nullable: true }) + validFrom?: Date | null + + @Field(() => Date, { nullable: true }) + validTo?: Date | null + + @Field(() => Decimal, { nullable: true }) + maxAmountPerMonth: Decimal | null + + @Field(() => Int, { default: 1 }) + maxPerCycle: number +} diff --git a/backend/src/graphql/model/ContributionLink.ts b/backend/src/graphql/model/ContributionLink.ts index b60df37e2..df28bb0e5 100644 --- a/backend/src/graphql/model/ContributionLink.ts +++ b/backend/src/graphql/model/ContributionLink.ts @@ -45,7 +45,7 @@ export class ContributionLink { @Field(() => Date, { nullable: true }) validTo: Date | null - @Field(() => Decimal) + @Field(() => Decimal, { nullable: true }) maxAmountPerMonth: Decimal | null @Field(() => string) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 4c94e48c8..d9945a617 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -14,12 +14,15 @@ import { UserAdmin, SearchUsersResult } from '@model/UserAdmin' import { PendingCreation } from '@model/PendingCreation' import { CreatePendingCreations } from '@model/CreatePendingCreations' import { UpdatePendingCreation } from '@model/UpdatePendingCreation' +import { ContributionLink } from '@model/ContributionLink' import { RIGHTS } from '@/auth/RIGHTS' import { UserRepository } from '@repository/User' import CreatePendingCreationArgs from '@arg/CreatePendingCreationArgs' import UpdatePendingCreationArgs from '@arg/UpdatePendingCreationArgs' import SearchUsersArgs from '@arg/SearchUsersArgs' +import ContributionLinkArgs from '@arg/ContributionLinkArgs' import { Transaction as DbTransaction } from '@entity/Transaction' +import { ContributionLink as DbContributionLink } from '@entity/ContributionLink' import { Transaction } from '@model/Transaction' import { TransactionLink, TransactionLinkResult } from '@model/TransactionLink' import { TransactionLink as dbTransactionLink } from '@entity/TransactionLink' @@ -460,6 +463,14 @@ export class AdminResolver { linkList: transactionLinks.map((tl) => new TransactionLink(tl, new User(user))), } } + + @Authorized([RIGHTS.CREATE_CONTRIBUTION_LINK]) + @Mutation(() => ContributionLink) + async createContributionLink( + @Args() + { amount, name, memo, cycle, validFrom, validTo, maxAmountPerMonth, maxPerCycle }: ContributionLinkArgs, + ) + } interface CreationMap { From 1e0b246252b426db52d4ff19c7b0a7e5ee9b26d1 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 14 Jun 2022 09:44:37 +0200 Subject: [PATCH 03/17] simple createContributionLink mutation --- .../src/graphql/arg/ContributionLinkArgs.ts | 2 +- backend/src/graphql/model/ContributionLink.ts | 2 +- backend/src/graphql/resolver/AdminResolver.ts | 27 ++++++++++++++++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/backend/src/graphql/arg/ContributionLinkArgs.ts b/backend/src/graphql/arg/ContributionLinkArgs.ts index f3d3f91df..809ce89c4 100644 --- a/backend/src/graphql/arg/ContributionLinkArgs.ts +++ b/backend/src/graphql/arg/ContributionLinkArgs.ts @@ -24,6 +24,6 @@ export default class ContributionLinkArgs { @Field(() => Decimal, { nullable: true }) maxAmountPerMonth: Decimal | null - @Field(() => Int, { default: 1 }) + @Field(() => Int) maxPerCycle: number } diff --git a/backend/src/graphql/model/ContributionLink.ts b/backend/src/graphql/model/ContributionLink.ts index df28bb0e5..9fb60e4aa 100644 --- a/backend/src/graphql/model/ContributionLink.ts +++ b/backend/src/graphql/model/ContributionLink.ts @@ -48,7 +48,7 @@ export class ContributionLink { @Field(() => Decimal, { nullable: true }) maxAmountPerMonth: Decimal | null - @Field(() => string) + @Field(() => String) cycle: string @Field(() => Int) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index d9945a617..d99bf6c6f 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -468,9 +468,30 @@ export class AdminResolver { @Mutation(() => ContributionLink) async createContributionLink( @Args() - { amount, name, memo, cycle, validFrom, validTo, maxAmountPerMonth, maxPerCycle }: ContributionLinkArgs, - ) - + { + amount, + name, + memo, + cycle, + validFrom, + validTo, + maxAmountPerMonth, + maxPerCycle, + }: ContributionLinkArgs, + ): Promise { + const dbContributionLink = new DbContributionLink() + dbContributionLink.amount = amount + dbContributionLink.name = name + dbContributionLink.memo = memo + dbContributionLink.createdAt = new Date() + dbContributionLink.cycle = cycle + if (validFrom) dbContributionLink.validFrom = validFrom + if (validTo) dbContributionLink.validTo = validTo + dbContributionLink.maxAmountPerMonth = maxAmountPerMonth + dbContributionLink.maxPerCycle = maxPerCycle + dbContributionLink.save() + return new ContributionLink(dbContributionLink) + } } interface CreationMap { From f258f63ee74f3535a661f1e5e8c57e890eb89f08 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 14 Jun 2022 10:43:03 +0200 Subject: [PATCH 04/17] test createContributionLink --- .../src/graphql/arg/ContributionLinkArgs.ts | 8 +- backend/src/graphql/model/ContributionLink.ts | 6 + .../graphql/resolver/AdminResolver.test.ts | 118 ++++++++++++++++++ backend/src/graphql/resolver/AdminResolver.ts | 6 +- backend/src/seeds/graphql/mutations.ts | 36 ++++++ 5 files changed, 168 insertions(+), 6 deletions(-) diff --git a/backend/src/graphql/arg/ContributionLinkArgs.ts b/backend/src/graphql/arg/ContributionLinkArgs.ts index 809ce89c4..7344a28ff 100644 --- a/backend/src/graphql/arg/ContributionLinkArgs.ts +++ b/backend/src/graphql/arg/ContributionLinkArgs.ts @@ -15,11 +15,11 @@ export default class ContributionLinkArgs { @Field(() => String) cycle: string - @Field(() => Date, { nullable: true }) - validFrom?: Date | null + @Field(() => String, { nullable: true }) + validFrom?: string | null - @Field(() => Date, { nullable: true }) - validTo?: Date | null + @Field(() => String, { nullable: true }) + validTo?: string | null @Field(() => Decimal, { nullable: true }) maxAmountPerMonth: Decimal | null diff --git a/backend/src/graphql/model/ContributionLink.ts b/backend/src/graphql/model/ContributionLink.ts index 9fb60e4aa..e4b37ad59 100644 --- a/backend/src/graphql/model/ContributionLink.ts +++ b/backend/src/graphql/model/ContributionLink.ts @@ -1,6 +1,7 @@ import { ObjectType, Field, Int } from 'type-graphql' import Decimal from 'decimal.js-light' import { ContributionLink as dbContributionLink } from '@entity/ContributionLink' +import CONFIG from '@/config' @ObjectType() export class ContributionLink { @@ -16,6 +17,8 @@ export class ContributionLink { this.maxAmountPerMonth = contributionLink.maxAmountPerMonth this.cycle = contributionLink.cycle this.maxPerCycle = contributionLink.maxPerCycle + this.code = 'CL-' + contributionLink.code + this.link = CONFIG.COMMUNITY_REDEEM_URL.replace(/{code}/g, this.code) } @Field(() => Number) @@ -33,6 +36,9 @@ export class ContributionLink { @Field(() => String) code: string + @Field(() => String) + link: string + @Field(() => Date) createdAt: Date diff --git a/backend/src/graphql/resolver/AdminResolver.test.ts b/backend/src/graphql/resolver/AdminResolver.test.ts index acf880efb..6b0f295c7 100644 --- a/backend/src/graphql/resolver/AdminResolver.test.ts +++ b/backend/src/graphql/resolver/AdminResolver.test.ts @@ -20,6 +20,7 @@ import { updatePendingCreation, deletePendingCreation, confirmPendingCreation, + createContributionLink, } from '@/seeds/graphql/mutations' import { getPendingCreations, @@ -34,6 +35,7 @@ import { sendAccountActivationEmail } from '@/mailer/sendAccountActivationEmail' import Decimal from 'decimal.js-light' import { AdminPendingCreation } from '@entity/AdminPendingCreation' import { Transaction as DbTransaction } from '@entity/Transaction' +import { ContributionLink as DbContributionLink } from '@entity/ContributionLink' // mock account activation email to avoid console spam jest.mock('@/mailer/sendAccountActivationEmail', () => { @@ -1593,4 +1595,120 @@ describe('AdminResolver', () => { }) }) }) + + describe('Contribution Links', () => { + const variables = { + amount: new Decimal(200), + name: 'Dokumenta 2022', + memo: 'Danke für deine Teilnahme an der Dokumenta 2022', + cycle: 'once', + validFrom: new Date(2022, 5, 18).toISOString(), + validTo: new Date(2022, 7, 14).toISOString(), + maxAmountPerMonth: new Decimal(200), + maxPerCycle: 1, + } + + describe('unauthenticated', () => { + describe('createContributionLink', () => { + it.only('returns an error', async () => { + await expect(mutate({ mutation: createContributionLink, variables })).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('401 Unauthorized')], + }), + ) + }) + }) + }) + + describe('authenticated', () => { + describe('without admin rights', () => { + beforeAll(async () => { + user = await userFactory(testEnv, bibiBloxberg) + await query({ + query: login, + variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, + }) + }) + + afterAll(async () => { + await cleanDB() + resetToken() + }) + + describe('createContributionLink', () => { + it.only('returns an error', async () => { + await expect(mutate({ mutation: createContributionLink, variables })).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('401 Unauthorized')], + }), + ) + }) + }) + }) + + describe('with admin rights', () => { + beforeAll(async () => { + user = await userFactory(testEnv, peterLustig) + await query({ + query: login, + variables: { email: 'peter@lustig.de', password: 'Aa12345_' }, + }) + }) + + afterAll(async () => { + await cleanDB() + resetToken() + }) + + describe('createContributionLink', () => { + it.only('returns a contribution link object', async () => { + await expect(mutate({ mutation: createContributionLink, variables })).resolves.toEqual( + expect.objectContaining({ + data: { + createContributionLink: expect.objectContaining({ + amount: '200', + code: expect.stringMatching(/^CL-[0-9a-f]{24,24}$/), + link: expect.any(String), + createdAt: expect.any(String), + name: 'Dokumenta 2022', + memo: 'Danke für deine Teilnahme an der Dokumenta 2022', + validFrom: expect.any(String), + validTo: expect.any(String), + maxAmountPerMonth: '200', + cycle: 'once', + maxPerCycle: 1, + }), + }, + }), + ) + }) + + it.only('has a contribution link stored in db', async () => { + const cls = await DbContributionLink.find() + expect(cls).toHaveLength(1) + expect(cls[0]).toEqual( + expect.objectContaining({ + id: expect.any(Number), + name: 'Dokumenta 2022', + memo: 'Danke für deine Teilnahme an der Dokumenta 2022', + validFrom: new Date('2022-06-18T00:00:00.000Z'), + validTo: new Date('2022-08-14T00:00:00.000Z'), + cycle: 'once', + maxPerCycle: 1, + totalMaxCountOfContribution: null, + maxAccountBalance: null, + minGapHours: null, + createdAt: expect.any(Date), + deletedAt: null, + code: expect.stringMatching(/^[0-9a-f]{24,24}$/), + linkEnabled: true, + // amount: '200', + // maxAmountPerMonth: '200', + }), + ) + }) + }) + }) + }) + }) }) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index d99bf6c6f..d7c843611 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -42,6 +42,7 @@ import { Order } from '@enum/Order' import { communityUser } from '@/util/communityUser' import { checkOptInCode, activationLink, printTimeDuration } from './UserResolver' import { sendAccountActivationEmail } from '@/mailer/sendAccountActivationEmail' +import { transactionLinkCode as contributionLinkCode } from './TransactionLinkResolver' import CONFIG from '@/config' // const EMAIL_OPT_IN_REGISTER = 1 @@ -484,9 +485,10 @@ export class AdminResolver { dbContributionLink.name = name dbContributionLink.memo = memo dbContributionLink.createdAt = new Date() + dbContributionLink.code = contributionLinkCode(dbContributionLink.createdAt) dbContributionLink.cycle = cycle - if (validFrom) dbContributionLink.validFrom = validFrom - if (validTo) dbContributionLink.validTo = validTo + if (validFrom) dbContributionLink.validFrom = new Date(validFrom) + if (validTo) dbContributionLink.validTo = new Date(validTo) dbContributionLink.maxAmountPerMonth = maxAmountPerMonth dbContributionLink.maxPerCycle = maxPerCycle dbContributionLink.save() diff --git a/backend/src/seeds/graphql/mutations.ts b/backend/src/seeds/graphql/mutations.ts index e66827566..355b5aa79 100644 --- a/backend/src/seeds/graphql/mutations.ts +++ b/backend/src/seeds/graphql/mutations.ts @@ -137,3 +137,39 @@ export const deletePendingCreation = gql` deletePendingCreation(id: $id) } ` + +export const createContributionLink = gql` + mutation ( + $amount: Decimal! + $name: String! + $memo: String! + $cycle: String! + $validFrom: String + $validTo: String + $maxAmountPerMonth: Decimal + $maxPerCycle: Int! = 1 + ) { + createContributionLink( + amount: $amount + name: $name + memo: $memo + cycle: $cycle + validFrom: $validFrom + validTo: $validTo + maxAmountPerMonth: $maxAmountPerMonth + maxPerCycle: $maxPerCycle + ) { + amount + name + memo + code + link + createdAt + validFrom + validTo + maxAmountPerMonth + cycle + maxPerCycle + } + } +` From e1a84eb52e0313247b8185a7a69b5da23b11b090 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 14 Jun 2022 10:45:10 +0200 Subject: [PATCH 05/17] add enum cycle type for contribution links --- .../src/graphql/enum/ContributionCycleType.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 backend/src/graphql/enum/ContributionCycleType.ts diff --git a/backend/src/graphql/enum/ContributionCycleType.ts b/backend/src/graphql/enum/ContributionCycleType.ts new file mode 100644 index 000000000..5fe494a02 --- /dev/null +++ b/backend/src/graphql/enum/ContributionCycleType.ts @@ -0,0 +1,28 @@ +import { registerEnumType } from 'type-graphql' + +export enum ContributionCycleType { + ONCE = 'once', + HOUR = 'hour', + TWO_HOURS = 'two_hours', + FOUR_HOURS = 'four_hours', + EIGHT_HOURS = 'eight_hours', + HALF_DAY = 'half_day', + DAY = 'day', + TWO_DAYS = 'two_days', + THREE_DAYS = 'three_days', + FOUR_DAYS = 'four_days', + FIVE_DAYS = 'five_days', + SIX_DAYS = 'six_days', + WEEK = 'week', + TWO_WEEKS = 'two_weeks', + MONTH = 'month', + TWO_MONTH = 'two_month', + QUARTER = 'quarter', + HALF_YEAR = 'half_year', + YEAR = 'year', +} + +registerEnumType(ContributionCycleType, { + name: 'ContributionCycleType', // this one is mandatory + description: 'Name of the Type of the ContributionCycle', // this one is optional +}) From fd2f6a16b7b22cc61d8a7778728bc61f155443c5 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 14 Jun 2022 12:10:16 +0200 Subject: [PATCH 06/17] lsit contribution links query --- backend/src/auth/RIGHTS.ts | 1 + .../src/graphql/model/ContributionLinkList.ts | 11 ++++ .../graphql/resolver/AdminResolver.test.ts | 52 +++++++++++++++++++ backend/src/graphql/resolver/AdminResolver.ts | 18 +++++++ backend/src/seeds/graphql/queries.ts | 22 ++++++++ 5 files changed, 104 insertions(+) create mode 100644 backend/src/graphql/model/ContributionLinkList.ts diff --git a/backend/src/auth/RIGHTS.ts b/backend/src/auth/RIGHTS.ts index dcd0e44d6..a9270cd36 100644 --- a/backend/src/auth/RIGHTS.ts +++ b/backend/src/auth/RIGHTS.ts @@ -38,4 +38,5 @@ export enum RIGHTS { CREATION_TRANSACTION_LIST = 'CREATION_TRANSACTION_LIST', LIST_TRANSACTION_LINKS_ADMIN = 'LIST_TRANSACTION_LINKS_ADMIN', CREATE_CONTRIBUTION_LINK = 'CREATE_CONTRIBUTION_LINK', + LIST_CONTRIBUTION_LINKS = 'LIST_CONTRIBUTION_LINKS', } diff --git a/backend/src/graphql/model/ContributionLinkList.ts b/backend/src/graphql/model/ContributionLinkList.ts new file mode 100644 index 000000000..412d0bf7b --- /dev/null +++ b/backend/src/graphql/model/ContributionLinkList.ts @@ -0,0 +1,11 @@ +import { ObjectType, Field } from 'type-graphql' +import { ContributionLink } from '@model/ContributionLink' + +@ObjectType() +export class ContributionLinkList { + @Field(() => [ContributionLink]) + links: ContributionLink[] + + @Field(() => Number) + count: number +} diff --git a/backend/src/graphql/resolver/AdminResolver.test.ts b/backend/src/graphql/resolver/AdminResolver.test.ts index 6b0f295c7..8e700ce9b 100644 --- a/backend/src/graphql/resolver/AdminResolver.test.ts +++ b/backend/src/graphql/resolver/AdminResolver.test.ts @@ -27,6 +27,7 @@ import { login, searchUsers, listTransactionLinksAdmin, + listContributionLinks, } from '@/seeds/graphql/queries' import { GraphQLError } from 'graphql' import { User } from '@entity/User' @@ -1618,6 +1619,16 @@ describe('AdminResolver', () => { ) }) }) + + describe('listContributionLinks', () => { + it.only('returns an error', async () => { + await expect(query({ query: listContributionLinks })).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('401 Unauthorized')], + }), + ) + }) + }) }) describe('authenticated', () => { @@ -1644,6 +1655,16 @@ describe('AdminResolver', () => { ) }) }) + + describe('listContributionLinks', () => { + it.only('returns an error', async () => { + await expect(query({ query: listContributionLinks })).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('401 Unauthorized')], + }), + ) + }) + }) }) describe('with admin rights', () => { @@ -1708,6 +1729,37 @@ describe('AdminResolver', () => { ) }) }) + + describe('listContributionLinks', () => { + describe('one link in DB', () => { + it.only('returns the link and count 1', async () => { + await expect(query({ query: listContributionLinks })).resolves.toEqual( + expect.objectContaining({ + data: { + listContributionLinks: { + links: expect.arrayContaining([ + expect.objectContaining({ + amount: '200', + code: expect.stringMatching(/^CL-[0-9a-f]{24,24}$/), + link: expect.any(String), + createdAt: expect.any(String), + name: 'Dokumenta 2022', + memo: 'Danke für deine Teilnahme an der Dokumenta 2022', + validFrom: expect.any(String), + validTo: expect.any(String), + maxAmountPerMonth: '200', + cycle: 'once', + maxPerCycle: 1, + }), + ]), + count: 1, + }, + }, + }), + ) + }) + }) + }) }) }) }) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index d7c843611..e13a013b6 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -15,6 +15,7 @@ import { PendingCreation } from '@model/PendingCreation' import { CreatePendingCreations } from '@model/CreatePendingCreations' import { UpdatePendingCreation } from '@model/UpdatePendingCreation' import { ContributionLink } from '@model/ContributionLink' +import { ContributionLinkList } from '@model/ContributionLinkList' import { RIGHTS } from '@/auth/RIGHTS' import { UserRepository } from '@repository/User' import CreatePendingCreationArgs from '@arg/CreatePendingCreationArgs' @@ -494,6 +495,23 @@ export class AdminResolver { dbContributionLink.save() return new ContributionLink(dbContributionLink) } + + @Authorized([RIGHTS.LIST_CONTRIBUTION_LINKS]) + @Query(() => ContributionLinkList) + async listContributionLinks( + @Args() + { currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated, + ): Promise { + const [links, count] = await DbContributionLink.findAndCount({ + order: { createdAt: order }, + skip: (currentPage - 1) * pageSize, + take: pageSize, + }) + return { + links: links.map((link: DbContributionLink) => new ContributionLink(link)), + count, + } + } } interface CreationMap { diff --git a/backend/src/seeds/graphql/queries.ts b/backend/src/seeds/graphql/queries.ts index 03ee3b53e..9a0e00be3 100644 --- a/backend/src/seeds/graphql/queries.ts +++ b/backend/src/seeds/graphql/queries.ts @@ -217,3 +217,25 @@ export const listTransactionLinksAdmin = gql` } } ` + +export const listContributionLinks = gql` + query ($pageSize: Int = 25, $currentPage: Int = 1, $order: Order) { + listContributionLinks(pageSize: $pageSize, currentPage: $currentPage, order: $order) { + links { + id + amount + name + memo + code + link + createdAt + validFrom + validTo + maxAmountPerMonth + cycle + maxPerCycle + } + count + } + } +` From 8ba0a4af7c27c3d4fef0c54b452fa58bef9943e9 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 14 Jun 2022 12:11:43 +0200 Subject: [PATCH 07/17] no only in admin resolver tests --- backend/src/graphql/resolver/AdminResolver.test.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.test.ts b/backend/src/graphql/resolver/AdminResolver.test.ts index 8e700ce9b..362a5b90b 100644 --- a/backend/src/graphql/resolver/AdminResolver.test.ts +++ b/backend/src/graphql/resolver/AdminResolver.test.ts @@ -1611,7 +1611,7 @@ describe('AdminResolver', () => { describe('unauthenticated', () => { describe('createContributionLink', () => { - it.only('returns an error', async () => { + it('returns an error', async () => { await expect(mutate({ mutation: createContributionLink, variables })).resolves.toEqual( expect.objectContaining({ errors: [new GraphQLError('401 Unauthorized')], @@ -1621,7 +1621,7 @@ describe('AdminResolver', () => { }) describe('listContributionLinks', () => { - it.only('returns an error', async () => { + it('returns an error', async () => { await expect(query({ query: listContributionLinks })).resolves.toEqual( expect.objectContaining({ errors: [new GraphQLError('401 Unauthorized')], @@ -1647,7 +1647,7 @@ describe('AdminResolver', () => { }) describe('createContributionLink', () => { - it.only('returns an error', async () => { + it('returns an error', async () => { await expect(mutate({ mutation: createContributionLink, variables })).resolves.toEqual( expect.objectContaining({ errors: [new GraphQLError('401 Unauthorized')], @@ -1657,7 +1657,7 @@ describe('AdminResolver', () => { }) describe('listContributionLinks', () => { - it.only('returns an error', async () => { + it('returns an error', async () => { await expect(query({ query: listContributionLinks })).resolves.toEqual( expect.objectContaining({ errors: [new GraphQLError('401 Unauthorized')], @@ -1682,7 +1682,7 @@ describe('AdminResolver', () => { }) describe('createContributionLink', () => { - it.only('returns a contribution link object', async () => { + it('returns a contribution link object', async () => { await expect(mutate({ mutation: createContributionLink, variables })).resolves.toEqual( expect.objectContaining({ data: { @@ -1704,7 +1704,7 @@ describe('AdminResolver', () => { ) }) - it.only('has a contribution link stored in db', async () => { + it('has a contribution link stored in db', async () => { const cls = await DbContributionLink.find() expect(cls).toHaveLength(1) expect(cls[0]).toEqual( @@ -1732,7 +1732,7 @@ describe('AdminResolver', () => { describe('listContributionLinks', () => { describe('one link in DB', () => { - it.only('returns the link and count 1', async () => { + it('returns the link and count 1', async () => { await expect(query({ query: listContributionLinks })).resolves.toEqual( expect.objectContaining({ data: { From fa30b871b71e848c624226e1477a5d6e2b27b02e Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 14 Jun 2022 13:12:41 +0200 Subject: [PATCH 08/17] delete contribution link mutation --- backend/src/auth/RIGHTS.ts | 1 + .../graphql/resolver/AdminResolver.test.ts | 72 +++++++++++++++++++ backend/src/graphql/resolver/AdminResolver.ts | 16 ++++- backend/src/seeds/graphql/mutations.ts | 6 ++ 4 files changed, 94 insertions(+), 1 deletion(-) diff --git a/backend/src/auth/RIGHTS.ts b/backend/src/auth/RIGHTS.ts index a9270cd36..f8fa38616 100644 --- a/backend/src/auth/RIGHTS.ts +++ b/backend/src/auth/RIGHTS.ts @@ -39,4 +39,5 @@ export enum RIGHTS { LIST_TRANSACTION_LINKS_ADMIN = 'LIST_TRANSACTION_LINKS_ADMIN', CREATE_CONTRIBUTION_LINK = 'CREATE_CONTRIBUTION_LINK', LIST_CONTRIBUTION_LINKS = 'LIST_CONTRIBUTION_LINKS', + DELETE_CONTRIBUTION_LINK = 'DELETE_CONTRIBUTION_LINK', } diff --git a/backend/src/graphql/resolver/AdminResolver.test.ts b/backend/src/graphql/resolver/AdminResolver.test.ts index 362a5b90b..32227f257 100644 --- a/backend/src/graphql/resolver/AdminResolver.test.ts +++ b/backend/src/graphql/resolver/AdminResolver.test.ts @@ -21,6 +21,7 @@ import { deletePendingCreation, confirmPendingCreation, createContributionLink, + deleteContributionLink, } from '@/seeds/graphql/mutations' import { getPendingCreations, @@ -1629,6 +1630,18 @@ describe('AdminResolver', () => { ) }) }) + + describe('deleteContributionLink', () => { + it('returns an error', async () => { + await expect( + mutate({ mutation: deleteContributionLink, variables: { id: -1 } }), + ).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('401 Unauthorized')], + }), + ) + }) + }) }) describe('authenticated', () => { @@ -1665,6 +1678,18 @@ describe('AdminResolver', () => { ) }) }) + + describe('deleteContributionLink', () => { + it('returns an error', async () => { + await expect( + mutate({ mutation: deleteContributionLink, variables: { id: -1 } }), + ).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('401 Unauthorized')], + }), + ) + }) + }) }) describe('with admin rights', () => { @@ -1760,6 +1785,53 @@ describe('AdminResolver', () => { }) }) }) + + describe('deleteContributionLink', () => { + describe('no valid id', () => { + it('returns an error', async () => { + await expect( + mutate({ mutation: deleteContributionLink, variables: { id: -1 } }), + ).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('Contribution Link not found to given id.')], + }), + ) + }) + }) + + describe('valid id', () => { + let linkId: number + beforeAll(async () => { + const links = await query({ query: listContributionLinks }) + linkId = links.data.listContributionLinks.links[0].id + }) + + it('returns a date string', async () => { + await expect( + mutate({ mutation: deleteContributionLink, variables: { id: linkId } }), + ).resolves.toEqual( + expect.objectContaining({ + data: { + deleteContributionLink: expect.any(String), + }, + }), + ) + }) + + it('does not list this contribution link anymore', async () => { + await expect(query({ query: listContributionLinks })).resolves.toEqual( + expect.objectContaining({ + data: { + listContributionLinks: { + links: [], + count: 0, + }, + }, + }), + ) + }) + }) + }) }) }) }) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index e13a013b6..715d09d35 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -1,4 +1,5 @@ import { Context, getUser } from '@/server/context' +import { backendLogger as logger } from '@/server/logger' import { Resolver, Query, Arg, Args, Authorized, Mutation, Ctx, Int } from 'type-graphql' import { getCustomRepository, @@ -492,7 +493,7 @@ export class AdminResolver { if (validTo) dbContributionLink.validTo = new Date(validTo) dbContributionLink.maxAmountPerMonth = maxAmountPerMonth dbContributionLink.maxPerCycle = maxPerCycle - dbContributionLink.save() + await dbContributionLink.save() return new ContributionLink(dbContributionLink) } @@ -512,6 +513,19 @@ export class AdminResolver { count, } } + + @Authorized([RIGHTS.DELETE_CONTRIBUTION_LINK]) + @Mutation(() => Date, { nullable: true }) + async deleteContributionLink(@Arg('id', () => Int) id: number): Promise { + const contributionLink = await DbContributionLink.findOne(id) + if (!contributionLink) { + logger.error(`Contribution Link not found to given id: ${id}`) + throw new Error('Contribution Link not found to given id.') + } + await contributionLink.softRemove() + const newContributionLink = await DbContributionLink.findOne({ id }, { withDeleted: true }) + return newContributionLink ? newContributionLink.deletedAt : null + } } interface CreationMap { diff --git a/backend/src/seeds/graphql/mutations.ts b/backend/src/seeds/graphql/mutations.ts index 355b5aa79..7c334796e 100644 --- a/backend/src/seeds/graphql/mutations.ts +++ b/backend/src/seeds/graphql/mutations.ts @@ -173,3 +173,9 @@ export const createContributionLink = gql` } } ` + +export const deleteContributionLink = gql` + mutation ($id: Int!) { + deleteContributionLink(id: $id) + } +` From dc46f4e78c5d26af13871d4773e4c102c30238fe Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 14 Jun 2022 15:29:34 +0200 Subject: [PATCH 09/17] add update contribution link mutation --- backend/src/auth/RIGHTS.ts | 1 + .../graphql/resolver/AdminResolver.test.ts | 118 ++++++++++++++++++ backend/src/graphql/resolver/AdminResolver.ts | 33 +++++ backend/src/seeds/graphql/mutations.ts | 39 ++++++ 4 files changed, 191 insertions(+) diff --git a/backend/src/auth/RIGHTS.ts b/backend/src/auth/RIGHTS.ts index f8fa38616..8ac2c78cc 100644 --- a/backend/src/auth/RIGHTS.ts +++ b/backend/src/auth/RIGHTS.ts @@ -40,4 +40,5 @@ export enum RIGHTS { CREATE_CONTRIBUTION_LINK = 'CREATE_CONTRIBUTION_LINK', LIST_CONTRIBUTION_LINKS = 'LIST_CONTRIBUTION_LINKS', DELETE_CONTRIBUTION_LINK = 'DELETE_CONTRIBUTION_LINK', + UPDATE_CONTRIBUTION_LINK = 'UPDATE_CONTRIBUTION_LINK', } diff --git a/backend/src/graphql/resolver/AdminResolver.test.ts b/backend/src/graphql/resolver/AdminResolver.test.ts index 32227f257..d08c52320 100644 --- a/backend/src/graphql/resolver/AdminResolver.test.ts +++ b/backend/src/graphql/resolver/AdminResolver.test.ts @@ -22,6 +22,7 @@ import { confirmPendingCreation, createContributionLink, deleteContributionLink, + updateContributionLink, } from '@/seeds/graphql/mutations' import { getPendingCreations, @@ -1631,6 +1632,27 @@ describe('AdminResolver', () => { }) }) + describe('updateContributionLink', () => { + it('returns an error', async () => { + await expect( + mutate({ + mutation: updateContributionLink, + variables: { + ...variables, + id: -1, + amount: new Decimal(400), + name: 'Dokumenta 2023', + memo: 'Danke für deine Teilnahme an der Dokumenta 2023', + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('401 Unauthorized')], + }), + ) + }) + }) + describe('deleteContributionLink', () => { it('returns an error', async () => { await expect( @@ -1679,6 +1701,27 @@ describe('AdminResolver', () => { }) }) + describe('updateContributionLink', () => { + it('returns an error', async () => { + await expect( + mutate({ + mutation: updateContributionLink, + variables: { + ...variables, + id: -1, + amount: new Decimal(400), + name: 'Dokumenta 2023', + memo: 'Danke für deine Teilnahme an der Dokumenta 2023', + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('401 Unauthorized')], + }), + ) + }) + }) + describe('deleteContributionLink', () => { it('returns an error', async () => { await expect( @@ -1786,6 +1829,81 @@ describe('AdminResolver', () => { }) }) + describe('updateContributionLink', () => { + describe('no valid id', () => { + it('returns an error', async () => { + await expect( + mutate({ + mutation: updateContributionLink, + variables: { + ...variables, + id: -1, + amount: new Decimal(400), + name: 'Dokumenta 2023', + memo: 'Danke für deine Teilnahme an der Dokumenta 2023', + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('Contribution Link not found to given id.')], + }), + ) + }) + }) + + describe('valid id', () => { + let linkId: number + beforeAll(async () => { + const links = await query({ query: listContributionLinks }) + linkId = links.data.listContributionLinks.links[0].id + }) + + it('returns updated contribution link object', async () => { + await expect( + mutate({ + mutation: updateContributionLink, + variables: { + ...variables, + id: linkId, + amount: new Decimal(400), + name: 'Dokumenta 2023', + memo: 'Danke für deine Teilnahme an der Dokumenta 2023', + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + data: { + updateContributionLink: { + id: linkId, + amount: '400', + code: expect.stringMatching(/^CL-[0-9a-f]{24,24}$/), + link: expect.any(String), + createdAt: expect.any(String), + name: 'Dokumenta 2023', + memo: 'Danke für deine Teilnahme an der Dokumenta 2023', + validFrom: expect.any(String), + validTo: expect.any(String), + maxAmountPerMonth: '200', + cycle: 'once', + maxPerCycle: 1, + }, + }, + }), + ) + }) + + it('updated the DB record', async () => { + await expect(DbContributionLink.findOne(linkId)).resolves.toEqual( + expect.objectContaining({ + id: linkId, + name: 'Dokumenta 2023', + memo: 'Danke für deine Teilnahme an der Dokumenta 2023', + }), + ) + }) + }) + }) + describe('deleteContributionLink', () => { describe('no valid id', () => { it('returns an error', async () => { diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 715d09d35..785a7de02 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -526,6 +526,39 @@ export class AdminResolver { const newContributionLink = await DbContributionLink.findOne({ id }, { withDeleted: true }) return newContributionLink ? newContributionLink.deletedAt : null } + + @Authorized([RIGHTS.UPDATE_CONTRIBUTION_LINK]) + @Mutation(() => ContributionLink) + async updateContributionLink( + @Args() + { + amount, + name, + memo, + cycle, + validFrom, + validTo, + maxAmountPerMonth, + maxPerCycle, + }: ContributionLinkArgs, + @Arg('id', () => Int) id: number, + ): Promise { + const dbContributionLink = await DbContributionLink.findOne(id) + if (!dbContributionLink) { + logger.error(`Contribution Link not found to given id: ${id}`) + throw new Error('Contribution Link not found to given id.') + } + dbContributionLink.amount = amount + dbContributionLink.name = name + dbContributionLink.memo = memo + dbContributionLink.cycle = cycle + if (validFrom) dbContributionLink.validFrom = new Date(validFrom) + if (validTo) dbContributionLink.validTo = new Date(validTo) + dbContributionLink.maxAmountPerMonth = maxAmountPerMonth + dbContributionLink.maxPerCycle = maxPerCycle + await dbContributionLink.save() + return new ContributionLink(dbContributionLink) + } } interface CreationMap { diff --git a/backend/src/seeds/graphql/mutations.ts b/backend/src/seeds/graphql/mutations.ts index 7c334796e..c0f0fa6e4 100644 --- a/backend/src/seeds/graphql/mutations.ts +++ b/backend/src/seeds/graphql/mutations.ts @@ -174,6 +174,45 @@ export const createContributionLink = gql` } ` +export const updateContributionLink = gql` + mutation ( + $amount: Decimal! + $name: String! + $memo: String! + $cycle: String! + $validFrom: String + $validTo: String + $maxAmountPerMonth: Decimal + $maxPerCycle: Int! = 1 + $id: Int! + ) { + updateContributionLink( + amount: $amount + name: $name + memo: $memo + cycle: $cycle + validFrom: $validFrom + validTo: $validTo + maxAmountPerMonth: $maxAmountPerMonth + maxPerCycle: $maxPerCycle + id: $id + ) { + id + amount + name + memo + code + link + createdAt + validFrom + validTo + maxAmountPerMonth + cycle + maxPerCycle + } + } +` + export const deleteContributionLink = gql` mutation ($id: Int!) { deleteContributionLink(id: $id) From 26a653fd7db50ce239e3d457ef4dc38e246d96c8 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 14 Jun 2022 17:14:09 +0200 Subject: [PATCH 10/17] coverage backend to 70% --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b7000100e..b935ef8f4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -528,7 +528,7 @@ jobs: report_name: Coverage Backend type: lcov result_path: ./backend/coverage/lcov.info - min_coverage: 68 + min_coverage: 70 token: ${{ github.token }} ########################################################################## From 7640680c421b1205e195723abe06fe45e5c43fe2 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 14 Jun 2022 18:04:20 +0200 Subject: [PATCH 11/17] seed two ContributionLinks --- .../graphql/resolver/AdminResolver.test.ts | 1 + .../ContributionLinkInterface.ts | 7 +++++ backend/src/seeds/contributionLink/index.ts | 18 +++++++++++++ backend/src/seeds/factory/contributionLink.ts | 27 +++++++++++++++++++ backend/src/seeds/index.ts | 7 +++++ 5 files changed, 60 insertions(+) create mode 100644 backend/src/seeds/contributionLink/ContributionLinkInterface.ts create mode 100644 backend/src/seeds/contributionLink/index.ts create mode 100644 backend/src/seeds/factory/contributionLink.ts diff --git a/backend/src/graphql/resolver/AdminResolver.test.ts b/backend/src/graphql/resolver/AdminResolver.test.ts index d08c52320..a1a92dace 100644 --- a/backend/src/graphql/resolver/AdminResolver.test.ts +++ b/backend/src/graphql/resolver/AdminResolver.test.ts @@ -1898,6 +1898,7 @@ describe('AdminResolver', () => { id: linkId, name: 'Dokumenta 2023', memo: 'Danke für deine Teilnahme an der Dokumenta 2023', + // amount: '400', }), ) }) diff --git a/backend/src/seeds/contributionLink/ContributionLinkInterface.ts b/backend/src/seeds/contributionLink/ContributionLinkInterface.ts new file mode 100644 index 000000000..d213bff23 --- /dev/null +++ b/backend/src/seeds/contributionLink/ContributionLinkInterface.ts @@ -0,0 +1,7 @@ +export interface ContributionLinkInterface { + amount: number + name: string + memo: string + validFrom?: date + validTo?: date +} diff --git a/backend/src/seeds/contributionLink/index.ts b/backend/src/seeds/contributionLink/index.ts new file mode 100644 index 000000000..41d28eb60 --- /dev/null +++ b/backend/src/seeds/contributionLink/index.ts @@ -0,0 +1,18 @@ +import { ContributionLinkInterface } from './ContributionLinkInterface' + +export const contributionLinks: ContributionLinkInterface[] = [ + { + name: 'Dokumenta 2017', + memo: 'Vielen Dank für deinen Besuch bei der Dokumenta 2017', + amount: 200, + validFrom: new Date(2017, 3, 8), + validTo: new Date(2017, 6, 16), + }, + { + name: 'Dokumenta 2022', + memo: 'Vielen Dank für deinen Besuch bei der Dokumenta 2022', + amount: 200, + validFrom: new Date(2022, 5, 18), + validTo: new Date(2022, 8, 25), + }, +] diff --git a/backend/src/seeds/factory/contributionLink.ts b/backend/src/seeds/factory/contributionLink.ts new file mode 100644 index 000000000..7e34b9d20 --- /dev/null +++ b/backend/src/seeds/factory/contributionLink.ts @@ -0,0 +1,27 @@ +import { ApolloServerTestClient } from 'apollo-server-testing' +import { createContributionLink } from '@/seeds/graphql/mutations' +import { login } from '@/seeds/graphql/queries' +import { ContributionLinkInterface } from '@/seeds/contributionLink/ContributionLinkInterface' + +export const contributionLinkFactory = async ( + client: ApolloServerTestClient, + contributionLink: ContributionLinkInterface, +): Promise => { + const { mutate, query } = client + + // login as admin + await query({ query: login, variables: { email: 'peter@lustig.de', password: 'Aa12345_' } }) + + const variables = { + amount: contributionLink.amount, + memo: contributionLink.memo, + name: contributionLink.name, + cycle: 'ONCE', + maxPerCycle: 1, + maxAmountPerMonth: 200, + validFrom: contributionLink.validFrom ? contributionLink.validFrom.toISOString() : undefined, + validTo: contributionLink.validTo ? contributionLink.validTo.toISOString() : undefined, + } + + await mutate({ mutation: createContributionLink, variables }) +} diff --git a/backend/src/seeds/index.ts b/backend/src/seeds/index.ts index 710f255ee..8e9a4e2d8 100644 --- a/backend/src/seeds/index.ts +++ b/backend/src/seeds/index.ts @@ -9,9 +9,11 @@ import { name, internet, datatype } from 'faker' import { users } from './users/index' import { creations } from './creation/index' import { transactionLinks } from './transactionLink/index' +import { contributionLinks } from './contributionLink/index' import { userFactory } from './factory/user' import { creationFactory } from './factory/creation' import { transactionLinkFactory } from './factory/transactionLink' +import { contributionLinkFactory } from './factory/contributionLink' import { entities } from '@entity/index' import CONFIG from '@/config' @@ -77,6 +79,11 @@ const run = async () => { await transactionLinkFactory(seedClient, transactionLinks[i]) } + // create Contribution Links + for (let i = 0; i < contributionLinks.length; i++) { + await contributionLinkFactory(seedClient, contributionLinks[i]) + } + await con.close() } From dcc1e9c2e7f9efe7d3f9ee98c845cd5d402bee2d Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 14 Jun 2022 19:19:12 +0200 Subject: [PATCH 12/17] proper type in seed --- .../src/seeds/contributionLink/ContributionLinkInterface.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/seeds/contributionLink/ContributionLinkInterface.ts b/backend/src/seeds/contributionLink/ContributionLinkInterface.ts index d213bff23..15ba4b72d 100644 --- a/backend/src/seeds/contributionLink/ContributionLinkInterface.ts +++ b/backend/src/seeds/contributionLink/ContributionLinkInterface.ts @@ -2,6 +2,6 @@ export interface ContributionLinkInterface { amount: number name: string memo: string - validFrom?: date - validTo?: date + validFrom?: Date + validTo?: Date } From ad3bb58d433251f437b65f8bef2b3df889e85758 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 15 Jun 2022 15:19:29 +0200 Subject: [PATCH 13/17] createContributionLink response contains contribution id --- backend/src/graphql/resolver/AdminResolver.test.ts | 1 + backend/src/seeds/graphql/mutations.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/backend/src/graphql/resolver/AdminResolver.test.ts b/backend/src/graphql/resolver/AdminResolver.test.ts index a1a92dace..06a11d8c2 100644 --- a/backend/src/graphql/resolver/AdminResolver.test.ts +++ b/backend/src/graphql/resolver/AdminResolver.test.ts @@ -1755,6 +1755,7 @@ describe('AdminResolver', () => { expect.objectContaining({ data: { createContributionLink: expect.objectContaining({ + id: expect.any(Number), amount: '200', code: expect.stringMatching(/^CL-[0-9a-f]{24,24}$/), link: expect.any(String), diff --git a/backend/src/seeds/graphql/mutations.ts b/backend/src/seeds/graphql/mutations.ts index c0f0fa6e4..253f78e2a 100644 --- a/backend/src/seeds/graphql/mutations.ts +++ b/backend/src/seeds/graphql/mutations.ts @@ -159,6 +159,7 @@ export const createContributionLink = gql` maxAmountPerMonth: $maxAmountPerMonth maxPerCycle: $maxPerCycle ) { + id amount name memo From 4d58320426e11980d3078a174c63759db62aa369 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 15 Jun 2022 15:29:10 +0200 Subject: [PATCH 14/17] new backend config version to have COMMUNITY_REDEEM_CONTRIBUTION_URL --- backend/.env.dist | 3 ++- backend/.env.template | 1 + backend/src/config/index.ts | 4 +++- backend/src/graphql/model/ContributionLink.ts | 2 +- deployment/bare_metal/.env.dist | 3 ++- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/backend/.env.dist b/backend/.env.dist index 62b786456..41eeeaf58 100644 --- a/backend/.env.dist +++ b/backend/.env.dist @@ -1,4 +1,4 @@ -CONFIG_VERSION=v6.2022-04-21 +CONFIG_VERSION=v7.2022-06-15 # Server PORT=4000 @@ -28,6 +28,7 @@ COMMUNITY_NAME=Gradido Entwicklung COMMUNITY_URL=http://localhost/ COMMUNITY_REGISTER_URL=http://localhost/register COMMUNITY_REDEEM_URL=http://localhost/redeem/{code} +COMMUNITY_REDEEM_CONTRIBUTION_URL=http://localhost/redeem/CL-{code} COMMUNITY_DESCRIPTION=Die lokale Entwicklungsumgebung von Gradido. # Login Server diff --git a/backend/.env.template b/backend/.env.template index 140ec67e9..284abc204 100644 --- a/backend/.env.template +++ b/backend/.env.template @@ -27,6 +27,7 @@ COMMUNITY_NAME=$COMMUNITY_NAME COMMUNITY_URL=$COMMUNITY_URL COMMUNITY_REGISTER_URL=$COMMUNITY_REGISTER_URL COMMUNITY_REDEEM_URL=$COMMUNITY_REDEEM_URL +COMMUNITY_REDEEM_CONTRIBUTION_URL=$COMMUNITY_REDEEM_CONTRIBUTION_URL COMMUNITY_DESCRIPTION=$COMMUNITY_DESCRIPTION # Login Server diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 5736e6d8a..dafcd4bf0 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -17,7 +17,7 @@ const constants = { LOG_LEVEL: process.env.LOG_LEVEL || 'info', CONFIG_VERSION: { DEFAULT: 'DEFAULT', - EXPECTED: 'v6.2022-04-21', + EXPECTED: 'v7.2022-06-15', CURRENT: '', }, } @@ -54,6 +54,8 @@ const community = { COMMUNITY_URL: process.env.COMMUNITY_URL || 'http://localhost/', COMMUNITY_REGISTER_URL: process.env.COMMUNITY_REGISTER_URL || 'http://localhost/register', COMMUNITY_REDEEM_URL: process.env.COMMUNITY_REDEEM_URL || 'http://localhost/redeem/{code}', + COMMUNITY_REDEEM_CONTRIBUTION_URL: + process.env.COMMUNITY_REDEEM_CONTRIBUTION_URL || 'http://localhost/redeem/CL-{code}', COMMUNITY_DESCRIPTION: process.env.COMMUNITY_DESCRIPTION || 'Die lokale Entwicklungsumgebung von Gradido.', } diff --git a/backend/src/graphql/model/ContributionLink.ts b/backend/src/graphql/model/ContributionLink.ts index e4b37ad59..87c3f7824 100644 --- a/backend/src/graphql/model/ContributionLink.ts +++ b/backend/src/graphql/model/ContributionLink.ts @@ -18,7 +18,7 @@ export class ContributionLink { this.cycle = contributionLink.cycle this.maxPerCycle = contributionLink.maxPerCycle this.code = 'CL-' + contributionLink.code - this.link = CONFIG.COMMUNITY_REDEEM_URL.replace(/{code}/g, this.code) + this.link = CONFIG.COMMUNITY_REDEEM_CONTRIBUTION_URL.replace(/{code}/g, this.code) } @Field(() => Number) diff --git a/deployment/bare_metal/.env.dist b/deployment/bare_metal/.env.dist index a1751a859..d9e159382 100644 --- a/deployment/bare_metal/.env.dist +++ b/deployment/bare_metal/.env.dist @@ -22,10 +22,11 @@ COMMUNITY_NAME="Gradido Development Stage1" COMMUNITY_URL=https://stage1.gradido.net/ COMMUNITY_REGISTER_URL=https://stage1.gradido.net/register COMMUNITY_REDEEM_URL=https://stage1.gradido.net/redeem/{code} +COMMUNITY_REDEEM_CONTRIBUTION_URL=https://stage1.gradido.net/redeem/CL-{code} COMMUNITY_DESCRIPTION="Gradido Development Stage1 Test Community" # backend -BACKEND_CONFIG_VERSION=v6.2022-04-21 +BACKEND_CONFIG_VERSION=v7.2022-06-15 JWT_EXPIRES_IN=30m GDT_API_URL=https://gdt.gradido.net From fbb629cac5fe9a581280d3e24dc1cbd050c46427 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 15 Jun 2022 15:52:11 +0200 Subject: [PATCH 15/17] remove CL-prefix --- backend/src/graphql/model/ContributionLink.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/model/ContributionLink.ts b/backend/src/graphql/model/ContributionLink.ts index 87c3f7824..9fe9eccd6 100644 --- a/backend/src/graphql/model/ContributionLink.ts +++ b/backend/src/graphql/model/ContributionLink.ts @@ -17,7 +17,7 @@ export class ContributionLink { this.maxAmountPerMonth = contributionLink.maxAmountPerMonth this.cycle = contributionLink.cycle this.maxPerCycle = contributionLink.maxPerCycle - this.code = 'CL-' + contributionLink.code + this.code = contributionLink.code this.link = CONFIG.COMMUNITY_REDEEM_CONTRIBUTION_URL.replace(/{code}/g, this.code) } From 64a7f4aa6ff9f20b6559c1f5104630caf5ce1956 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 15 Jun 2022 16:04:14 +0200 Subject: [PATCH 16/17] remove CL-prefix for contribution links in tests --- backend/src/graphql/resolver/AdminResolver.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.test.ts b/backend/src/graphql/resolver/AdminResolver.test.ts index 06a11d8c2..d55795f6e 100644 --- a/backend/src/graphql/resolver/AdminResolver.test.ts +++ b/backend/src/graphql/resolver/AdminResolver.test.ts @@ -1757,7 +1757,7 @@ describe('AdminResolver', () => { createContributionLink: expect.objectContaining({ id: expect.any(Number), amount: '200', - code: expect.stringMatching(/^CL-[0-9a-f]{24,24}$/), + code: expect.stringMatching(/^[0-9a-f]{24,24}$/), link: expect.any(String), createdAt: expect.any(String), name: 'Dokumenta 2022', @@ -1809,7 +1809,7 @@ describe('AdminResolver', () => { links: expect.arrayContaining([ expect.objectContaining({ amount: '200', - code: expect.stringMatching(/^CL-[0-9a-f]{24,24}$/), + code: expect.stringMatching(/^[0-9a-f]{24,24}$/), link: expect.any(String), createdAt: expect.any(String), name: 'Dokumenta 2022', @@ -1877,7 +1877,7 @@ describe('AdminResolver', () => { updateContributionLink: { id: linkId, amount: '400', - code: expect.stringMatching(/^CL-[0-9a-f]{24,24}$/), + code: expect.stringMatching(/^[0-9a-f]{24,24}$/), link: expect.any(String), createdAt: expect.any(String), name: 'Dokumenta 2023', From 5b7cb5cdf45e472f12fd8262d7d3548ea216a7fd Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 15 Jun 2022 16:08:16 +0200 Subject: [PATCH 17/17] test CL-prefix on contribution links --- backend/src/graphql/resolver/AdminResolver.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.test.ts b/backend/src/graphql/resolver/AdminResolver.test.ts index d55795f6e..7417b529e 100644 --- a/backend/src/graphql/resolver/AdminResolver.test.ts +++ b/backend/src/graphql/resolver/AdminResolver.test.ts @@ -1758,7 +1758,7 @@ describe('AdminResolver', () => { id: expect.any(Number), amount: '200', code: expect.stringMatching(/^[0-9a-f]{24,24}$/), - link: expect.any(String), + link: expect.stringMatching(/^.*?\/CL-[0-9a-f]{24,24}$/), createdAt: expect.any(String), name: 'Dokumenta 2022', memo: 'Danke für deine Teilnahme an der Dokumenta 2022', @@ -1810,7 +1810,7 @@ describe('AdminResolver', () => { expect.objectContaining({ amount: '200', code: expect.stringMatching(/^[0-9a-f]{24,24}$/), - link: expect.any(String), + link: expect.stringMatching(/^.*?\/CL-[0-9a-f]{24,24}$/), createdAt: expect.any(String), name: 'Dokumenta 2022', memo: 'Danke für deine Teilnahme an der Dokumenta 2022', @@ -1878,7 +1878,7 @@ describe('AdminResolver', () => { id: linkId, amount: '400', code: expect.stringMatching(/^[0-9a-f]{24,24}$/), - link: expect.any(String), + link: expect.stringMatching(/^.*?\/CL-[0-9a-f]{24,24}$/), createdAt: expect.any(String), name: 'Dokumenta 2023', memo: 'Danke für deine Teilnahme an der Dokumenta 2023',