File size: 997 Bytes
ba5c923
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const zod_1 = require("zod");
const pingMessageSchema = zod_1.z.object({
    message: zod_1.z
        .string()
        .min(1, "Message is required and must be a non-empty string"),
    numbers: zod_1.z
        .array(zod_1.z
        .string()
        .min(12, "Each number must be at least 12 characters long")
        .regex(/^\d{12}$/, "Invalid phone number format. Correct example: 123456789012"))
        .max(5, "You can provide a maximum of 5 phone numbers"),
    image: zod_1.z.string().optional()
});
const validatePingMessage = (req, res, next) => {
    try {
        pingMessageSchema.parse(req.body);
        next();
    }
    catch (error) {
        if (error instanceof zod_1.z.ZodError) {
            res.status(400).json({ errors: error.errors });
        }
        else {
            res.status(500).json({ message: "Internal Server Error" });
        }
    }
};
exports.default = validatePingMessage;