Merge pull request #233 from RubenPX/filter-in-out-trades

Filter in out trades from lots selector
This commit is contained in:
Santiago L 2022-05-06 07:58:11 +02:00 committed by GitHub
commit 7177b0fbfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 2 deletions

View File

@ -9,6 +9,12 @@ dags-with-materialized-paths-using-postgres-ltree/>`_ you have
a low-level technical implementation of how lots and their
relationships are mapped.
Getting lots
************
You can get lots list by ``GET /lots/``
There are one optional filter ``type``, only works with this 3 values ``temporary``, ``incoming`` and ``outgoing``
Create lots
***********
You create a lot by ``POST /lots/`` a `JSON Lot object <https://
@ -28,7 +34,6 @@ And for devices is all the same:
``POST /lots/<parent-lot-id>/devices/?id=<device-id-1>&id=<device-id-2>``;
idem for removing devices.
Sharing lots
************
Sharing a lot means giving certain permissions to users, like reading

View File

@ -29,6 +29,7 @@ class LotView(View):
"""
format = EnumField(LotFormat, missing=None)
search = f.Str(missing=None)
type = f.Str(missing=None)
def post(self):
l = request.get_json()
@ -88,6 +89,7 @@ class LotView(View):
else:
query = Lot.query
query = self.visibility_filter(query)
query = self.type_filter(query, args)
if args['search']:
query = query.filter(Lot.name.ilike(args['search'] + '%'))
lots = query.paginate(per_page=6 if args['search'] else query.count())
@ -104,6 +106,21 @@ class LotView(View):
Lot.owner_id == g.user.id))
return query
def type_filter(self, query, args):
lot_type = args.get('type')
# temporary
if lot_type == "temporary":
return query.filter(Lot.trade == None)
if lot_type == "incoming":
return query.filter(Lot.trade and Trade.user_to == g.user)
if lot_type == "outgoing":
return query.filter(Lot.trade and Trade.user_from == g.user)
return query
def query(self, args):
query = Lot.query.distinct()
return query

View File

@ -4,7 +4,7 @@ const Api = {
* @returns get lots
*/
async get_lots() {
const request = await this.doRequest(API_URLS.lots, "GET", null);
const request = await this.doRequest(`${API_URLS.lots}?type=temporary`, "GET", null);
if (request != undefined) return request.items;
throw request;
},