How to use the celebrate.Joi.string 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 / users.js View on Github external
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,
      { $set: { role: data.role } },
      { new: true }
    );
github hack4impact-uiuc / life-after-hate / backend / routes / api / users.js View on Github external
);

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

    const user = await User.findByIdAndUpdate(
      userId,
      { $set: { isApproved: true } },
      { new: true }
    );
    const ret = user
      ? {
          code: 200,
          message: "User Approved Successfully",
          success: true
        }
github hack4impact-uiuc / life-after-hate / backend / routes / api / users.js View on Github external
});
  })
);

// create new user
router.post(
  "/",
  requireAdminStatus,
  celebrate({
    body: Joi.object().keys({
      firstName: Joi.string().required(),
      lastName: Joi.string().required(),
      oauthId: Joi.string().required(),
      propicUrl: Joi.string(),
      isApproved: Joi.boolean().default(false),
      role: Joi.string().required(),
      location: Joi.string().required(),
      email: Joi.string().required()
    })
  }),
  errorWrap(async (req, res) => {
    const data = req.body;
    const newUser = new User({
      firstName: data.firstName,
      lastName: data.lastName,
      oauthId: data.oauthId,
      propicUrl: data.propicUrl,
      role: data.role,
      location: data.location,
      email: data.email
    });
    await newUser.save();
github hack4impact-uiuc / life-after-hate / backend / routes / api / resources.js View on Github external
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: {
      resource_id: Joi.objectId().required()
github hack4impact-uiuc / life-after-hate / backend / routes / api / resources.js View on Github external
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: {
      resource_id: Joi.objectId().required()
    }
  }),
  errorWrap(async (req, res) => {
    const data = req.body;
github hack4impact-uiuc / life-after-hate / backend / routes / api / resources.js View on Github external
success: true
    });
  })
);

// get list of resources filtered by location radius
router.get(
  "/filter",
  requireVolunteerStatus,
  celebrate({
    query: {
      radius: Joi.number(),
      address: Joi.string(),
      keyword: Joi.string(),
      customWeights: Joi.array(),
      tag: Joi.string()
    }
  }),
  errorWrap(async (req, res) => {
    const { radius, address, keyword, customWeights, tag } = req.query;
    let resources = await Resource.find({});

    const latlng = await resourceUtils.addressToLatLong(address);
    const lat = latlng.lat;
    const long = latlng.lng;

    if (radius && lat && long) {
      const radiusOfEarth = 3963.2; // in miles
      resources = await Resource.find({
        location: {
          $geoWithin: { $centerSphere: [[long, lat], radius / radiusOfEarth] }
        }
github hack4impact-uiuc / life-after-hate / backend / routes / api / resources.js View on Github external
res.json({
      code: 200,
      result: resources,
      success: true
    });
  })
);

// get list of resources filtered by location radius
router.get(
  "/filter",
  requireVolunteerStatus,
  celebrate({
    query: {
      radius: Joi.number(),
      address: Joi.string(),
      keyword: Joi.string(),
      customWeights: Joi.array(),
      tag: Joi.string()
    }
  }),
  errorWrap(async (req, res) => {
    const { radius, address, keyword, customWeights, tag } = req.query;
    let resources = await Resource.find({});

    const latlng = await resourceUtils.addressToLatLong(address);
    const lat = latlng.lat;
    const long = latlng.lng;

    if (radius && lat && long) {
      const radiusOfEarth = 3963.2; // in miles
      resources = await Resource.find({
github hack4impact-uiuc / life-after-hate / backend / routes / api / users.js View on Github external
res.status(ret.code).json(ret);
  })
);

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

    const user = await User.findByIdAndUpdate(
      userId,
      { $set: { isApproved: true } },
      { new: true }
    );
    const ret = user
      ? {
          code: 200,
          message: "User Approved Successfully",
github hack4impact-uiuc / life-after-hate / backend / routes / api / users.js View on Github external
})
);

// 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,
      { $set: { role: data.role } },
      { new: true }
    );
    const ret = user
      ? {
          code: 200,
          message: "User Role Updated Successfully",
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 }),