mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge branch 'master' into add-nvm-config-files
This commit is contained in:
commit
2928a03b81
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@ -528,7 +528,7 @@ jobs:
|
||||
report_name: Coverage Backend
|
||||
type: lcov
|
||||
result_path: ./backend/coverage/lcov.info
|
||||
min_coverage: 58
|
||||
min_coverage: 65
|
||||
token: ${{ github.token }}
|
||||
|
||||
##########################################################################
|
||||
|
||||
@ -24,12 +24,6 @@ const mocks = {
|
||||
},
|
||||
$store: {
|
||||
commit: stateCommitMock,
|
||||
state: {
|
||||
moderator: {
|
||||
id: 0,
|
||||
name: 'test moderator',
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@ -122,7 +116,6 @@ describe('CreationFormular', () => {
|
||||
creationDate: getCreationDate(2),
|
||||
amount: 90,
|
||||
memo: 'Test create coins',
|
||||
moderator: 0,
|
||||
},
|
||||
}),
|
||||
)
|
||||
@ -370,14 +363,12 @@ describe('CreationFormular', () => {
|
||||
creationDate: getCreationDate(1),
|
||||
amount: 200,
|
||||
memo: 'Test mass create coins',
|
||||
moderator: 0,
|
||||
},
|
||||
{
|
||||
email: 'bibi@bloxberg.de',
|
||||
creationDate: getCreationDate(1),
|
||||
amount: 200,
|
||||
memo: 'Test mass create coins',
|
||||
moderator: 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@ -154,7 +154,6 @@ export default {
|
||||
creationDate: this.selected.date,
|
||||
amount: Number(this.value),
|
||||
memo: this.text,
|
||||
moderator: Number(this.$store.state.moderator.id),
|
||||
})
|
||||
})
|
||||
this.$apollo
|
||||
@ -188,7 +187,6 @@ export default {
|
||||
creationDate: this.selected.date,
|
||||
amount: Number(this.value),
|
||||
memo: this.text,
|
||||
moderator: Number(this.$store.state.moderator.id),
|
||||
}
|
||||
this.$apollo
|
||||
.mutate({
|
||||
|
||||
@ -11,7 +11,6 @@ const apolloMutateMock = jest.fn().mockResolvedValue({
|
||||
amount: 500,
|
||||
date: new Date(),
|
||||
memo: 'Test Schöpfung 2',
|
||||
moderator: 0,
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -28,12 +27,6 @@ const mocks = {
|
||||
mutate: apolloMutateMock,
|
||||
},
|
||||
$store: {
|
||||
state: {
|
||||
moderator: {
|
||||
id: 0,
|
||||
name: 'test moderator',
|
||||
},
|
||||
},
|
||||
commit: stateCommitMock,
|
||||
},
|
||||
}
|
||||
@ -104,7 +97,6 @@ describe('EditCreationFormular', () => {
|
||||
creationDate: getCreationDate(0),
|
||||
amount: 500,
|
||||
memo: 'Test Schöpfung 2',
|
||||
moderator: 0,
|
||||
},
|
||||
}),
|
||||
)
|
||||
@ -129,7 +121,6 @@ describe('EditCreationFormular', () => {
|
||||
amount: 500,
|
||||
date: expect.any(Date),
|
||||
memo: 'Test Schöpfung 2',
|
||||
moderator: 0,
|
||||
row: expect.any(Object),
|
||||
},
|
||||
],
|
||||
|
||||
@ -120,7 +120,6 @@ export default {
|
||||
creationDate: this.selected.date,
|
||||
amount: Number(this.value),
|
||||
memo: this.text,
|
||||
moderator: Number(this.$store.state.moderator.id),
|
||||
},
|
||||
})
|
||||
.then((result) => {
|
||||
@ -129,7 +128,6 @@ export default {
|
||||
amount: Number(result.data.updatePendingCreation.amount),
|
||||
date: result.data.updatePendingCreation.date,
|
||||
memo: result.data.updatePendingCreation.memo,
|
||||
moderator: Number(result.data.updatePendingCreation.moderator),
|
||||
row: this.row,
|
||||
})
|
||||
this.toastSuccess(
|
||||
|
||||
@ -1,19 +1,7 @@
|
||||
import gql from 'graphql-tag'
|
||||
|
||||
export const createPendingCreation = gql`
|
||||
mutation (
|
||||
$email: String!
|
||||
$amount: Decimal!
|
||||
$memo: String!
|
||||
$creationDate: String!
|
||||
$moderator: Int!
|
||||
) {
|
||||
createPendingCreation(
|
||||
email: $email
|
||||
amount: $amount
|
||||
memo: $memo
|
||||
creationDate: $creationDate
|
||||
moderator: $moderator
|
||||
)
|
||||
mutation ($email: String!, $amount: Decimal!, $memo: String!, $creationDate: String!) {
|
||||
createPendingCreation(email: $email, amount: $amount, memo: $memo, creationDate: $creationDate)
|
||||
}
|
||||
`
|
||||
|
||||
@ -1,27 +1,18 @@
|
||||
import gql from 'graphql-tag'
|
||||
|
||||
export const updatePendingCreation = gql`
|
||||
mutation (
|
||||
$id: Int!
|
||||
$email: String!
|
||||
$amount: Decimal!
|
||||
$memo: String!
|
||||
$creationDate: String!
|
||||
$moderator: Int!
|
||||
) {
|
||||
mutation ($id: Int!, $email: String!, $amount: Decimal!, $memo: String!, $creationDate: String!) {
|
||||
updatePendingCreation(
|
||||
id: $id
|
||||
email: $email
|
||||
amount: $amount
|
||||
memo: $memo
|
||||
creationDate: $creationDate
|
||||
moderator: $moderator
|
||||
) {
|
||||
amount
|
||||
date
|
||||
memo
|
||||
creation
|
||||
moderator
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { ArgsType, Field, InputType, Int } from 'type-graphql'
|
||||
import { ArgsType, Field, InputType } from 'type-graphql'
|
||||
import Decimal from 'decimal.js-light'
|
||||
|
||||
@InputType()
|
||||
@ -15,7 +15,4 @@ export default class CreatePendingCreationArgs {
|
||||
|
||||
@Field(() => String)
|
||||
creationDate: string
|
||||
|
||||
@Field(() => Int)
|
||||
moderator: number
|
||||
}
|
||||
|
||||
@ -17,7 +17,4 @@ export default class UpdatePendingCreationArgs {
|
||||
|
||||
@Field(() => String)
|
||||
creationDate: string
|
||||
|
||||
@Field(() => Int)
|
||||
moderator: number
|
||||
}
|
||||
|
||||
@ -12,9 +12,6 @@ export class UpdatePendingCreation {
|
||||
@Field(() => Decimal)
|
||||
amount: Decimal
|
||||
|
||||
@Field(() => Number)
|
||||
moderator: number
|
||||
|
||||
@Field(() => [Decimal])
|
||||
creation: Decimal[]
|
||||
}
|
||||
|
||||
1060
backend/src/graphql/resolver/AdminResolver.test.ts
Normal file
1060
backend/src/graphql/resolver/AdminResolver.test.ts
Normal file
File diff suppressed because it is too large
Load Diff
@ -157,11 +157,12 @@ export class AdminResolver {
|
||||
@Mutation(() => Date, { nullable: true })
|
||||
async unDeleteUser(@Arg('userId', () => Int) userId: number): Promise<Date | null> {
|
||||
const user = await dbUser.findOne({ id: userId }, { withDeleted: true })
|
||||
// user exists ?
|
||||
if (!user) {
|
||||
throw new Error(`Could not find user with userId: ${userId}`)
|
||||
}
|
||||
// recover user account
|
||||
if (!user.deletedAt) {
|
||||
throw new Error('User is not deleted')
|
||||
}
|
||||
await user.recover()
|
||||
return null
|
||||
}
|
||||
@ -169,7 +170,8 @@ export class AdminResolver {
|
||||
@Authorized([RIGHTS.CREATE_PENDING_CREATION])
|
||||
@Mutation(() => [Number])
|
||||
async createPendingCreation(
|
||||
@Args() { email, amount, memo, creationDate, moderator }: CreatePendingCreationArgs,
|
||||
@Args() { email, amount, memo, creationDate }: CreatePendingCreationArgs,
|
||||
@Ctx() context: Context,
|
||||
): Promise<Decimal[]> {
|
||||
const user = await dbUser.findOne({ email }, { withDeleted: true })
|
||||
if (!user) {
|
||||
@ -181,6 +183,7 @@ export class AdminResolver {
|
||||
if (!user.emailChecked) {
|
||||
throw new Error('Creation could not be saved, Email is not activated')
|
||||
}
|
||||
const moderator = getUser(context)
|
||||
const creations = await getUserCreation(user.id)
|
||||
const creationDateObj = new Date(creationDate)
|
||||
if (isCreationValid(creations, amount, creationDateObj)) {
|
||||
@ -190,7 +193,7 @@ export class AdminResolver {
|
||||
adminPendingCreation.created = new Date()
|
||||
adminPendingCreation.date = creationDateObj
|
||||
adminPendingCreation.memo = memo
|
||||
adminPendingCreation.moderator = moderator
|
||||
adminPendingCreation.moderator = moderator.id
|
||||
|
||||
await AdminPendingCreation.save(adminPendingCreation)
|
||||
}
|
||||
@ -202,12 +205,13 @@ export class AdminResolver {
|
||||
async createPendingCreations(
|
||||
@Arg('pendingCreations', () => [CreatePendingCreationArgs])
|
||||
pendingCreations: CreatePendingCreationArgs[],
|
||||
@Ctx() context: Context,
|
||||
): Promise<CreatePendingCreations> {
|
||||
let success = false
|
||||
const successfulCreation: string[] = []
|
||||
const failedCreation: string[] = []
|
||||
for (const pendingCreation of pendingCreations) {
|
||||
await this.createPendingCreation(pendingCreation)
|
||||
await this.createPendingCreation(pendingCreation, context)
|
||||
.then(() => {
|
||||
successfulCreation.push(pendingCreation.email)
|
||||
success = true
|
||||
@ -226,7 +230,8 @@ export class AdminResolver {
|
||||
@Authorized([RIGHTS.UPDATE_PENDING_CREATION])
|
||||
@Mutation(() => UpdatePendingCreation)
|
||||
async updatePendingCreation(
|
||||
@Args() { id, email, amount, memo, creationDate, moderator }: UpdatePendingCreationArgs,
|
||||
@Args() { id, email, amount, memo, creationDate }: UpdatePendingCreationArgs,
|
||||
@Ctx() context: Context,
|
||||
): Promise<UpdatePendingCreation> {
|
||||
const user = await dbUser.findOne({ email }, { withDeleted: true })
|
||||
if (!user) {
|
||||
@ -236,7 +241,13 @@ export class AdminResolver {
|
||||
throw new Error(`User was deleted (${email})`)
|
||||
}
|
||||
|
||||
const pendingCreationToUpdate = await AdminPendingCreation.findOneOrFail({ id })
|
||||
const moderator = getUser(context)
|
||||
|
||||
const pendingCreationToUpdate = await AdminPendingCreation.findOne({ id })
|
||||
|
||||
if (!pendingCreationToUpdate) {
|
||||
throw new Error('No creation found to given id.')
|
||||
}
|
||||
|
||||
if (pendingCreationToUpdate.userId !== user.id) {
|
||||
throw new Error('user of the pending creation and send user does not correspond')
|
||||
@ -248,20 +259,18 @@ export class AdminResolver {
|
||||
creations = updateCreations(creations, pendingCreationToUpdate)
|
||||
}
|
||||
|
||||
if (!isCreationValid(creations, amount, creationDateObj)) {
|
||||
throw new Error('Creation is not valid')
|
||||
}
|
||||
// all possible cases not to be true are thrown in this function
|
||||
isCreationValid(creations, amount, creationDateObj)
|
||||
pendingCreationToUpdate.amount = amount
|
||||
pendingCreationToUpdate.memo = memo
|
||||
pendingCreationToUpdate.date = new Date(creationDate)
|
||||
pendingCreationToUpdate.moderator = moderator
|
||||
pendingCreationToUpdate.moderator = moderator.id
|
||||
|
||||
await AdminPendingCreation.save(pendingCreationToUpdate)
|
||||
const result = new UpdatePendingCreation()
|
||||
result.amount = amount
|
||||
result.memo = pendingCreationToUpdate.memo
|
||||
result.date = pendingCreationToUpdate.date
|
||||
result.moderator = pendingCreationToUpdate.moderator
|
||||
|
||||
result.creation = await getUserCreation(user.id)
|
||||
|
||||
@ -298,8 +307,11 @@ export class AdminResolver {
|
||||
@Authorized([RIGHTS.DELETE_PENDING_CREATION])
|
||||
@Mutation(() => Boolean)
|
||||
async deletePendingCreation(@Arg('id', () => Int) id: number): Promise<boolean> {
|
||||
const entity = await AdminPendingCreation.findOneOrFail(id)
|
||||
const res = await AdminPendingCreation.delete(entity)
|
||||
const pendingCreation = await AdminPendingCreation.findOne(id)
|
||||
if (!pendingCreation) {
|
||||
throw new Error('Creation not found for given id.')
|
||||
}
|
||||
const res = await AdminPendingCreation.delete(pendingCreation)
|
||||
return !!res
|
||||
}
|
||||
|
||||
@ -309,7 +321,10 @@ export class AdminResolver {
|
||||
@Arg('id', () => Int) id: number,
|
||||
@Ctx() context: Context,
|
||||
): Promise<boolean> {
|
||||
const pendingCreation = await AdminPendingCreation.findOneOrFail(id)
|
||||
const pendingCreation = await AdminPendingCreation.findOne(id)
|
||||
if (!pendingCreation) {
|
||||
throw new Error('Creation not found to given id.')
|
||||
}
|
||||
const moderatorUser = getUser(context)
|
||||
if (moderatorUser.id === pendingCreation.userId)
|
||||
throw new Error('Moderator can not confirm own pending creation')
|
||||
@ -340,8 +355,7 @@ export class AdminResolver {
|
||||
transaction.memo = pendingCreation.memo
|
||||
transaction.userId = pendingCreation.userId
|
||||
transaction.previous = lastTransaction ? lastTransaction.id : null
|
||||
// TODO pending creations decimal
|
||||
transaction.amount = new Decimal(Number(pendingCreation.amount))
|
||||
transaction.amount = pendingCreation.amount
|
||||
transaction.creationDate = pendingCreation.date
|
||||
transaction.balance = newBalance
|
||||
transaction.balanceDate = receivedCallDate
|
||||
@ -504,7 +518,7 @@ function updateCreations(creations: Decimal[], pendingCreation: AdminPendingCrea
|
||||
if (index < 0) {
|
||||
throw new Error('You cannot create GDD for a month older than the last three months.')
|
||||
}
|
||||
creations[index] = creations[index].plus(pendingCreation.amount)
|
||||
creations[index] = creations[index].plus(pendingCreation.amount.toString())
|
||||
return creations
|
||||
}
|
||||
|
||||
@ -512,12 +526,12 @@ function isCreationValid(creations: Decimal[], amount: Decimal, creationDate: Da
|
||||
const index = getCreationIndex(creationDate.getMonth())
|
||||
|
||||
if (index < 0) {
|
||||
throw new Error(`No Creation found!`)
|
||||
throw new Error('No information for available creations for the given date')
|
||||
}
|
||||
|
||||
if (amount.greaterThan(creations[index].toString())) {
|
||||
throw new Error(
|
||||
`The amount (${amount} GDD) to be created exceeds the available amount (${creations[index]} GDD) for this month.`,
|
||||
`The amount (${amount} GDD) to be created exceeds the amount (${creations[index]} GDD) still available for this month.`,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -17,27 +17,22 @@ export const nMonthsBefore = (date: Date, months = 1): string => {
|
||||
export const creationFactory = async (
|
||||
client: ApolloServerTestClient,
|
||||
creation: CreationInterface,
|
||||
): Promise<void> => {
|
||||
): Promise<AdminPendingCreation | void> => {
|
||||
const { mutate, query } = client
|
||||
|
||||
// login as Peter Lustig (admin) and get his user ID
|
||||
const {
|
||||
data: {
|
||||
login: { id },
|
||||
},
|
||||
} = await query({ query: login, variables: { email: 'peter@lustig.de', password: 'Aa12345_' } })
|
||||
await query({ query: login, variables: { email: 'peter@lustig.de', password: 'Aa12345_' } })
|
||||
|
||||
await mutate({ mutation: createPendingCreation, variables: { ...creation, moderator: id } })
|
||||
// TODO it would be nice to have this mutation return the id
|
||||
await mutate({ mutation: createPendingCreation, variables: { ...creation } })
|
||||
|
||||
// get User
|
||||
const user = await User.findOneOrFail({ where: { email: creation.email } })
|
||||
|
||||
if (creation.confirmed) {
|
||||
const pendingCreation = await AdminPendingCreation.findOneOrFail({
|
||||
where: { userId: user.id },
|
||||
order: { created: 'DESC' },
|
||||
})
|
||||
const pendingCreation = await AdminPendingCreation.findOneOrFail({
|
||||
where: { userId: user.id, amount: creation.amount },
|
||||
order: { created: 'DESC' },
|
||||
})
|
||||
|
||||
if (creation.confirmed) {
|
||||
await mutate({ mutation: confirmPendingCreation, variables: { id: pendingCreation.id } })
|
||||
|
||||
if (creation.moveCreationDate) {
|
||||
@ -55,5 +50,7 @@ export const creationFactory = async (
|
||||
await transaction.save()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return pendingCreation
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ import { ApolloServerTestClient } from 'apollo-server-testing'
|
||||
export const userFactory = async (
|
||||
client: ApolloServerTestClient,
|
||||
user: UserInterface,
|
||||
): Promise<void> => {
|
||||
): Promise<User> => {
|
||||
const { mutate } = client
|
||||
|
||||
const {
|
||||
@ -24,13 +24,15 @@ export const userFactory = async (
|
||||
})
|
||||
}
|
||||
|
||||
if (user.createdAt || user.deletedAt || user.isAdmin) {
|
||||
// get user from database
|
||||
const dbUser = await User.findOneOrFail({ id })
|
||||
// get user from database
|
||||
const dbUser = await User.findOneOrFail({ id })
|
||||
|
||||
if (user.createdAt || user.deletedAt || user.isAdmin) {
|
||||
if (user.createdAt) dbUser.createdAt = user.createdAt
|
||||
if (user.deletedAt) dbUser.deletedAt = user.deletedAt
|
||||
if (user.isAdmin) dbUser.isAdmin = new Date()
|
||||
await dbUser.save()
|
||||
}
|
||||
|
||||
return dbUser
|
||||
}
|
||||
|
||||
@ -84,20 +84,8 @@ export const createTransactionLink = gql`
|
||||
// from admin interface
|
||||
|
||||
export const createPendingCreation = gql`
|
||||
mutation (
|
||||
$email: String!
|
||||
$amount: Decimal!
|
||||
$memo: String!
|
||||
$creationDate: String!
|
||||
$moderator: Int!
|
||||
) {
|
||||
createPendingCreation(
|
||||
email: $email
|
||||
amount: $amount
|
||||
memo: $memo
|
||||
creationDate: $creationDate
|
||||
moderator: $moderator
|
||||
)
|
||||
mutation ($email: String!, $amount: Decimal!, $memo: String!, $creationDate: String!) {
|
||||
createPendingCreation(email: $email, amount: $amount, memo: $memo, creationDate: $creationDate)
|
||||
}
|
||||
`
|
||||
|
||||
@ -106,3 +94,48 @@ export const confirmPendingCreation = gql`
|
||||
confirmPendingCreation(id: $id)
|
||||
}
|
||||
`
|
||||
|
||||
export const deleteUser = gql`
|
||||
mutation ($userId: Int!) {
|
||||
deleteUser(userId: $userId)
|
||||
}
|
||||
`
|
||||
|
||||
export const unDeleteUser = gql`
|
||||
mutation ($userId: Int!) {
|
||||
unDeleteUser(userId: $userId)
|
||||
}
|
||||
`
|
||||
|
||||
export const createPendingCreations = gql`
|
||||
mutation ($pendingCreations: [CreatePendingCreationArgs!]!) {
|
||||
createPendingCreations(pendingCreations: $pendingCreations) {
|
||||
success
|
||||
successfulCreation
|
||||
failedCreation
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
export const updatePendingCreation = gql`
|
||||
mutation ($id: Int!, $email: String!, $amount: Decimal!, $memo: String!, $creationDate: String!) {
|
||||
updatePendingCreation(
|
||||
id: $id
|
||||
email: $email
|
||||
amount: $amount
|
||||
memo: $memo
|
||||
creationDate: $creationDate
|
||||
) {
|
||||
amount
|
||||
date
|
||||
memo
|
||||
creation
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
export const deletePendingCreation = gql`
|
||||
mutation ($id: Int!) {
|
||||
deletePendingCreation(id: $id)
|
||||
}
|
||||
`
|
||||
|
||||
@ -148,3 +148,21 @@ export const queryTransactionLink = gql`
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
// from admin interface
|
||||
|
||||
export const getPendingCreations = gql`
|
||||
query {
|
||||
getPendingCreations {
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
email
|
||||
amount
|
||||
memo
|
||||
date
|
||||
moderator
|
||||
creation
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user