import * as Joi from 'joi' ; import { ROLE , FIELDNAME , STATUS } from '@enums' ; import { list } from '@utils/enum.util' ; import { email , id , pagination , username , password , file } from '@schemas' ; const listUsers = { query : Joi . object ( { page : pagination ( 'page' ) , perPage : pagination ( 'perPage' ) , username : username ( ) , email : email ( ) , role : Joi . any ( ) . valid ( ... list ( ROLE ) ) , status : Joi . any ( ) . valid ( ... list ( STATUS ) ) , website : Joi . string ( ) . uri ( ) } ) } ; const getUser = { params : Joi . object ( { userId : id ( ) } ) } ; const createUser = { body : Joi . object ( { username : username ( ) . required ( ) , email : email ( ) . required ( ) , password : password ( 'user' ) . required ( ) , status : Joi . any ( ) . valid ( ... list ( STATUS ) ) . optional ( ) , avatar : file ( FIELDNAME . avatar ) . allow ( null ) , role : Joi . any ( ) . valid ( ... list ( ROLE ) ) } ) } ; const replaceUser = { params : Joi . object ( { userId : id ( ) } ) , body : Joi . object ( { username : username ( ) . required ( ) , email : email ( ) . required ( ) , password : password ( 'user' ) . required ( ) , status : Joi . any ( ) . valid ( ... list ( STATUS ) ) . required ( ) , avatar : file ( FIELDNAME . avatar ) . allow ( null ) , role : Joi . any ( ) . valid ( ... list ( ROLE ) ) . required ( ) } ) } ; const updateUser = { params : Joi . object ( { userId : id ( ) , } ) , body : Joi . object ( { username : username ( ) , email : email ( ) , isUpdatePassword : Joi . boolean ( ) . optional ( ) , password : password ( 'user' ) , passwordConfirmation : Joi . when ( 'password' , { is : password ( 'user' ) . required ( ) , then : Joi . any ( ) . equal ( Joi . ref ( 'password' ) ) . required ( ) . label ( 'Confirm password' ) . messages ( { 'any.only' : '{{#label}} does not match' } ) , otherwise : Joi . optional ( ) } ) , passwordToRevoke : Joi . when ( 'isUpdatePassword' , { is : Joi . any ( ) . equal ( true ) . required ( ) , then : password ( 'user' ) . required ( ) , otherwise : Joi . optional ( ) } ) , status : Joi . any ( ) . valid ( ... list ( STATUS ) ) . optional ( ) , avatar : file ( FIELDNAME . avatar ) . allow ( null ) , role : Joi . any ( ) . valid ( ... list ( ROLE ) ) } ) } ; const removeUser = { params : Joi . object ( { userId : id ( ) } ) } ; export { listUsers , getUser , createUser , replaceUser , updateUser , removeUser } ;