Press n or j to go to the next uncovered block, b, p or k for the previous block.
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 32 33 34 35 36 37 38 39 40 41 42 | 2x 2x 2x 2x 2x 2x | const Device = require("../models/device.model.js"); const { body, validationResult } = require('express-validator') // Create and Save a new Customer exports.create = (req, res) => { // Validate request const errors = validationResult(req); if (!errors.isEmpty()) { console.log(errors.array()); return res.status(422).json({ errors: errors.array() }); } // Create a Customer const device = new Device({ token: req.body.token, pilotID: req.body.pilotID, DeviceOs: req.body.device_os }); Device.create(device, (err, data) => { if (err) res.status(500).send({ message: err.message || "Some error occurred while creating the Device." }); else res.send(data); }); }; exports.validate = (method) => { switch (method) { case 'create': { return [ body('token', "token is empty").exists(), body('device_os', "device os is empty").exists(), body('pilotID', 'Invalid pilotID').optional().isInt() ] } } } |