mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
seed deleted and outdated transaction links
This commit is contained in:
parent
12f3a7ab4a
commit
5b9463ca2a
@ -29,7 +29,7 @@ export const transactionLinkCode = (date: Date): string => {
|
||||
|
||||
const CODE_VALID_DAYS_DURATION = 14
|
||||
|
||||
const transactionLinkExpireDate = (date: Date): Date => {
|
||||
export const transactionLinkExpireDate = (date: Date): Date => {
|
||||
const validUntil = new Date(date)
|
||||
return new Date(validUntil.setDate(date.getDate() + CODE_VALID_DAYS_DURATION))
|
||||
}
|
||||
|
||||
@ -2,6 +2,9 @@ import { ApolloServerTestClient } from 'apollo-server-testing'
|
||||
import { createTransactionLink } from '@/seeds/graphql/mutations'
|
||||
import { login } from '@/seeds/graphql/queries'
|
||||
import { TransactionLinkInterface } from '@/seeds/transactionLink/TransactionLinkInterface'
|
||||
import { transactionLinkExpireDate } from '@/graphql/resolver/TransactionLinkResolver'
|
||||
import { TransactionLink } from '@entity/TransactionLink'
|
||||
import { User } from '@entity/User'
|
||||
|
||||
export const transactionLinkFactory = async (
|
||||
client: ApolloServerTestClient,
|
||||
@ -18,4 +21,23 @@ export const transactionLinkFactory = async (
|
||||
}
|
||||
|
||||
await mutate({ mutation: createTransactionLink, variables })
|
||||
|
||||
if (transactionLink.createdAt || transactionLink.deletedAt) {
|
||||
const user = await User.findOneOrFail({ where: { email: transactionLink.email } })
|
||||
const dbTransactionLink = await TransactionLink.findOneOrFail({
|
||||
where: { userId: user.id },
|
||||
order: { createdAt: 'DESC' },
|
||||
})
|
||||
|
||||
if (transactionLink.createdAt) {
|
||||
dbTransactionLink.createdAt = transactionLink.createdAt
|
||||
dbTransactionLink.validUntil = transactionLinkExpireDate(transactionLink.createdAt)
|
||||
await dbTransactionLink.save()
|
||||
}
|
||||
|
||||
if (transactionLink.deletedAt) {
|
||||
dbTransactionLink.deletedAt = new Date()
|
||||
await dbTransactionLink.save()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,4 +2,6 @@ export interface TransactionLinkInterface {
|
||||
email: string
|
||||
amount: number
|
||||
memo: string
|
||||
createdAt?: Date
|
||||
deletedAt?: boolean
|
||||
}
|
||||
|
||||
@ -1,10 +1,52 @@
|
||||
import { TransactionLinkInterface } from './TransactionLinkInterface'
|
||||
|
||||
export const transactionLinks: TransactionLinkInterface[] = [
|
||||
{
|
||||
email: 'bibi@bloxberg.de',
|
||||
amount: 19.99,
|
||||
memo: 'Leider wollte niemand meine Gradidos zum Neujahr haben :(',
|
||||
createdAt: new Date(2022, 0, 1),
|
||||
},
|
||||
{
|
||||
email: 'bibi@bloxberg.de',
|
||||
amount: 19.99,
|
||||
memo: `Kein Trick, keine Zauberrei,
|
||||
bei Gradidio sei dabei!`,
|
||||
},
|
||||
{
|
||||
email: 'bibi@bloxberg.de',
|
||||
amount: 19.99,
|
||||
memo: `Kein Trick, keine Zauberrei,
|
||||
bei Gradidio sei dabei!`,
|
||||
},
|
||||
{
|
||||
email: 'bibi@bloxberg.de',
|
||||
amount: 19.99,
|
||||
memo: `Kein Trick, keine Zauberrei,
|
||||
bei Gradidio sei dabei!`,
|
||||
},
|
||||
{
|
||||
email: 'bibi@bloxberg.de',
|
||||
amount: 19.99,
|
||||
memo: `Kein Trick, keine Zauberrei,
|
||||
bei Gradidio sei dabei!`,
|
||||
},
|
||||
{
|
||||
email: 'bibi@bloxberg.de',
|
||||
amount: 19.99,
|
||||
memo: `Kein Trick, keine Zauberrei,
|
||||
bei Gradidio sei dabei!`,
|
||||
},
|
||||
{
|
||||
email: 'bibi@bloxberg.de',
|
||||
amount: 19.99,
|
||||
memo: `Kein Trick, keine Zauberrei,
|
||||
bei Gradidio sei dabei!`,
|
||||
},
|
||||
{
|
||||
email: 'bibi@bloxberg.de',
|
||||
amount: 19.99,
|
||||
memo: 'Da habe ich mich wohl etwas übernommen.',
|
||||
deletedAt: true,
|
||||
},
|
||||
]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user