Added the publisherId to the login & createUser calls, adjusted the tests to the new code.

This commit is contained in:
elweyn 2021-10-13 13:26:46 +02:00
parent 5a14161284
commit 58182d73c6
4 changed files with 15 additions and 10 deletions

View File

@ -1,4 +1,4 @@
import { ArgsType, Field } from 'type-graphql'
import { ArgsType, Field, Int } from 'type-graphql'
@ArgsType()
export default class CreateUserArgs {
@ -16,4 +16,7 @@ export default class CreateUserArgs {
@Field(() => String)
language: string
@Field(() => Int, { nullable: true })
publisherId: number
}

View File

@ -1,4 +1,4 @@
import { ArgsType, Field } from 'type-graphql'
import { ArgsType, Field, Int } from 'type-graphql'
@ArgsType()
export default class UnsecureLoginArgs {
@ -8,6 +8,6 @@ export default class UnsecureLoginArgs {
@Field(() => String)
password: string
@Field(() => Number, { nullable: true })
@Field(() => Int, { nullable: true })
publisherId: number
}

View File

@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { ObjectType, Field } from 'type-graphql'
import { ObjectType, Field, Int } from 'type-graphql'
import { KlickTipp } from './KlickTipp'
@ObjectType()
@ -66,8 +66,8 @@ export class User {
groupId: number
*/
// what is publisherId?
@Field(() => Number)
publisherId: number
@Field(() => Int, { nullable: true })
publisherId?: number
@Field(() => Boolean)
coinanimation: boolean

View File

@ -48,6 +48,9 @@ export class UserResolver {
value: encode(result.data.session_id, result.data.user.public_hex),
})
const user = new User(result.data.user)
if (user.publisherId === 0) {
user.publisherId = undefined
}
user.hasElopage = result.data.hasElopage
// read additional settings from settings table
const userRepository = getCustomRepository(UserRepository)
@ -68,8 +71,7 @@ export class UserResolver {
throw new Error('error with cannot happen')
}
if (publisherId) {
// Save it
if (!user.hasElopage && publisherId) {
user.publisherId = publisherId
await this.updateUserInfos(
{ publisherId },
@ -115,7 +117,7 @@ export class UserResolver {
@Mutation(() => String)
async createUser(
@Args() { email, firstName, lastName, password, language }: CreateUserArgs,
@Args() { email, firstName, lastName, password, language, publisherId }: CreateUserArgs,
): Promise<string> {
const payload = {
email,
@ -125,7 +127,7 @@ export class UserResolver {
emailType: 2,
login_after_register: true,
language: language,
publisher_id: 0,
publisher_id: publisherId,
}
const result = await apiPost(CONFIG.LOGIN_API_URL + 'createUser', payload)
if (!result.success) {