Skip to content

Commit 281af4a

Browse files
committed
remove filtering by id substring (only exact match support for now)
1 parent 85ab047 commit 281af4a

File tree

4 files changed

+60
-60
lines changed

4 files changed

+60
-60
lines changed

migrations/elasticsearch_sync.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,7 @@ function getRequestBody(indexName) {
209209
},
210210
},
211211
id: {
212-
type: 'string',
213-
index: 'not_analyzed',
212+
type: 'long',
214213
},
215214
members: {
216215
type: 'nested',

postman.json

Lines changed: 41 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"info": {
3-
"_postman_id": "97085cd7-b298-4f1c-9629-24af14ff5f13",
3+
"_postman_id": "4fc2b7cf-404a-4fd7-b6d2-4828a3994859",
44
"name": "tc-project-service",
55
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
66
},
@@ -1452,7 +1452,7 @@
14521452
"response": []
14531453
},
14541454
{
1455-
"name": "List projects with filters applied",
1455+
"name": "List projects with filters - type (exact)",
14561456
"request": {
14571457
"method": "GET",
14581458
"header": [
@@ -1466,7 +1466,7 @@
14661466
"raw": ""
14671467
},
14681468
"url": {
1469-
"raw": "{{api-url}}/v4/projects?filter=type%3Dgeneric",
1469+
"raw": "{{api-url}}/v4/projects?filter=type%3Dapp",
14701470
"host": [
14711471
"{{api-url}}"
14721472
],
@@ -1477,7 +1477,7 @@
14771477
"query": [
14781478
{
14791479
"key": "filter",
1480-
"value": "type%3Dgeneric"
1480+
"value": "type%3Dapp"
14811481
}
14821482
]
14831483
},
@@ -1486,10 +1486,21 @@
14861486
"response": []
14871487
},
14881488
{
1489-
"name": "List projects with filters - name, code, customer, manager",
1489+
"name": "List projects with filters - id (exact)",
14901490
"request": {
1491+
"method": "GET",
1492+
"header": [
1493+
{
1494+
"key": "Authorization",
1495+
"value": "Bearer {{jwt-token}}"
1496+
}
1497+
],
1498+
"body": {
1499+
"mode": "raw",
1500+
"raw": ""
1501+
},
14911502
"url": {
1492-
"raw": "{{api-url}}/v4/projects?filter=id%3D1*%26name%3Dtes*%26code=test*%26customer%3DDiya*%26manager=first*",
1503+
"raw": "{{api-url}}/v4/projects?filter=id%3D1",
14931504
"host": [
14941505
"{{api-url}}"
14951506
],
@@ -1500,34 +1511,30 @@
15001511
"query": [
15011512
{
15021513
"key": "filter",
1503-
"value": "id%3D1*%26name%3Dtes*%26code=test*%26customer%3DDiya*%26manager=first*",
1504-
"equals": true,
1505-
"description": ""
1514+
"value": "id%3D1"
15061515
}
1507-
],
1508-
"variable": []
1516+
]
15091517
},
1518+
"description": "List all the project with filters applied. The filter string should be url encoded. Default limit and offset is applicable"
1519+
},
1520+
"response": []
1521+
},
1522+
{
1523+
"name": "List projects with filters - name, code, customer, manager",
1524+
"request": {
15101525
"method": "GET",
15111526
"header": [
15121527
{
15131528
"key": "Authorization",
1514-
"value": "Bearer {{jwt-token}}",
1515-
"description": ""
1529+
"value": "Bearer {{jwt-token}}"
15161530
}
15171531
],
15181532
"body": {
15191533
"mode": "raw",
15201534
"raw": ""
15211535
},
1522-
"description": "List all the project with filters applied. The filter string should be url encoded. Default limit and offset is applicable"
1523-
},
1524-
"response": []
1525-
},
1526-
{
1527-
"name": "List projects with filters - id",
1528-
"request": {
15291536
"url": {
1530-
"raw": "{{api-url}}/v4/projects?filter=id%3D2",
1537+
"raw": "{{api-url}}/v4/projects?filter=id%3D1*%26name%3Dtes*%26code=test*%26customer%3DDiya*%26manager=first*",
15311538
"host": [
15321539
"{{api-url}}"
15331540
],
@@ -1538,32 +1545,28 @@
15381545
"query": [
15391546
{
15401547
"key": "filter",
1541-
"value": "id%3D2",
1542-
"equals": true,
1543-
"description": ""
1548+
"value": "id%3D1*%26name%3Dtes*%26code=test*%26customer%3DDiya*%26manager=first*"
15441549
}
1545-
],
1546-
"variable": []
1550+
]
15471551
},
1552+
"description": "List all the project with filters applied. The filter string should be url encoded. Default limit and offset is applicable"
1553+
},
1554+
"response": []
1555+
},
1556+
{
1557+
"name": "List projects with filters - code",
1558+
"request": {
15481559
"method": "GET",
15491560
"header": [
15501561
{
15511562
"key": "Authorization",
1552-
"value": "Bearer {{jwt-token}}",
1553-
"description": ""
1563+
"value": "Bearer {{jwt-token}}"
15541564
}
15551565
],
15561566
"body": {
15571567
"mode": "raw",
15581568
"raw": ""
15591569
},
1560-
"description": "List all the project with filters applied. The filter string should be url encoded. Default limit and offset is applicable"
1561-
},
1562-
"response": []
1563-
},
1564-
{
1565-
"name": "List projects with filters - code",
1566-
"request": {
15671570
"url": {
15681571
"raw": "{{api-url}}/v4/projects?filter=code%3Dtest*",
15691572
"host": [
@@ -1576,24 +1579,9 @@
15761579
"query": [
15771580
{
15781581
"key": "filter",
1579-
"value": "code%3Dtest*",
1580-
"equals": true,
1581-
"description": ""
1582+
"value": "code%3Dtest*"
15821583
}
1583-
],
1584-
"variable": []
1585-
},
1586-
"method": "GET",
1587-
"header": [
1588-
{
1589-
"key": "Authorization",
1590-
"value": "Bearer {{jwt-token}}",
1591-
"description": ""
1592-
}
1593-
],
1594-
"body": {
1595-
"mode": "raw",
1596-
"raw": ""
1584+
]
15971585
},
15981586
"description": "List all the project with filters applied. The filter string should be url encoded. Default limit and offset is applicable"
15991587
},
@@ -5509,4 +5497,4 @@
55095497
]
55105498
}
55115499
]
5512-
}
5500+
}

