feat(v1:vehicles): Adding vehicles search by company_name and filters
This commit is contained in:
@@ -448,6 +448,7 @@ __This endpoint is only valid for carriers.__
|
|||||||
- state,
|
- state,
|
||||||
- status,
|
- status,
|
||||||
- destino
|
- destino
|
||||||
|
- $sort[ field ] : -1/1 ; Sort result by field name
|
||||||
- `GET /global/find` : Find a list of elements (from all the system) with any of the following fields:
|
- `GET /global/find` : Find a list of elements (from all the system) with any of the following fields:
|
||||||
- company, (company id)
|
- company, (company id)
|
||||||
- categories,
|
- categories,
|
||||||
@@ -464,6 +465,9 @@ __This endpoint is only valid for carriers.__
|
|||||||
- state,
|
- state,
|
||||||
- status,
|
- status,
|
||||||
- destino
|
- destino
|
||||||
|
- company_name[$regex] : Regex string to find company_name
|
||||||
|
- company_name[$options] : Regex options from MongoDB filter description
|
||||||
|
- $sort[ field ] : -1/1 ; Sort result by field name
|
||||||
- `POST /new` : Creates a new element.
|
- `POST /new` : Creates a new element.
|
||||||
- `PATCH /:id` : Updates data from specific element.
|
- `PATCH /:id` : Updates data from specific element.
|
||||||
- `DELETE /:id` : Delete element from company. Returns the element data.
|
- `DELETE /:id` : Delete element from company. Returns the element data.
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"description": "ETA API",
|
"description": "ETA API",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node src/",
|
"start": "nodemon src/",
|
||||||
"dev": "nodemon src/",
|
"dev": "nodemon src/",
|
||||||
"test": "mocha test/lib/handlers/proposals"
|
"test": "mocha test/lib/handlers/proposals"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ function getAndFilterList( query ){
|
|||||||
} = query;
|
} = query;
|
||||||
|
|
||||||
if( company ) { filter_list.push({ company }); }
|
if( company ) { filter_list.push({ company }); }
|
||||||
if( company_name ) { filter_list.push({ company_name }); }
|
if( company_name ) { filter_list.push({ company_name : company_name }); }
|
||||||
if( is_available ) { filter_list.push({ is_available }); }
|
if( is_available ) { filter_list.push({ is_available }); }
|
||||||
if( categories ) { filter_list.push({ categories }); }
|
if( categories ) { filter_list.push({ categories }); }
|
||||||
if( active_load ) { filter_list.push({ active_load }); }
|
if( active_load ) { filter_list.push({ active_load }); }
|
||||||
@@ -56,6 +56,7 @@ function getAndFilterList( query ){
|
|||||||
|
|
||||||
async function findElements( companyId , query ){
|
async function findElements( companyId , query ){
|
||||||
const { page, elements } = getPagination( query );
|
const { page, elements } = getPagination( query );
|
||||||
|
const { $sort } = query;
|
||||||
const andFilterList = getAndFilterList( query );
|
const andFilterList = getAndFilterList( query );
|
||||||
let filter;
|
let filter;
|
||||||
if( andFilterList ){
|
if( andFilterList ){
|
||||||
@@ -64,7 +65,7 @@ async function findElements( companyId , query ){
|
|||||||
}else{
|
}else{
|
||||||
filter = { company : companyId };
|
filter = { company : companyId };
|
||||||
}
|
}
|
||||||
const { total , limit, skip, data } = await generic.getList( page , elements, filter );
|
const { total , limit, skip, data } = await generic.getList( page , elements, filter, null, $sort );
|
||||||
return {
|
return {
|
||||||
total,
|
total,
|
||||||
limit,
|
limit,
|
||||||
@@ -75,6 +76,7 @@ async function findElements( companyId , query ){
|
|||||||
|
|
||||||
async function findGlobalElements( query ){
|
async function findGlobalElements( query ){
|
||||||
const { page, elements } = getPagination( query );
|
const { page, elements } = getPagination( query );
|
||||||
|
const { $sort } = query;
|
||||||
const andFilterList = getAndFilterList( query );
|
const andFilterList = getAndFilterList( query );
|
||||||
let filter = null;
|
let filter = null;
|
||||||
|
|
||||||
@@ -84,7 +86,7 @@ async function findGlobalElements( query ){
|
|||||||
filter = null;
|
filter = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { total , limit, skip, data } = await generic.getList( page , elements, filter );
|
const { total , limit, skip, data } = await generic.getList( page , elements, filter, null, $sort );
|
||||||
return {
|
return {
|
||||||
total,
|
total,
|
||||||
limit,
|
limit,
|
||||||
|
|||||||
Reference in New Issue
Block a user