bde148f286
* wip * some extra fixes * stuff kinda works? * need to figure out mocks * need to figure out mocks * fix db listener * gqlgen fix * minor gqlgen watch adjustment * lint fixes * delete old codegen file * converting migrations to ESM * getModuleDIrectory * vitest sort of works * added back ts-vitest * resolve gql double load * fixing test timeout configs * TSC lint fix * fix automate tests * moar debugging * debugging * more debugging * codegen update * server works * yargs migrated * chore(server): getting rid of global mocks for Server ESM (#5046) * got rid of email mock * got rid of comment mocks * got rid of multi region mocks * got rid of stripe mock * admin override mock updated * removed final mock * fixing import.meta.resolve calls * another import.meta.resolve fix * added requested test * nyc ESM fix * removed unneeded deps + linting * yarn lock forgot to commit * tryna fix flakyness * email capture util fix * sendEmail fix * fix TSX check * sender transporter fix + CR comments * merge main fix * test fixx * circleci fix * gqlgen bigint fix * error formatter fix * more error formatting improvements * esmloader added to Dockerfile * more dockerfile fixes * bg jobs fix
65 lines
2.2 KiB
TypeScript
65 lines
2.2 KiB
TypeScript
import { db } from '@/db/knex'
|
|
import { Resolvers } from '@/modules/core/graph/generated/graphql'
|
|
import { getServerInfoFactory } from '@/modules/core/repositories/server'
|
|
import { findPrimaryEmailForUserFactory } from '@/modules/core/repositories/userEmails'
|
|
import {
|
|
getUserByEmailFactory,
|
|
getUserFactory
|
|
} from '@/modules/core/repositories/users'
|
|
import {
|
|
deleteOldAndInsertNewVerificationFactory,
|
|
getPendingTokenFactory
|
|
} from '@/modules/emails/repositories'
|
|
import { renderEmail } from '@/modules/emails/services/emailRendering'
|
|
import { sendEmail } from '@/modules/emails/services/sending'
|
|
import { requestEmailVerificationFactory } from '@/modules/emails/services/verification/request'
|
|
import { withOperationLogging } from '@/observability/domain/businessLogging'
|
|
|
|
const getUser = getUserFactory({ db })
|
|
const requestEmailVerification = requestEmailVerificationFactory({
|
|
getUser,
|
|
getServerInfo: getServerInfoFactory({ db }),
|
|
deleteOldAndInsertNewVerification: deleteOldAndInsertNewVerificationFactory({ db }),
|
|
findPrimaryEmailForUser: findPrimaryEmailForUserFactory({ db }),
|
|
sendEmail,
|
|
renderEmail
|
|
})
|
|
const getUserByEmail = getUserByEmailFactory({ db })
|
|
|
|
export default {
|
|
User: {
|
|
async hasPendingVerification(parent) {
|
|
const email = parent.email
|
|
if (!email) return false
|
|
|
|
const token = await getPendingTokenFactory({ db })({ email })
|
|
return !!token
|
|
}
|
|
},
|
|
Mutation: {
|
|
async requestVerification(_parent, _args, ctx) {
|
|
const { userId } = ctx
|
|
await withOperationLogging(
|
|
async () => await requestEmailVerification(userId || ''),
|
|
{
|
|
logger: ctx.log,
|
|
operationName: 'requestEmailVerification',
|
|
operationDescription: 'Request email verification'
|
|
}
|
|
)
|
|
return true
|
|
},
|
|
async requestVerificationByEmail(_parent, args, ctx) {
|
|
const { email } = args
|
|
const user = await getUserByEmail(email)
|
|
if (!user?.email || user.verified) return false
|
|
await withOperationLogging(async () => await requestEmailVerification(user.id), {
|
|
logger: ctx.log,
|
|
operationName: 'requestEmailVerificationFromEmail',
|
|
operationDescription: `Request verification by email`
|
|
})
|
|
return true
|
|
}
|
|
}
|
|
} as Resolvers
|