import joi from '@hapi/joi'; import globals from "../../globals"; export default class UserValidate { // validate input for user static input (data) { return joi.object({ name: joi.string() .alphanum() .lowercase() .required(), email: joi.string() .email({minDomainSegments: 2}) .lowercase() .required(), pass: joi.string() .pattern(new RegExp('^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[!"#$%&\'()*+,-.\\/:;<=>?@[\\]^_`{|}~])(?=\\S+$).{8,}$')) .required(), level: joi.string() .valid(...globals.levels) .required(), location: joi.string() .alphanum() .required(), device_name: joi.string() .required() }).validate(data); } static output (data) { // validate output from database for needed properties, strip everything else return joi.object({ _id: joi.any(), name: joi.string(), email: joi.string(), level: joi.string(), location: joi.string(), device_name: joi.string() }).validate(data, {stripUnknown: true}).value; } }