sequelize-middleware/rules/Cars.js

131 lines
2.5 KiB
JavaScript
Raw Normal View History

import Joi from "@hapi/joi";
const Rules = {
model: "Cars",
crud: {
read: ["admin", "user"],
write: ["admin"],
edit: ["admin"],
delete: ["admin"]
},
includes: [
{
collection: "Brand",
requiredRole: ["admin", "user"]
2020-02-13 22:36:14 +01:00
},
{
collection: "Colors"
}
],
format: {
user: {
id: "id",
model: "model",
Brand: {
name: "name"
}
}
},
itemId: "carId",
validate: {
create: Joi.object({
name: Joi.string().required(),
2020-02-13 22:36:14 +01:00
colorsId: Joi.array().items(Joi.number().integer()),
active: Joi.boolean(),
year: Joi.number()
.integer()
.required(),
brandId: Joi.number().integer()
}),
update: Joi.object({
2020-02-13 22:36:14 +01:00
name: Joi.string(),
year: Joi.number().integer(),
colorsId: Joi.array().items(Joi.number().integer())
}),
item: Joi.object({
carId: Joi.number().required()
}),
list: Joi.object({
weirdfilter: Joi.string(),
"name.lk": Joi.string(),
name: Joi.string(),
year: Joi.number().integer(),
"year.lte": Joi.number().integer(),
"year.gte": Joi.number().integer(),
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("year.lte", "year.gte")
.with("year.gte", "year.lte")
.with("limit", "page")
.with("page", "limit")
.with("sort", "order")
.with("order", "sort")
},
restrictOn: {
list: [
{
roles: ["user"],
type: "raw",
field: "active",
value: "true"
}
],
item: [
{
roles: ["user"],
type: "raw",
field: "active",
value: "true"
}
]
},
override: {
list: {
filters: {
weirdfilter: {
$or: [
{
active: true
},
{
year: 2003
}
]
},
"name.lk": {
name: {
$like: "%_TERM_%"
}
},
"year.lte": {
year: {
$lte: "_TERM_"
}
},
"year.gte": {
year: {
$gte: "_TERM_"
}
}
}
}
2020-02-13 22:36:14 +01:00
},
belongsToMany: {
colorsId: "Colors"
}
};
export default Rules;