You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We want to make some changes in the next version. Defining a resource in the following way should be clearer. If you have any suggestions, please comment on this issue.
import{Resource,queryable,action}from'node-odata';importcreateErrorfrom'http-errors';constbookInfo={title: String,price: Number,};functionasynccheckUserAuth(req){// Check the permissions of the user roleconstuser=awaitUser.get(req.query.id);if(user.role==='guest')returnfalse;}// Resource contains five query methods: `list/get/create/update/remove`, you can selectively cover it as needed// In addition, you can also declare the action to do some special operations, Use `@action` decoratorexportdefaultclassBookextendsResource{constructor(){super('book',bookInfo);}// `queryable` is used to make some restrictions on the list request,// such as default pageSize / maxTop / allowed orderby field.
@queryable({pageSize: 10,maxTop: 50})asynclist(next){// You can manually call the query method `next()`, so you can do something before or after of the query.awaitnext();}asyncget(next){// Check if resource meets the requirementsconstentity=req.body;if(entity.title===undefined){throwcreateError.UnprocessableEntity({...});}constentity=awaitnext();}// If you do not need to do anything, you can not declare the method// async create(next) {// next();// }
@checkUserAuthasyncremove(next){next();}
@checkUserAuthasyncupdate(next){next();}
@action['/50off']
@checkUserAuthasynchalfPriceAction(id,query){constentity=awaitBook.findOneById(id);entity.price/=2;awaitentity.save();returnentity;}}
The text was updated successfully, but these errors were encountered:
Here are the features, that current version doesn't has, and which I have to implement bypassing node-odata:
Case insensitive search in many fields at once.
Similar to this: $filter=substringof('foo',article) eq true or substringof('foo',mail) eq true
Async calls inside .post.before() or so.
I need to perform different async mongo calls while processing the requests. It will be great to have possibility to do return next() inside before()
We want to make some changes in the next version. Defining a resource in the following way should be clearer. If you have any suggestions, please comment on this issue.
The text was updated successfully, but these errors were encountered: