const otpModel = require("../models/otpModel");

const generateOTP = async (req) => {
    const { email } = req.body;
    const otp = Math.floor(1000+ 
        Math.random()* 9000).toString(); 
    const newOTP = new otpModel({
        email: email,
        OTP: otp
    });
    const result = await newOTP.save();
    return result
};

const verfiyOTP = async (req) => {
    const {email, OTP} = req.body;
    const OTPverify = await otpModel.findOne({email: email, OTP: OTP});
    return OTPverify;
};

module.exports = {
    generateOTP,
    verfiyOTP
};