Simply expose resource CRUD (Create Read Update Delete) routes for Express & Sequelize. Compatible with React Admin Simple Rest Data Provider
getOne
and search
are not anymore necessary
as they are deduced from getList
handler (renamed get
).
search definition must be handled thanks to filters option:crud('/admin/users', {
- search: async (q, limit) => {
- const { rows, count } = await User.findAndCountAll({
- limit,
- where: {
- [Op.or]: [
- { address: { [Op.iLike]: `${q}%` } },
- { zipCode: { [Op.iLike]: `${q}%` } },
- { city: { [Op.iLike]: `${q}%` } },
- ],
- },
- })
-
- return { rows, count }
},
+ {
+ filters: {
+ q: q => ({
+ [Op.or]: [
+ { address: { [Op.iLike]: `${q}%` } },
+ { zipCode: { [Op.iLike]: `${q}%` } },
+ { city: { [Op.iLike]: `${q}%` } },
+ ],
+ })
+ }
}
})
crud('/admin/users', sequelizeCrud(User), {
filters: {
email: value => ({
- [Op.iLike]: value,
+ email: {[Op.iLike]: value },
},
}),
},
})
Asynchronous custom filters are now supported:
const filters = {
categoryName: async value => {
const category = await Category.findOne({ name: value }).orFail()
// this object will be merged in filters given to the getter handler
return {
categoryId: category.id,
}
},
}