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

GrottoCenter / grottocenter-api / 19277458745

11 Nov 2025 08:15PM UTC coverage: 45.598% (+0.8%) from 44.806%
19277458745

push

github

Clément Ronzon
feat(region): adds endpoints for Region page support

963 of 2824 branches covered (34.1%)

Branch coverage included in aggregate %.

165 of 235 new or added lines in 15 files covered. (70.21%)

2 existing lines in 2 files now uncovered.

2958 of 5775 relevant lines covered (51.22%)

6.84 hits per line

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

36.67
/api/services/StatisticsRegionService.js
1
const FIND_REGION_IN_VIEW = `
1✔
2
  SELECT id_region
3
  FROM v_region_info
4
  WHERE id_region = $1
5
  LIMIT 1
6
`;
7

8
const GET_NB_MASSIFS = `
1✔
9
  SELECT COUNT(*) as nb_massifs
10
  FROM (
11
    SELECT DISTINCT id_massif
12
    FROM v_region_info
13
    WHERE id_region = $1) as tmp
14
`;
15

16
const GET_NB_CAVES = `
1✔
17
  SELECT COUNT(*) as nb_caves
18
  FROM (
19
    SELECT DISTINCT id_cave
20
    FROM v_region_info
21
    WHERE id_region = $1) as tmp
22
`;
23

24
const GET_NB_NETWORKS = `
1✔
25
  SELECT COUNT(*) as nb_networks
26
  FROM (
27
    SELECT DISTINCT id_cave
28
    FROM v_region_info
29
    WHERE id_region = $1
30
    AND nb_entrances > 1) as tmp
31
`;
32

33
const FIND_CAVE_WITH_MAX_DEPTH_IN_REGION = `
1✔
34
  SELECT id_cave, name_cave, depth_cave as value
35
  FROM v_region_info
36
  WHERE id_region = $1
37
  AND depth_cave IS NOT NULL
38
  ORDER BY depth_cave DESC
39
  LIMIT 1
40
`;
41

42
const FIND_CAVE_WITH_MAX_LENGTH_IN_REGION = `
1✔
43
  SELECT id_cave, name_cave, length_cave as value
44
  FROM v_region_info
45
  WHERE id_region = $1
46
  AND length_cave IS NOT NULL
47
  ORDER BY length_cave DESC
48
  LIMIT 1
49
`;
50

51
const GET_NB_CAVES_WHICH_ARE_DIVING_IN_REGION = `
1✔
52
  SELECT COUNT(*) as nb_diving_cave
53
  FROM (
54
    SELECT DISTINCT id_cave
55
    FROM v_region_info
56
    WHERE id_region = $1
57
    AND is_diving_cave = true) as tmp
58
`;
59

60
const GET_AVG_DEPTH_AND_LENGTH_IN_REGION = `
1✔
61
  SELECT AVG(depth_cave) as avg_depth, AVG(length_cave) as avg_length
62
  FROM (
63
    SELECT DISTINCT id_cave, depth_cave, length_cave
64
    FROM v_region_info
65
    WHERE id_region = $1) as tmp
66
`;
67

68
const GET_TOTAL_LENGTH_IN_REGION = `
1✔
69
  SELECT SUM(length_cave) as value, COUNT(length_cave) as nb_data
70
  FROM (
71
    SELECT DISTINCT id_region, id_cave, depth_cave, length_cave
72
    FROM v_region_info
73
    WHERE id_region = $1
74
    AND length_cave IS NOT NULL) as tmp
75
`;
76

77
const CommonService = require('./CommonService');
1✔
78

79
async function safeDBQuery(sql, param) {
NEW
80
  try {
×
NEW
81
    const queryResult = await CommonService.query(sql, [param]);
×
NEW
82
    const result = queryResult.rows;
×
NEW
83
    if (result.length > 0) {
×
NEW
84
      return result[0];
×
85
    }
NEW
86
    return null;
×
87
  } catch (e) {
NEW
88
    return null;
×
89
  }
90
}
91

92
module.exports = {
1✔
93
  /**
94
   *
95
   * @param {string} regionId ISO 3166-2 code
96
   * @returns {boolean} true if there is some line about this region, else false
97
   */
98
  isRegionInView: async (regionId) => {
NEW
99
    const result = await safeDBQuery(FIND_REGION_IN_VIEW, regionId);
×
NEW
100
    return result;
×
101
  },
102

103
  /**
104
   *
105
   * @param {string} regionId ISO 3166-2 code
106
   * @returns {int} the number of massifs in the region
107
   *                or null if no result or something went wrong
108
   */
109
  getNbMassifsInRegion: async (regionId) =>
NEW
110
    safeDBQuery(GET_NB_MASSIFS, regionId),
×
111

112
  /**
113
   *
114
   * @param {string} regionId ISO 3166-2 code
115
   * @returns {int} the number of caves in the region
116
   *                or null if no result or something went wrong
117
   */
NEW
118
  getNbCavesInRegion: async (regionId) => safeDBQuery(GET_NB_CAVES, regionId),
×
119

120
  /**
121
   *
122
   * @param {string} regionId ISO 3166-2 code
123
   * @returns {int} the number of networks in the region
124
   *                or null if no result or something went wrong
125
   */
126
  getNbNetworksInRegion: async (regionId) =>
NEW
127
    safeDBQuery(GET_NB_NETWORKS, regionId),
×
128

129
  /**
130
   *
131
   * @param {string} regionId ISO 3166-2 code
132
   * @returns {Object} the cave with the maximum depth in the region (id, name and depth)
133
   *                or null if no result or something went wrong
134
   */
135
  getCaveWithMaxDepthInRegion: async (regionId) =>
NEW
136
    safeDBQuery(FIND_CAVE_WITH_MAX_DEPTH_IN_REGION, regionId),
×
137

138
  /**
139
   *
140
   * @param {string} regionId ISO 3166-2 code
141
   * @returns {Object} the cave with the maximum length in the region (id, name and length)
142
   *                or null if no result or something went wrong
143
   */
144
  getCaveWithMaxLengthInRegion: async (regionId) =>
NEW
145
    safeDBQuery(FIND_CAVE_WITH_MAX_LENGTH_IN_REGION, regionId),
×
146

147
  /**
148
   *
149
   * @param {string} regionId ISO 3166-2 code
150
   * @returns {int} the number of caves which are diving in the region
151
   *                or null if no result or something went wrong
152
   */
153
  getNbCavesWhichAreDivingInRegion: async (regionId) =>
NEW
154
    safeDBQuery(GET_NB_CAVES_WHICH_ARE_DIVING_IN_REGION, regionId),
×
155

156
  /**
157
   *
158
   * @param {string} regionId ISO 3166-2 code
159
   * @returns {Object} the average depth and length in the region
160
   *                or null if no result or something went wrong
161
   */
162
  getAvgDepthAndLengthInRegion: async (regionId) =>
NEW
163
    safeDBQuery(GET_AVG_DEPTH_AND_LENGTH_IN_REGION, regionId),
×
164

165
  /**
166
   *
167
   * @param {string} regionId ISO 3166-2 code
168
   * @returns {int} the sum of the lengths of each cave in the region
169
   *                or null if no result or something went wrong
170
   */
171
  getTotalLength: async (regionId) =>
NEW
172
    safeDBQuery(GET_TOTAL_LENGTH_IN_REGION, regionId),
×
173
};
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