Create a new service
1- feathers generate service
$ feathers generate service
? What kind of service is it? Mongoose
? What is the name of the service? comments
? Which path should the service be registered on? /comments
? Does the service require authentication? No? Does the service require authentication? No We authentication all the services from app.hook
2- Create validator file
inside validators create comments.validators.js with this contnet
const {Joi} = require('feathers-mongoose-casl');
const getJoiObject = function(withRequired){
const required = withRequired ? 'required' : 'optional';
return Joi.object({
post: Joi.objectId().meta({ type: 'ObjectId', ref: 'roles' })[required](),
text: Joi.string()[required](),
});
};
module.exports = getJoiObject;3- Update comments.model.js
4- comments.service.js
replace feathers-mongoose with createService from feathers-mongoose-casl feathers-mongoose-casl.createService is a wrapper of feathers-mongoose but we add mongoose-to-swagger to let you see the schema inside swagger docs and we handle validation with joi
Before
After
Last updated
Was this helpful?