Update posts service
1 - Inside the src/validators folder create this file posts.validators.js
const {Joi} = require('feathers-mongoose-casl');
const getJoiObject = function(withRequired){
const required = withRequired ? 'required' : 'optional';
return Joi.object({
author: Joi.objectId().meta({
type: 'ObjectId',
ref: 'users',
displayKey: 'email'
})[required](),
title: Joi.string().min(5)[required]().meta({
dashboard: {
label: 'Post title',
inputProps: JSON.stringify({style: {background: 'red'}})
}
}),
body: Joi.string()[required](),
rating: Joi.number().max(5).meta({
dashboard: {
hideOnUpdate: true,
hideOnCreate: true,
}
}),
image: Joi.objectId().meta({
type: 'ObjectId',
ref: 'files',
displayKey: 'name'
})
});
};
module.exports = getJoiObject;2 - Update Posts model
3 - Update posts.service
Add serviceRules to service options
Remove authenticate from posts.hooks
Last updated
Was this helpful?