Last active
September 5, 2020 05:56
-
-
Save julioflima/da7f673b4e1f3b010f7239170b43d56f to your computer and use it in GitHub Desktop.
DTO using Joi exporting schemes to Celebrate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Segments, Joi } = require('celebrate'); | |
module.exports = class SensorDTO { | |
static getSensorTimestamps() { | |
return { | |
[Segments.QUERY]: Joi.object().keys({ | |
name: Joi.string().required(), | |
}), | |
}; | |
} | |
static getSensor() { | |
return { | |
[Segments.QUERY]: Joi.object().keys({ | |
name: Joi.string().required(), | |
}), | |
}; | |
} | |
static postSensor() { | |
return { | |
[Segments.QUERY]: Joi.object().keys({ | |
name: Joi.string().required(), | |
}), | |
[Segments.BODY]: Joi.object().keys({ | |
value: Joi.number().required(), | |
timestamp: Joi.number().integer().required(), | |
}), | |
}; | |
} | |
static deleteSensor() { | |
return { | |
[Segments.QUERY]: Joi.object().keys({ | |
name: Joi.string().required(), | |
}), | |
[Segments.BODY]: Joi.object().keys({ | |
timestamp: Joi.number().integer().required(), | |
}), | |
}; | |
} | |
static ruleDate() { | |
return { | |
[Segments.QUERY]: Joi.object().keys({ | |
name: Joi.string().required(), | |
}), | |
[Segments.BODY]: Joi.object().keys({ | |
value: Joi.number().required(), | |
date: Joi.string().required(), | |
timestamp: Joi.number().integer().required(), | |
}), | |
}; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment