126 lines
2.3 KiB
JavaScript
126 lines
2.3 KiB
JavaScript
|
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"]
|
||
|
// },
|
||
|
// {
|
||
|
// collection: "Colors",
|
||
|
// requiredRole: ["admin", "user"]
|
||
|
}
|
||
|
],
|
||
|
format: {
|
||
|
user: {
|
||
|
id: "id",
|
||
|
model: "model",
|
||
|
Brand: {
|
||
|
name: "name"
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
itemId: "carId",
|
||
|
validate: {
|
||
|
create: Joi.object({
|
||
|
name: Joi.string().required(),
|
||
|
active: Joi.boolean(),
|
||
|
year: Joi.number()
|
||
|
.integer()
|
||
|
.required(),
|
||
|
brandId: Joi.number().integer()
|
||
|
}),
|
||
|
update: Joi.object({
|
||
|
name: Joi.string()
|
||
|
}),
|
||
|
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_"
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
export default Rules;
|