Merge pull request #2046 from gradido/add-creations-to-user

feat: Login Returns Open Creations for User
This commit is contained in:
Moriz Wahl 2022-07-12 16:19:41 +02:00 committed by GitHub
commit 0e1dc8c632
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -1,10 +1,12 @@
import { ObjectType, Field } from 'type-graphql'
import { KlickTipp } from './KlickTipp'
import { User as dbUser } from '@entity/User'
import Decimal from 'decimal.js-light'
import { FULL_CREATION_AVAILABLE } from '../resolver/const/const'
@ObjectType()
export class User {
constructor(user: dbUser) {
constructor(user: dbUser, creation: Decimal[] = FULL_CREATION_AVAILABLE) {
this.id = user.id
this.email = user.email
this.firstName = user.firstName
@ -17,6 +19,7 @@ export class User {
this.isAdmin = user.isAdmin
this.klickTipp = null
this.hasElopage = null
this.creation = creation
}
@Field(() => Number)
@ -64,4 +67,7 @@ export class User {
@Field(() => Boolean, { nullable: true })
hasElopage: boolean | null
@Field(() => [Decimal])
creation: Decimal[]
}

View File

@ -23,6 +23,7 @@ import { sendAccountMultiRegistrationEmail } from '@/mailer/sendAccountMultiRegi
import { klicktippSignIn } from '@/apis/KlicktippController'
import { RIGHTS } from '@/auth/RIGHTS'
import { hasElopageBuys } from '@/util/hasElopageBuys'
import { getUserCreation } from './util/creations'
// eslint-disable-next-line @typescript-eslint/no-var-requires
const sodium = require('sodium-native')
@ -224,7 +225,7 @@ export class UserResolver {
logger.info('verifyLogin...')
// TODO refactor and do not have duplicate code with login(see below)
const userEntity = getUser(context)
const user = new User(userEntity)
const user = new User(userEntity, await getUserCreation(userEntity.id))
// user.pubkey = userEntity.pubKey.toString('hex')
// Elopage Status & Stored PublisherId
user.hasElopage = await this.hasElopage(context)
@ -274,7 +275,7 @@ export class UserResolver {
logger.addContext('user', dbUser.id)
logger.debug('login credentials valid...')
const user = new User(dbUser)
const user = new User(dbUser, await getUserCreation(dbUser.id))
logger.debug('user=' + user)
// Elopage Status & Stored PublisherId