0
import { Router, Request, Response } from 'express';
import { deleteOtp, generateOtp, verifyOtp } from '../services/otp.services';
import { sendOtp } from '../utils/sendOtp';

const router = Router();

router.get('/send-otp', async (req: Request, res: Response) => {
    try {
        const { phone } = req.body;
        if (!phone) return res.status(400).json({ message: 'Numéro requis' });

        const otp = await generateOtp(phone);
        await sendOtp(phone, otp);
        res.json({ success: true, message: 'OTP envoyé' });
    } catch (error) {
        res.status(500).json({ success: false, message: 'Erreur lors de l\'envoi de l\'OTP' });
    }
});

router.post('/verify-otp', async (req: Request, res: Response) => {
    try {
        const { phone, otp } = req.body;
        const valid = await verifyOtp(phone, otp);
        res.json({ valid });
    } catch (error) {
        res.status(500).json({ success: false, message: 'Erreur lors de la vérification de l\'OTP' });
    }
});

router.delete('/delete-otp', async (req: Request, res: Response) => {
    try {
        const { phone, otp } = req.body;
        await deleteOtp(phone, otp);
        res.json({ success: true, message: 'OTP supprimé' });
    } catch (error) {
        res.status(500).json({ success: false, message: 'Erreur lors de la suppression de l\'OTP' });
    }
});

export default router;

error:

No overload matches this call.
The last overload gave the following error.
Argument of type '(req: Request, res: Response) => Promise<Response<any, Record<string, any>> | undefined>' is not assignable to parameter of type 'Application<Record<string, any>>'.
Type '(req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>) => Promise<...>' is missing the following properties from type 'Application<Record<string, any>>': init, defaultConfiguration, engine, set, and 63 more.ts(2769) index.d.ts(168, 5): The last overload is declared here. (alias) interface Response<ResBody = any, Locals extends Record<string, any> = Record<string, any>>
import Response

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.