src/routes/projects/list.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,6 @@ const parseElasticSearchCriteria = (criteria, fields, order) => {
241241
values: criteria.filters.id.$in,
242242
},
243243
});
244-
} else if (_.has(criteria, 'filters.id') && criteria.filters.id.indexOf('*') > -1) {
245-
mustQuery = _.concat(mustQuery, buildEsQueryWithFilter('id', criteria.filters.id, MATCH_TYPE_WILDCARD, ['id']));
246244
} else if (_.has(criteria, 'filters.id')) {
247245
boolQuery.push({
248246
term: {
@@ -287,6 +285,21 @@ const parseElasticSearchCriteria = (criteria, fields, order) => {
287285
});
288286
}
289287

288+
if (_.has(criteria, 'filters.type.$in')) {
289+
// type is an array
290+
boolQuery.push({
291+
terms: {
292+
type: criteria.filters.type.$in,
293+
},
294+
});
295+
} else if (_.has(criteria, 'filters.type')) {
296+
// type is simple string
297+
boolQuery.push({
298+
term: {
299+
type: criteria.filters.type,
300+
},
301+
});
302+
}
290303
if (_.has(criteria, 'filters.keyword')) {
291304
// keyword is a full text search
292305
// escape special fields from keyword search
@@ -400,7 +413,7 @@ module.exports = [
400413
'type', 'type asc', 'type desc',
401414
];
402415
if (!util.isValidFilter(filters,
403-
['id', 'status', 'memberOnly', 'keyword', 'name', 'code', 'customer', 'manager']) ||
416+
['id', 'status', 'memberOnly', 'keyword', 'type', 'name', 'code', 'customer', 'manager']) ||
404417
(sort && _.indexOf(sortableProps, sort) < 0)) {
405418
return util.handleError('Invalid filters or sort', null, req, next);
406419
}

src/routes/projects/list.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,9 @@ describe('LIST Project', () => {
513513
});
514514
});
515515

516-
it('should return project that match when filtering by id', (done) => {
516+
it('should return project that match when filtering by id (exact)', (done) => {
517517
request(server)
518-
.get('/v4/projects/?filter=id%3D1*')
518+
.get('/v4/projects/?filter=id%3D1')
519519
.set({
520520
Authorization: `Bearer ${testUtil.jwts.admin}`,
521521
})

0 commit comments

Comments
 (0)