How to use the celebrate.Joi.object function in celebrate

To help you get started, we’ve selected a few celebrate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hack4impact-uiuc / life-after-hate / backend / routes / api / sample.js View on Github external
body: Joi.object().keys({
      name: Joi.string().required(),
      age: Joi.number().integer(),
      role: Joi.string().default("admin")
    })
  }),
  function(req, res) {
    console.log("HI");
    res.send("Hello world!");
  }
);

router.post(
  "/signup",
  celebrate({
    body: Joi.object().keys({
      name: Joi.string().required(),
      age: Joi.number().integer(),
      role: Joi.string().default("admin")
    })
  }),
  (req, res) => {
    res.send("HI");
    console.log(req.body);
    // At this point, req.body has been validated and
    // req.body.role is equal to req.body.role if provided in the POST or set to 'admin' by joi
  }
);

module.exports = router;
github hack4impact-uiuc / life-after-hate / backend / routes / api / resources.js View on Github external
})
);

// create new resource
router.post(
  "/",
  requireAdminStatus,
  celebrate({
    body: Joi.object().keys({
      companyName: Joi.string().required(),
      contactName: Joi.string().required(),
      contactPhone: Joi.string().required(),
      contactEmail: Joi.string().required(),
      description: Joi.string().required(),
      address: Joi.string().required(),
      location: Joi.object({
        type: Joi.string().default("Point"),
        coordinates: Joi.array()
          .length(2)
          .items(Joi.number())
      }).required(),
      notes: Joi.string().allow(""),
      tags: Joi.array().items(Joi.string())
    })
  }),
  errorWrap(async (req, res) => {
    const data = req.body;
    const created_tags = extractor.extract(data.notes, {
      language: "english",
      remove_digits: true,
      return_changed_case: true,
      remove_duplicates: true
github hack4impact-uiuc / life-after-hate / backend / routes / api / resources.js View on Github external
const resourceId = req.params.resource_id;
    const resource = await Resource.findById(resourceId);
    res.json({
      code: 200,
      result: resource,
      success: true
    });
  })
);

// edit resource
router.put(
  "/:resource_id",
  requireAdminStatus,
  celebrate({
    body: Joi.object().keys({
      companyName: Joi.string(),
      contactName: Joi.string(),
      contactPhone: Joi.string(),
      contactEmail: Joi.string(),
      description: Joi.string(),
      address: Joi.string(),
      location: Joi.object({
        type: Joi.string().default("Point"),
        coordinates: Joi.array()
          .length(2)
          .items(Joi.number())
      }),
      notes: Joi.string(),
      tags: Joi.array().items(Joi.string())
    }),
    params: {
github hack4impact-uiuc / life-after-hate / backend / routes / api / resources.js View on Github external
})
);

// edit resource
router.put(
  "/:resource_id",
  requireAdminStatus,
  celebrate({
    body: Joi.object().keys({
      companyName: Joi.string(),
      contactName: Joi.string(),
      contactPhone: Joi.string(),
      contactEmail: Joi.string(),
      description: Joi.string(),
      address: Joi.string(),
      location: Joi.object({
        type: Joi.string().default("Point"),
        coordinates: Joi.array()
          .length(2)
          .items(Joi.number())
      }),
      notes: Joi.string(),
      tags: Joi.array().items(Joi.string())
    }),
    params: {
      resource_id: Joi.objectId().required()
    }
  }),
  errorWrap(async (req, res) => {
    const data = req.body;
    const resourceId = req.params.resource_id;
github hack4impact-uiuc / life-after-hate / backend / routes / api / users.js View on Github external
});
    await newUser.save();
    res.json({
      code: 200,
      message: "User Successfully Created",
      success: true
    });
  })
);

// set role
router.put(
  "/:user_id/role",
  requireAdminStatus,
  celebrate({
    body: Joi.object().keys({
      firstName: Joi.string(),
      lastName: Joi.string(),
      oauthId: Joi.string(),
      propicUrl: Joi.string(),
      isApproved: Joi.boolean(),
      role: Joi.string().required(),
      location: Joi.string(),
      email: Joi.string()
    })
  }),
  errorWrap(async (req, res) => {
    const data = req.body;
    const userId = req.params.user_id;

    const user = await User.findByIdAndUpdate(
      userId,
github jmbl1685 / express-restapi-es6 / models / value / value.validate.js View on Github external
'use strict'

import { Joi, celebrate } from 'celebrate'

const { body, params, query, headers } = {
    body: Joi.object().keys({
        id: Joi.string().required(),
        value: Joi.string().required()
    }),
    params: Joi.object({
        id: Joi.string().alphanum().optional()
    }).unknown(),
    query: {

    },
    headers: Joi.object({

    }).unknown()
}

export default {
    BODY: celebrate({ body }),
    PARAMS: celebrate({ params }),
    BODY_AND_PARAMS: celebrate({ body, params })
}
github jmbl1685 / express-restapi-es6 / models / value / value.validate.js View on Github external
'use strict'

import { Joi, celebrate } from 'celebrate'

const { body, params, query, headers } = {
    body: Joi.object().keys({
        id: Joi.string().required(),
        value: Joi.string().required()
    }),
    params: Joi.object({
        id: Joi.string().alphanum().optional()
    }).unknown(),
    query: {

    },
    headers: Joi.object({

    }).unknown()
}

export default {
    BODY: celebrate({ body }),
github santiq / bulletproof-nodejs / src / api / routes / auth.ts View on Github external
logger.debug('Calling Sign-Up endpoint with body: %o', req.body )
      try {
        const authServiceInstance = Container.get(AuthService);
        const { user, token } = await authServiceInstance.SignUp(req.body as IUserInputDTO);
        return res.status(201).json({ user, token });
      } catch (e) {
        logger.error('🔥 error: %o', e);
        return next(e);
      }
    },
  );

  route.post(
    '/signin',
    celebrate({
      body: Joi.object({
        email: Joi.string().required(),
        password: Joi.string().required(),
      }),
    }),
    async (req: Request, res: Response, next: NextFunction) => {
      const logger = Container.get('logger');
      logger.debug('Calling Sign-In endpoint with body: %o', req.body)
      try {
        const { email, password } = req.body;
        const authServiceInstance = Container.get(AuthService);
        const { user, token } = await authServiceInstance.SignIn(email, password);
        return res.json({ user, token }).status(200);
      } catch (e) {
        logger.error('🔥 error: %o',  e );
        return next(e);
      }