import Verification from "../../../entities/Verification" ; import { StartPhoneVerificationMutationArgs , StartPhoneVerificationResponse } from "../../../types/graph" ; import { Resolvers } from "../../../types/resolvers" ; import { sendVerificationSMS } from "../../../utils/sendSMS" ; const resolvers = { Mutation : { StartPhoneVerification : async ( _ , args ) : Promise < StartPhoneVerificationResponse > => { const { phoneNumber } = args ; try { const existingVerification = await Verification . findOne ( { payload : phoneNumber } ) ; if ( existingVerification ) { existingVerification . remove ( ) ; } const newVerification = await Verification . create ( { payload : phoneNumber , target : "PHONE" } ) . save ( ) ; await sendVerificationSMS ( newVerification . payload , newVerification . key ) ; return { ok : true , error : null } ; } catch ( error ) { return { ok : false , error : error . message } ; } } } } ; export default resolvers ;