Releases: nicgirault/express-crud-router
Releases · nicgirault/express-crud-router
v8.1.0
v8.0.2
v8.0.1
v8.0.0
v7.0.1
v7.0.0
7.0.0 (2023-08-19)
Code Refactoring
- force consistency between getList, getOne and search (f4e9b0a)
Features
- add additionalFields option to populate computed fields (8d759be)
- support asynchronous custom filters (fa18d2f)
BREAKING CHANGES
getOne
andsearch
are not anymore necessary
as they are deduced fromgetList
handler (renamedget
).
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}%` } },
+ ],
+ })
+ }
}
})
- custom filter handlers do not anymore return the value
associated to the key of the given handler. Instead the returned value must be an object that will be merged in the filters passed to the getter handler. In order to keep the same behavior for an existing
custom filter, the following modification must be implemented:
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,
}
},
}