• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CBIIT / INS-REST-WebService / 25824106726

13 May 2026 08:18PM UTC coverage: 56.422% (+12.0%) from 44.469%
25824106726

Pull #62

github

web-flow
Merge d21bdb263 into 61c98c8d0
Pull Request #62: INS-1615

309 of 498 branches covered (62.05%)

Branch coverage included in aggregate %.

297 of 417 new or added lines in 11 files covered. (71.22%)

36 existing lines in 1 file now uncovered.

574 of 1067 relevant lines covered (53.8%)

13.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.72
/Controllers/resource.controllers.js
1
const logger = require('../Components/logger');
1✔
2
const cache = require('../Components/cache');
1✔
3
const config = require('../Config');
1✔
4
const path = require('path');
1✔
5
const { RESOURCE_DEFAULT_SORT_FIELD } = require('../Utils/resourceFields');
1✔
6
const { getObjectParam, getStringParam } = require('../Utils/params');
1✔
7
const resourceService = require('../Services/resource.service');
1✔
8

9
const search = async (req, res) => {
1✔
10
  const body = getObjectParam(req, 'body');
2✔
11
  const data = {};
2✔
12
  const filters = getObjectParam(body, 'filters');
2✔
13
  const options = {};
2✔
14
  const pageInfo = getObjectParam(body, 'pageInfo', {page: 1, pageSize: 10});
2✔
15
  const searchText = getStringParam(body, 'search_text');
2✔
16
  const sort = getObjectParam(body, 'sort', {k: RESOURCE_DEFAULT_SORT_FIELD, v: 'asc'});
2✔
17

18
  if (pageInfo.page !== parseInt(pageInfo.page, 10) || pageInfo.page <= 0) {
2!
NEW
19
    pageInfo.page = 1;
×
20
  }
21
  if (pageInfo.pageSize !== parseInt(pageInfo.pageSize, 10) || pageInfo.pageSize <= 0) {
2!
NEW
22
    pageInfo.pageSize = 10;
×
23
  }
24
  if (!(sort?.v && ['asc', 'desc'].includes(sort.v))) {
2!
NEW
25
    sort.v = 'asc';
×
26
  }
27

28
  options.pageInfo = pageInfo;
2✔
29
  options.sort = sort;
2✔
30
  data.sort = sort;
2✔
31
  data.pageInfo = options.pageInfo;
2✔
32

33
  const searchResult = await resourceService.search(searchText, filters, options);
2✔
34

35
  // Error response if there's an error
36
  if (searchResult.error) {
2✔
37
    res.status(500).json({
1✔
38
      status: "error",
39
      aggs: 'all',
40
      data: {},
41
      error: searchResult.error,
42
    });
43
    return;
1✔
44
  }
45

46
  if (searchResult.total !== 0 && (options.pageInfo.page - 1) * options.pageInfo.pageSize >= searchResult.total) {
1!
NEW
47
    let lastPage = Math.ceil(searchResult.total / options.pageInfo.pageSize);
×
NEW
48
    options.pageInfo.page = lastPage;
×
NEW
49
    const searchResultAgain = await resourceService.search(searchText, filters, options);
×
NEW
50
    data.pageInfo.total = searchResultAgain.total;
×
NEW
51
    data.result = searchResultAgain.data;
×
NEW
52
    data.aggs = searchResultAgain.aggs;
×
53
  } else {
54
    data.pageInfo.total = searchResult.total;
1✔
55
    data.result = searchResult.data;
1✔
56
    data.aggs = searchResult.aggs;
1✔
57
  }
58

59
  res.json({status:"success", data: data});
1✔
60
};
61

62
const getById = async (req, res) => {
1✔
63
  const resourceId = req.params.uuid || req.params.resourceId;
2!
64
  const searchResult = await resourceService.searchById(resourceId);
2✔
65

66
  if (!searchResult) {
2✔
67
    res.status(404).json({
1✔
68
      status: 'failure',
69
      error: 'No resource found with the provided UUID',
70
    });
71
    return;
1✔
72
  }
73

74
  res.json({status:'success', data: searchResult});
1✔
75
};
76

77
const getFilters = async (req, res) => {
1✔
78
  const body = getObjectParam(req, 'body');
2✔
79
  const searchText = getStringParam(body, 'search_text');
2✔
80
  const searchFilters = getObjectParam(body, 'filters');
2✔
81

82
  const filters = await resourceService.getFilters(searchText, searchFilters);
2✔
83

84
  // Error response if there's an error
85
  if (filters.error) {
2✔
86
    res.status(500).json({
1✔
87
      status: "error",
88
      data: {},
89
      error: filters.error,
90
    });
91
    return;
1✔
92
  }
93

94
  res.json({status: 'success', data: filters});
1✔
95
};
96

97
module.exports = {
1✔
98
        search,
99
  getFilters,
100
        getById,
101
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc