$ 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
// comments-model.js - A mongoose model// // See http://mongoosejs.com/docs/models.html// for more of what you can do here.constcommentsValidators=require('../validators/comments.validators.js');const {createModelFromJoi} =require('feathers-mongoose-casl');module.exports=function (app) {returncreateModelFromJoi(app,'comments', commentsValidators);};
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
// Initializes the `comments` service on path `/comments`const {createService} =require('feathers-mongoose-casl');constcreateModel=require('../../models/comments.model');consthooks=require('./posts.hooks');module.exports=function (app) {constModel=createModel(app);constpaginate=app.get('paginate');constoptions= { Model, paginate, serviceRules: [ {'actions': ['manage'],'roles': ['admin']}, {'actions': ['read'], anonymousUser:true}, ] };// Initialize our service with any options it requiresapp.use('/comments',createService(options));// Get our initialized service so that we can register hooksconstservice=app.service('comments');service.hooks(hooks);};