sequelize-middleware/rules/Brands.js
2020-02-11 15:38:28 +01:00

69 lines
1.3 KiB
JavaScript

import Joi from "@hapi/joi";
const Rules = {
model: "Brands",
crud: {
read: ["admin", "user"],
write: ["admin"],
edit: ["admin"],
delete: ["admin"]
},
includes: [
{
collection: "Cars",
requiredRole: ["admin", "user"]
}
],
format: {
user: {
id: "id",
name: "name"
},
admin: {
id: "id",
name: "name",
created: "createdAt",
updated: "updatedAt",
Cars: {
id: "id",
name: "name",
year: "year",
created: "createdAt",
updated: "updatedAt"
}
}
},
itemId: "brandId",
validate: {
create: Joi.object({
name: Joi.string().required()
}),
update: Joi.object({
name: Joi.string()
}),
item: Joi.object({
brandId: Joi.number().required()
}),
list: Joi.object({
limit: Joi.number()
.integer()
.min(1)
.max(50),
page: Joi.number()
.integer()
.min(1),
sort: Joi.string()
.valid("id", "name", "createdAt", "updatedAt")
.only(),
order: Joi.string()
.valid("asc", "desc")
.only()
})
.with("limit", "page")
.with("page", "limit")
.with("sort", "order")
.with("order", "sort")
}
};
export default Rules;