try to solve problem of dbUser-entity with emailContact in context

This commit is contained in:
Claus-Peter Hübner 2022-08-26 14:42:37 +02:00
parent 0f90f960ce
commit 1184666fe2
2 changed files with 15 additions and 7 deletions

View File

@ -31,7 +31,7 @@ const isAuthorized: AuthChecker<any> = async ({ context }, rights) => {
// TODO - load from database dynamically & admin - maybe encode this in the token to prevent many database requests
// TODO this implementation is bullshit - two database queries cause our user identifiers are not aligned and vary between email, id and pubKey
const userRepository = await getCustomRepository(UserRepository)
const userRepository = getCustomRepository(UserRepository)
try {
const user = await userRepository.findByPubkeyHex(context.pubKey)
context.user = user

View File

@ -1,12 +1,20 @@
import { Brackets, EntityRepository, ObjectLiteral, Repository } from '@dbTools/typeorm'
import { User } from '@entity/User'
import { User as DbUser } from '@entity/User'
@EntityRepository(User)
export class UserRepository extends Repository<User> {
async findByPubkeyHex(pubkeyHex: string): Promise<User> {
return await this.createQueryBuilder('user')
@EntityRepository(DbUser)
export class UserRepository extends Repository<DbUser> {
async findByPubkeyHex(pubkeyHex: string): Promise<DbUser> {
const dbUser = await this.createQueryBuilder('user')
.where('hex(user.pubKey) = :pubkeyHex', { pubkeyHex })
.getOneOrFail()
/*
const dbUser = await this.findOneOrFail(`hex(user.pubKey) = { pubkeyHex }`)
const emailContact = await this.query(
`SELECT * from user_contacts where id = { dbUser.emailId }`,
)
dbUser.emailContact = emailContact
*/
return dbUser
}
async findBySearchCriteriaPagedFiltered(
@ -15,7 +23,7 @@ export class UserRepository extends Repository<User> {
filterCriteria: ObjectLiteral[],
currentPage: number,
pageSize: number,
): Promise<[User[], number]> {
): Promise<[DbUser[], number]> {
const query = await this.createQueryBuilder('user')
.select(select)
.withDeleted()