mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
some small refactors for the user resolver:
- stop using repositories where its not needed - removed unused function
This commit is contained in:
parent
d63f93149c
commit
264270524b
@ -152,8 +152,7 @@ const createEmailOptIn = async (
|
||||
loginUserId: number,
|
||||
queryRunner: QueryRunner,
|
||||
): Promise<LoginEmailOptIn> => {
|
||||
const loginEmailOptInRepository = await getRepository(LoginEmailOptIn)
|
||||
let emailOptIn = await loginEmailOptInRepository.findOne({
|
||||
let emailOptIn = await LoginEmailOptIn.findOne({
|
||||
userId: loginUserId,
|
||||
emailOptInTypeId: EMAIL_OPT_IN_REGISTER,
|
||||
})
|
||||
@ -182,8 +181,7 @@ const createEmailOptIn = async (
|
||||
}
|
||||
|
||||
const getOptInCode = async (loginUserId: number): Promise<LoginEmailOptIn> => {
|
||||
const loginEmailOptInRepository = await getRepository(LoginEmailOptIn)
|
||||
let optInCode = await loginEmailOptInRepository.findOne({
|
||||
let optInCode = await LoginEmailOptIn.findOne({
|
||||
userId: loginUserId,
|
||||
emailOptInTypeId: EMAIL_OPT_IN_RESET_PASSWORD,
|
||||
})
|
||||
@ -205,7 +203,7 @@ const getOptInCode = async (loginUserId: number): Promise<LoginEmailOptIn> => {
|
||||
optInCode.userId = loginUserId
|
||||
optInCode.emailOptInTypeId = EMAIL_OPT_IN_RESET_PASSWORD
|
||||
}
|
||||
await loginEmailOptInRepository.save(optInCode)
|
||||
await LoginEmailOptIn.save(optInCode)
|
||||
return optInCode
|
||||
}
|
||||
|
||||
@ -487,12 +485,9 @@ export class UserResolver {
|
||||
}
|
||||
|
||||
// Load code
|
||||
const loginEmailOptInRepository = await getRepository(LoginEmailOptIn)
|
||||
const optInCode = await loginEmailOptInRepository
|
||||
.findOneOrFail({ verificationCode: code })
|
||||
.catch(() => {
|
||||
throw new Error('Could not login with emailVerificationCode')
|
||||
})
|
||||
const optInCode = await LoginEmailOptIn.findOneOrFail({ verificationCode: code }).catch(() => {
|
||||
throw new Error('Could not login with emailVerificationCode')
|
||||
})
|
||||
|
||||
// Code is only valid for 10minutes
|
||||
const timeElapsed = Date.now() - new Date(optInCode.updatedAt).getTime()
|
||||
|
||||
@ -9,11 +9,6 @@ export class UserRepository extends Repository<User> {
|
||||
.getOneOrFail()
|
||||
}
|
||||
|
||||
async findByPubkeyHexBuffer(pubkeyHexBuffer: Buffer): Promise<User> {
|
||||
const pubKeyString = pubkeyHexBuffer.toString('hex')
|
||||
return await this.findByPubkeyHex(pubKeyString)
|
||||
}
|
||||
|
||||
async findByEmail(email: string): Promise<User> {
|
||||
return this.createQueryBuilder('user').where('user.email = :email', { email }).getOneOrFail()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user