fix(crud): DELETE plural

This commit is contained in:
Mahdi Dibaiee 2016-05-07 10:37:51 +04:30
parent 973f63640c
commit 193aec9619
2 changed files with 20 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "hapi-sequelize-crud", "name": "hapi-sequelize-crud",
"version": "2.0.6", "version": "2.0.7",
"description": "Hapi plugin that automatically generates RESTful API for CRUD", "description": "Hapi plugin that automatically generates RESTful API for CRUD",
"main": "build/index.js", "main": "build/index.js",
"config": { "config": {

View File

@ -121,6 +121,25 @@ export const destroy = (server, model) => {
}) })
} }
export const destroyAll = (server, model) => {
server.route({
method: 'DELETE',
path: `${prefix}/${model._plural}`,
@error
async handler(request, reply) {
const include = parseInclude(request);
const where = parseWhere(request);
const list = await model.findAll({ where });
await* list.map(instance => instance.destroy());
reply(list.length === 1 ? list[0] : list);
}
})
}
export const destroyScope = (server, model) => { export const destroyScope = (server, model) => {
let scopes = Object.keys(model.options.scopes); let scopes = Object.keys(model.options.scopes);