//validate our form inputs and handle the errors using YUP const validationSchema = () => Yup.object({ company: Yup.string() .min(1, "Please enter a name more than 1 character") .required("This field is required"), area: Yup.string() .min(1, "Must be more than 1 characters") .required("This field is requried"), phone: Yup.number() .min(10, "Must be more than 10 characters") .required("This field is requried") })
const deleteDelivery = async (req, res, next) => { try { const schema = Yup.object().shape({ id: Yup.number() .positive() .required('Id is required') }); await schema.validate(req.params, { abortEarly: false }); return next(); } catch (error) { return res .status(400) .json({ error: 'Validation fails', messages: error.inner }); } }
//validate our form inputs and handle the errors using YUP const validationSchema = () => Yup.object({ company: Yup.string() .min(1, "Please enter a name more than 1 character") .required("This field is required"), area: Yup.string() .min(1, "Must be more than 1 characters") .required("This field is requried"), phone: Yup.number() .min(10, "Must be more than 10 characters") .required("This field is requried") })
const deleteDeliveryman = async (req, res, next) => { try { const schema = Yup.object().shape({ id: Yup.number() .positive() .required('Id is required.') }); await schema.validate(req.params, { abortEarly: false }); return next(); } catch (error) { return res .status(400) .json({ error: 'Validation fails', messages: error.inner }); } }
const deleteRecipient = async (req, res, next) => { try { const schema = Yup.object().shape({ id: Yup.number() .positive() .required() }); await schema.validate(req.params, { abortEarly: false }); return next(); } catch (error) { return res .status(400) .json({ error: 'Validation fails', messages: error.inner }); } }
const showDeliveryProblem = async (req, res, next) => { try { const schema = Yup.object().shape({ deliveryId: Yup.number() .positive() .required('Id is required.') }); await schema.validate(req.params, { abortEarly: false }); return next(); } catch (error) { return res .status(400) .json({ error: 'Validation fails.', messages: error.inner }); } }
const deleteDeliveryProblem = async (req, res, next) => { try { const schema = Yup.object().shape({ problemId: Yup.number() .positive() .required('Id is required.') }); await schema.validate(req.params, { abortEarly: false }); return next(); } catch (error) { return res .status(400) .json({ error: 'Validation fails.', messages: error.inner }); } }
const deleteOrder = async (req, res, next) => { try { const schema = Yup.object().shape({ id: Yup.number() .positive() .required('Id is required') }); await schema.validate(req.params, { abortEarly: false }); return next(); } catch (error) { return res .status(400) .json({ error: 'Validation fails', messages: error.inner }); } }
const showRecipient = async (req, res, next) => { try { const schema = Yup.object().shape({ id: Yup.number() .positive() .required() }); await schema.validate(req.params, { abortEarly: false }); return next(); } catch (error) { return res .status(400) .json({ error: 'Validation fails', messages: error.inner }); } }
const showDeliveryman = async (req, res, next) => { try { const schema = Yup.object().shape({ id: Yup.number() .positive() .required('Id is required.') }); await schema.validate(req.params, { abortEarly: false }); return next(); } catch (error) { return res .status(400) .json({ error: 'Validation fails', messages: error.inner }); } }
const listOrderToDeliveryman = async (req, res, next) => { try { const schema = Yup.object().shape({ id: Yup.number() .positive() .required('Delivery Id is required') }); await schema.validate(req.params, { abortEarly: false }); return next(); } catch (error) { return res .status(400) .json({ error: 'Validation fails', messages: error.inner }); } }
const showDelivery = async (req, res, next) => { try { const schema = Yup.object().shape({ id: Yup.number() .positive() .required('Id is required') }); await schema.validate(req.params, { abortEarly: false }); return next(); } catch (error) { return res .status(400) .json({ error: 'Validation fails', messages: error.inner }); } }