hasElopage is now implemented on apollo

- requires authorization now
This commit is contained in:
Ulf Gebhardt 2021-11-06 19:30:03 +01:00
parent 5d7241da14
commit 248622f3be
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9

View File

@ -26,6 +26,7 @@ import { UserSettingRepository } from '../../typeorm/repository/UserSettingRepos
import { Setting } from '../enum/Setting'
import { UserRepository } from '../../typeorm/repository/User'
import { LoginUser } from '@entity/LoginUser'
import { LoginElopageBuys } from '@entity/LoginElopageBuys'
import { LoginUserBackup } from '@entity/LoginUserBackup'
import { LoginEmailOptIn } from '@entity/LoginEmailOptIn'
import { sendEMail } from '../../util/sendEMail'
@ -570,12 +571,19 @@ export class UserResolver {
return new CheckEmailResponse(result.data)
}
@Authorized()
@Query(() => Boolean)
async hasElopage(@Ctx() context: any): Promise<boolean> {
const result = await apiGet(CONFIG.LOGIN_API_URL + 'hasElopage?session_id=' + context.sessionId)
if (!result.success) {
throw new Error(result.data)
// const result = await apiGet(CONFIG.LOGIN_API_URL + 'hasElopage?session_id=' + context.sessionId)
const userRepository = getCustomRepository(UserRepository)
const userEntity = await userRepository.findByPubkeyHex(context.pubKey).catch()
if (!userEntity) {
return false
}
return result.data.hasElopage
const elopageBuyCount = await LoginElopageBuys.count({ payerEmail: userEntity.email })
return elopageBuyCount > 0
}
}