mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
33 lines
987 B
TypeScript
33 lines
987 B
TypeScript
import { Account } from '@entity/Account'
|
|
import { User } from '@entity/User'
|
|
import { FindOptionsRelations } from 'typeorm'
|
|
|
|
import { UserIdentifier } from '@/graphql/input/UserIdentifier'
|
|
import { getDataSource } from '@/typeorm/DataSource'
|
|
|
|
export const UserRepository = getDataSource()
|
|
.getRepository(User)
|
|
.extend({
|
|
async findAccountByUserIdentifier({
|
|
uuid,
|
|
accountNr,
|
|
}: UserIdentifier): Promise<Account | undefined> {
|
|
const user = await this.findOne({
|
|
where: { gradidoID: uuid, accounts: { derivationIndex: accountNr ?? 1 } },
|
|
relations: { accounts: true },
|
|
})
|
|
if (user && user.accounts?.length === 1) {
|
|
const account = user.accounts[0]
|
|
account.user = user
|
|
return account
|
|
}
|
|
},
|
|
|
|
findByGradidoId(
|
|
{ uuid }: UserIdentifier,
|
|
relations?: FindOptionsRelations<User>,
|
|
): Promise<User | null> {
|
|
return User.findOne({ where: { gradidoID: uuid }, relations })
|
|
},
|
|
})
|