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

CBIIT / INS-REST-WebService / 25825608805

13 May 2026 08:49PM UTC coverage: 56.386% (+11.9%) from 44.469%
25825608805

Pull #62

github

web-flow
Merge c2256ff5d into 61c98c8d0
Pull Request #62: INS-1615 INS-1616 INS-1617

309 of 498 branches covered (62.05%)

Branch coverage included in aggregate %.

298 of 418 new or added lines in 11 files covered. (71.29%)

36 existing lines in 1 file now uncovered.

574 of 1068 relevant lines covered (53.75%)

13.78 hits per line

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

81.71
/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.page = options.pageInfo.page;
×
NEW
51
    data.pageInfo.total = searchResultAgain.total;
×
NEW
52
    data.result = searchResultAgain.data;
×
NEW
53
    data.aggs = searchResultAgain.aggs;
×
54
  } else {
55
    data.pageInfo.total = searchResult.total;
1✔
56
    data.result = searchResult.data;
1✔
57
    data.aggs = searchResult.aggs;
1✔
58
  }
59

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

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

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

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

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

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

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

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

98
module.exports = {
1✔
99
        search,
100
  getFilters,
101
        getById,
102
};
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