strapi-sanitizer
v1.0.5
Published
sanitizer for strapi
Downloads
8
Readme
strapi-sanitizer
It's util for sanitizing object/array by custom models
Install
$ npm i strapi-sanitizer
or
$ yarn add strapi-sanitizer
Usage
const sanitizer = require('strapi-sanitizer')
module.exports = {
async find(ctx) {
const entity = await strapi.services.restaurant.find()
return sanitizer(entity, {
id: true,
name: true,
address: {
city: true,
street: true,
build: true,
},
menu: [
{
id: true,
type: true,
dishes: [
id: true,
price: {
uah: (v) => `${v} UAH`,
usd: (v) => `${v} USD`,
tax: true,
},
],
}
],
owner: 'info.fullname',
})
},
}
or
const sanitizer = require('strapi-sanitizer')
module.exports = {
async find(ctx) {
const entity = await strapi.services.restaurant.find()
return sanitizer(entity, 'Restaurant')
},
}
strapi-project/sanitizer/Restaurant.js
module.exports = {
id: true,
name: true,
address: {
city: true,
street: true,
build: true,
},
menu: [
{
id: true,
type: true,
dishes: [
id: true,
price: {
uah: (v) => `${v} UAH`,
usd: (v) => `${v} USD`,
tax: true,
},
],
}
],
owner: 'info.fullname',
}