Change response value to boolean, add RIGHTS for createContribution, add new RIGHT in ROLES.

This commit is contained in:
elweyn 2022-06-27 13:40:36 +02:00
parent 6ac0106470
commit c03509c525
3 changed files with 7 additions and 5 deletions

View File

@ -25,6 +25,7 @@ export enum RIGHTS {
REDEEM_TRANSACTION_LINK = 'REDEEM_TRANSACTION_LINK',
LIST_TRANSACTION_LINKS = 'LIST_TRANSACTION_LINKS',
GDT_BALANCE = 'GDT_BALANCE',
CREATE_CONTRIBUTION = 'CREATE_CONTRIBUTION',
// Admin
SEARCH_USERS = 'SEARCH_USERS',
SET_USER_ROLE = 'SET_USER_ROLE',

View File

@ -23,6 +23,7 @@ export const ROLE_USER = new Role('user', [
RIGHTS.REDEEM_TRANSACTION_LINK,
RIGHTS.LIST_TRANSACTION_LINKS,
RIGHTS.GDT_BALANCE,
RIGHTS.CREATE_CONTRIBUTION,
])
export const ROLE_ADMIN = new Role('admin', Object.values(RIGHTS)) // all rights

View File

@ -1,3 +1,4 @@
import { RIGHTS } from '@/auth/RIGHTS'
import { Context, getUser } from '@/server/context'
import { backendLogger as logger } from '@/server/logger'
import { Contribution } from '@entity/Contribution'
@ -8,13 +9,12 @@ import { isContributionValid } from './util/isContributionValid'
@Resolver()
export class ContributionResolver {
@Authorized([])
@Mutation(() => Contribution)
@Authorized([RIGHTS.CREATE_CONTRIBUTION])
@Mutation(() => Boolean)
async createContribution(
@Args() { amount, memo, creationDate }: CreateContributionArgs,
@Ctx() context: Context,
): Promise<Contribution> {
logger.trace('createContribution..')
): Promise<boolean> {
const user = getUser(context)
if (!user) {
throw new Error(`Could not find user`)
@ -40,6 +40,6 @@ export class ContributionResolver {
logger.trace('contribution to save', contribution)
await Contribution.save(contribution)
return contribution
return true
}
}