This commit is contained in:
einhornimmond 2021-10-12 15:56:02 +02:00
parent 0640eb24d5
commit 3ecf960ab6

View File

@ -47,20 +47,21 @@ export class UserResolver {
const user = new User(result.data.user) const user = new User(result.data.user)
// read additional settings from settings table // read additional settings from settings table
const userRepository = getCustomRepository(UserRepository) const userRepository = getCustomRepository(UserRepository)
let userEntity: void | DbUser = await userRepository.findByPubkeyHex(user.pubkey).catch(() => {}) let userEntity: void | DbUser
if(!userEntity) { userEntity = await userRepository.findByPubkeyHex(user.pubkey).catch(() => {
// create user if it don't exist with this pubkey userEntity = new DbUser()
userEntity = new DbUser
userEntity.firstName = user.firstName userEntity.firstName = user.firstName
userEntity.lastName = user.lastName userEntity.lastName = user.lastName
userEntity.username = user.username userEntity.username = user.username
userEntity.email = user.email userEntity.email = user.email
userEntity.pubkey = Buffer.from(fromHex(user.pubkey)) userEntity.pubkey = Buffer.from(fromHex(user.pubkey))
userEntity.save().catch(() => { userEntity.save().catch(() => {
throw new Error('error by save userEntity') throw new Error('error by save userEntity')
}) })
})
if (!userEntity) {
throw new Error('error with cannot happen')
} }
const userSettingRepository = getCustomRepository(UserSettingRepository) const userSettingRepository = getCustomRepository(UserSettingRepository)