How to use the joi.date function in joi

To help you get started, we’ve selected a few joi 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 glennjones / hapi-swagger / test / properties.js View on Github external
lab.test('parse type date', (done) => {

        expect(properties.parseProperty('x', Joi.date())).to.equal({ 'type': 'string', 'format': 'date' });

        /*  not yet 'x',
        date.min(date)
        date.max(date)
        date.format(format)
        date.iso()
        */
        done();
    });
github yegor-sytnyk / contoso-express / server / src / controllers / departmentController.ts View on Github external
async function saveDepartment(req, res) {
    try {
        let data = req.body.department;

        // check if budget is empty
        if (!data.budget) data.budget = 0;

        let schema = {
            id: Joi.number(),
            name: Joi.string().required(),
            budget: Joi.number().required(),
            startDate: Joi.date(),
            instructorId: Joi.number().required()
        };

        let result = null;

        let department = await helper.loadSchema(data, schema);

        if (department.id) {
            result = await departmentRepository.updateDepartment(department);
        } else {
            result = await departmentRepository.addDepartment(department);
        }

        department = await departmentRepository.getDepartmentById(result.id);

        return helper.sendData({data: department}, res);
github kartikayg / StatusPage / incidents-service / src / entities / incident_types / scheduled.js View on Github external
import incidentUpdate from '../incident-update';

const schema = Joi.object({

  components: Joi.array()
    .required(),

  // scheduled incident related fields
  scheduled_status: Joi.string()
    .only(['scheduled', 'in_progress', 'completed', 'cancelled'])
    .required(),
  scheduled_start_time: Joi.date()
    .iso()
    .required(),
  scheduled_end_time: Joi.date()
    .iso()
    .required()
    .min(Joi.ref('scheduled_start_time')),
  scheduled_auto_status_updates: Joi.boolean()
    .required(),
  scheduled_auto_updates_send_notifications: Joi.boolean()
    .required(),

  // add incident updates
  updates: Joi.array()
    .required()
    .unique('id')
    .min(1)
    .items(Object.assign({}, incidentUpdate.schema, {
      status: Joi.string()
        .required()
github vinli / vinli-node / lib / rule.js View on Github external
Rule.prototype.events = function(_options) {
    var self = this;

    var deviceId = this.deviceId || (_options || {}).deviceId;
    if (_options) {
      delete _options.deviceId;
    }

    Hoek.assert(deviceId, 'The Rule must have deviceId set internally or passed in the options when loading events');

    _options = Hoek.applyToDefaults({ limit: 20, objectId: this.id, type: 'rule-*' }, _options || {});
    Joi.assert(_options, {
      limit: Joi.number().integer().min(0).max(100),
      since: Joi.date(),
      until: Joi.date(),
      type: Joi.string(),
      objectId: Joi.string(),
      objectType: Joi.string()
    });

    return client.get(
      'event',
      'devices/' + deviceId + '/events',
      _options).then(function(resp) {
        return Utils.streamListResponse(resp, 'events', self.events, self);
      });
  };
github zmts / supra-api-nodejs / models / post / baseSchema.js View on Github external
const joi = require('joi')

module.exports = {
  title: joi.string().min(3).max(20).required(),
  content: joi.string().min(3).max(5000),
  createdAt: joi.date(),
  updatedAt: joi.date()
}
github kartikayg / StatusPage / notification-service / src / entities / subscriber.js View on Github external
*/

import Joi from 'joi';

import { schema as emailSchema } from './subscriber/email';
import { schema as webhookSchema } from './subscriber/webhook';

import { validTypes } from '../repositories/subscription';

const prefix = 'SB';

const schema = Joi.object({
  id: Joi.string()
    .regex(/^SB.+$/)
    .required(),
  created_at: Joi.date()
    .iso()
    .required(),
  updated_at: Joi.date()
    .iso()
    .required(),

  type: Joi.string()
    .only(validTypes)
    .required(),

  is_confirmed: Joi.boolean()
    .required(),

  components: Joi.array()
    .items(Joi.string())
    .unique()
github jedireza / aqua / server / models / status-entry.js View on Github external
'use strict';
const Joi = require('joi');
const MongoModels = require('mongo-models');


class StatusEntry extends MongoModels {}


StatusEntry.schema = Joi.object().keys({
    id: Joi.string().required(),
    name: Joi.string().required(),
    timeCreated: Joi.date().required(),
    userCreated: Joi.object().keys({
        id: Joi.string().required(),
        name: Joi.string().lowercase().required()
    }).required()
});


module.exports = StatusEntry;
github mtharrison / hapi.js-in-action / CH07 - Creating Modular Applications with Plugins / 7.2 / 7.2.4 / plugins / receive / index.js View on Github external
exports.register = function (server, options, next) {

    server.route({
        config: {
            validate: {
                payload: {
                    code: Joi.string().required(),
                    lat: Joi.number().required(),
                    lng: Joi.number().required(),
                    alt: Joi.number().required(),
                    timestamp: Joi.date().required()
                }
            }
        },
        method: 'POST',
        path: '/api',
        handler: function (request, reply) {

            server.methods.database.addPing(request.payload, reply);
        }
    });

    next();
};
github elastic / kibana / x-pack / plugins / monitoring / server / routes / api / v1 / kibana / overview.js View on Github external
/**
   * Kibana overview (metrics)
   */
  server.route({
    method: 'POST',
    path: '/api/monitoring/v1/clusters/{clusterUuid}/kibana',
    config: {
      validate: {
        params: Joi.object({
          clusterUuid: Joi.string().required()
        }),
        payload: Joi.object({
          ccs: Joi.string().optional(),
          timeRange: Joi.object({
            min: Joi.date().required(),
            max: Joi.date().required()
          }).required()
        })
      }
    },
    async handler(req) {
      const config = server.config();
      const ccs = req.payload.ccs;
      const clusterUuid = req.params.clusterUuid;
      const kbnIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_KIBANA, ccs);

      try {
        const [ clusterStatus, metrics ] = await Promise.all([
          getKibanaClusterStatus(req, kbnIndexPattern, { clusterUuid }),
          getMetrics(req, kbnIndexPattern, metricSet),
        ]);
github jedireza / aqua / server / models / user.js View on Github external
username: Joi.string().token().lowercase().required(),
    password: Joi.string(),
    email: Joi.string().email().lowercase().required(),
    roles: Joi.object({
        admin: Joi.object({
            id: Joi.string().required(),
            name: Joi.string().required()
        }),
        account: Joi.object({
            id: Joi.string().required(),
            name: Joi.string().required()
        })
    }),
    resetPassword: Joi.object({
        token: Joi.string().required(),
        expires: Joi.date().required()
    }),
    timeCreated: Joi.date()
});


User.indexes = [
    { key: { username: 1, unique: 1 } },
    { key: { email: 1, unique: 1 } }
];


module.exports = User;