How to use joi-objectid - 3 common examples

To help you get started, we’ve selected a few joi-objectid 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 huridocs / uwazi / app / api / entities / routes.js View on Github external
import Joi from 'joi';
import objectId from 'joi-objectid';
import entities from './entities';
import templates from '../templates/templates';
import thesauris from '../thesauris/thesauris';
import needsAuthorization from '../auth/authMiddleware';
import { validation } from '../utils';
import { saveSchema, metadataSchema, iconSchema } from './endpointSchema';

Joi.objectId = objectId(Joi);

export default (app) => {
  app.post(
    '/api/entities',
    needsAuthorization(['admin', 'editor']),
    validation.validateRequest(saveSchema),
    (req, res, next) => entities.save(req.body, { user: req.user, language: req.language })
    .then((response) => {
      res.json(response);
      return templates.getById(response.template);
    })
    .then(template => thesauris.templateToThesauri(template, req.language, req.user))
    .then((templateTransformed) => {
      req.io.sockets.emit('thesauriChange', templateTransformed);
    })
    .catch(next)
github IgorMCesar / react-express-mongo-boilerplate / src / server / graphql / validators / user.js View on Github external
import Joi from 'joi';
import JoiObjectId from 'joi-objectid';

Joi.objectId = JoiObjectId(Joi);

const email = Joi.string()
  .min(3)
  .max(255)
  .email()
  .required()
  .label('Email');

const username = Joi.string()
  .alphanum()
  .min(4)
  .max(30)
  .required()
  .label('Username');

const name = Joi.string()
github huridocs / uwazi / app / api / utils / validateRequest.js View on Github external
/** @format */

import Joi from 'joi';
import objectId from 'joi-objectid';
import createError from './Error';

Joi.objectId = objectId(Joi);

export default (schema, propTovalidate = 'body') => (req, _res, next) => {
  const result = Joi.validate(req[propTovalidate], schema);
  if (result.error) {
    next(createError(result.error.toString(), 400));
  }

  if (!result.error) {
    next();
  }
};

joi-objectid

A MongoDB ObjectId validator for Joi

MIT
Latest version published 3 years ago

Package Health Score

47 / 100
Full package analysis

Popular joi-objectid functions

Similar packages