solve problems reading user with emailcontact

This commit is contained in:
Claus-Peter Hübner 2022-08-30 00:57:57 +02:00
parent 1d1de2011a
commit 7269b4b67b
5 changed files with 7 additions and 11 deletions

View File

@ -14,7 +14,7 @@ export class User {
this.emailId = user.emailId
if (user.emailContact) {
this.email = user.emailContact.email
this.emailContact = user.emailContact
this.emailContact = new UserContact(user.emailContact)
this.emailChecked = user.emailContact.emailChecked
}
this.firstName = user.firstName

View File

@ -1,9 +1,9 @@
import { ObjectType, Field } from 'type-graphql'
import { UserContact as dbUserCOntact} from '@entity/UserContact'
import { UserContact as dbUserContact} from '@entity/UserContact'
@ObjectType()
export class UserContact {
constructor(userContact: dbUserCOntact) {
constructor(userContact: dbUserContact) {
this.id = userContact.id
this.type = userContact.type
this.userId = userContact.userId

View File

@ -850,11 +850,7 @@ export class UserResolver {
@Query(() => Boolean)
async hasElopage(@Ctx() context: Context): Promise<boolean> {
logger.info(`hasElopage()...`)
const userEntity = context.user
if (!userEntity) {
logger.info('missing context.user for EloPage-check')
return false
}
const userEntity = getUser(context)
const elopageBuys = hasElopageBuys(userEntity.emailContact.email)
logger.debug(`has ElopageBuys = ${elopageBuys}`)
return elopageBuys

View File

@ -43,7 +43,7 @@ export class User extends BaseEntity {
@Column({ length: 255, unique: true, nullable: false, collation: 'utf8mb4_unicode_ci' })
email: string
*/
@OneToOne(() => UserContact, (emailContact) => emailContact.userId)
@OneToOne(() => UserContact, (emailContact) => emailContact.user)
@JoinColumn({ name: 'email_id' })
emailContact: UserContact
@ -115,7 +115,7 @@ export class User extends BaseEntity {
@JoinColumn({ name: 'user_id' })
contributions?: Contribution[]
@OneToMany(() => UserContact, (usercontact) => usercontact.userId)
@OneToMany(() => UserContact, (usercontact) => usercontact.user)
@JoinColumn({ name: 'user_id' })
usercontacts?: UserContact[]
}

View File

@ -53,7 +53,7 @@ export class UserContact extends BaseEntity {
@Column({ name: 'created_at', default: () => 'CURRENT_TIMESTAMP', nullable: false })
createdAt: Date
@DeleteDateColumn({ name: 'updated_at', nullable: true })
@Column({ name: 'updated_at', nullable: true, default: null, type: 'datetime' })
updatedAt: Date | null
@DeleteDateColumn({ name: 'deleted_at', nullable: true })