mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge pull request #1522 from gradido/refactor_user_resolver
Refactor: User resolver
This commit is contained in:
commit
0605f7dcb0
@ -152,8 +152,7 @@ const createEmailOptIn = async (
|
|||||||
loginUserId: number,
|
loginUserId: number,
|
||||||
queryRunner: QueryRunner,
|
queryRunner: QueryRunner,
|
||||||
): Promise<LoginEmailOptIn> => {
|
): Promise<LoginEmailOptIn> => {
|
||||||
const loginEmailOptInRepository = await getRepository(LoginEmailOptIn)
|
let emailOptIn = await LoginEmailOptIn.findOne({
|
||||||
let emailOptIn = await loginEmailOptInRepository.findOne({
|
|
||||||
userId: loginUserId,
|
userId: loginUserId,
|
||||||
emailOptInTypeId: EMAIL_OPT_IN_REGISTER,
|
emailOptInTypeId: EMAIL_OPT_IN_REGISTER,
|
||||||
})
|
})
|
||||||
@ -182,8 +181,7 @@ const createEmailOptIn = async (
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getOptInCode = async (loginUserId: number): Promise<LoginEmailOptIn> => {
|
const getOptInCode = async (loginUserId: number): Promise<LoginEmailOptIn> => {
|
||||||
const loginEmailOptInRepository = await getRepository(LoginEmailOptIn)
|
let optInCode = await LoginEmailOptIn.findOne({
|
||||||
let optInCode = await loginEmailOptInRepository.findOne({
|
|
||||||
userId: loginUserId,
|
userId: loginUserId,
|
||||||
emailOptInTypeId: EMAIL_OPT_IN_RESET_PASSWORD,
|
emailOptInTypeId: EMAIL_OPT_IN_RESET_PASSWORD,
|
||||||
})
|
})
|
||||||
@ -205,7 +203,7 @@ const getOptInCode = async (loginUserId: number): Promise<LoginEmailOptIn> => {
|
|||||||
optInCode.userId = loginUserId
|
optInCode.userId = loginUserId
|
||||||
optInCode.emailOptInTypeId = EMAIL_OPT_IN_RESET_PASSWORD
|
optInCode.emailOptInTypeId = EMAIL_OPT_IN_RESET_PASSWORD
|
||||||
}
|
}
|
||||||
await loginEmailOptInRepository.save(optInCode)
|
await LoginEmailOptIn.save(optInCode)
|
||||||
return optInCode
|
return optInCode
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -490,12 +488,9 @@ export class UserResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load code
|
// Load code
|
||||||
const loginEmailOptInRepository = await getRepository(LoginEmailOptIn)
|
const optInCode = await LoginEmailOptIn.findOneOrFail({ verificationCode: code }).catch(() => {
|
||||||
const optInCode = await loginEmailOptInRepository
|
throw new Error('Could not login with emailVerificationCode')
|
||||||
.findOneOrFail({ verificationCode: code })
|
})
|
||||||
.catch(() => {
|
|
||||||
throw new Error('Could not login with emailVerificationCode')
|
|
||||||
})
|
|
||||||
|
|
||||||
// Code is only valid for 10minutes
|
// Code is only valid for 10minutes
|
||||||
const timeElapsed = Date.now() - new Date(optInCode.updatedAt).getTime()
|
const timeElapsed = Date.now() - new Date(optInCode.updatedAt).getTime()
|
||||||
|
|||||||
@ -9,11 +9,6 @@ export class UserRepository extends Repository<User> {
|
|||||||
.getOneOrFail()
|
.getOneOrFail()
|
||||||
}
|
}
|
||||||
|
|
||||||
async findByPubkeyHexBuffer(pubkeyHexBuffer: Buffer): Promise<User> {
|
|
||||||
const pubKeyString = pubkeyHexBuffer.toString('hex')
|
|
||||||
return await this.findByPubkeyHex(pubKeyString)
|
|
||||||
}
|
|
||||||
|
|
||||||
async getUsersIndiced(userIds: number[]): Promise<User[]> {
|
async getUsersIndiced(userIds: number[]): Promise<User[]> {
|
||||||
if (!userIds.length) return []
|
if (!userIds.length) return []
|
||||||
const users = await this.createQueryBuilder('user')
|
const users = await this.createQueryBuilder('user')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user