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

GrottoCenter / grottocenter-api / 10996210778

23 Sep 2024 02:17PM UTC coverage: 46.158% (-2.8%) from 48.952%
10996210778

Pull #1306

github

vmarseguerra
feat(entities): adds delete / restore for document
Pull Request #1306: Adds delete / restore for entrance sub entities

740 of 2203 branches covered (33.59%)

Branch coverage included in aggregate %.

526 of 1293 new or added lines in 114 files covered. (40.68%)

23 existing lines in 18 files now uncovered.

2462 of 4734 relevant lines covered (52.01%)

4.5 hits per line

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

34.38
/api/services/StatisticsCountryService.js
1
const FIND_COUNTRY_IN_VIEW = `
1✔
2
  SELECT *
3
  FROM v_country_info
4
  WHERE id_country = $1
5
`;
6

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

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

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

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

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

50
const GET_NB_CAVES_WHICH_ARE_DIVING_IN_COUNTRY = `
1✔
51
  SELECT COUNT(*) as nb_diving_cave
52
  FROM (
53
    SELECT DISTINCT id_cave
54
    FROM v_country_info
55
    WHERE id_country = $1
56
    AND is_diving_cave = true) as tmp;
57
`;
58

59
const GET_AVG_DEPTH_AND_LENGTH_IN_COUNTRY = `
1✔
60
  SELECT AVG(depth_cave) as avg_depth, AVG(length_cave) as avg_length
61
  FROM (
62
    SELECT DISTINCT id_cave, depth_cave, length_cave
63
    FROM v_country_info
64
    WHERE id_country = $1) as tmp;
65
`;
66

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

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

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

91
module.exports = {
1✔
92
  /**
93
   *
94
   * @param {int} countryId
95
   * @returns {boolean} true if there is some line about this country, else false
96
   */
97
  isCountryInView: async (countryId) => {
NEW
98
    const result = await safeDBQuery(FIND_COUNTRY_IN_VIEW, countryId);
×
NEW
99
    return result && result.length > 0;
×
100
  },
101

102
  /**
103
   *
104
   * @param {string} countryId
105
   * @returns {int} the number of massifs in the country
106
   *                or null if no result or something went wrong
107
   */
108
  getNbMassifsInCountry: async (countryId) =>
NEW
109
    safeDBQuery(GET_NB_MASSIFS, countryId),
×
110

111
  /**
112
   *
113
   * @param {string} countryId
114
   * @returns {int} the number of caves in the country
115
   *                or null if no result or something went wrong
116
   */
117
  getNbCavesInCountry: async (countryId) =>
NEW
118
    safeDBQuery(GET_NB_CAVES, countryId),
×
119

120
  /**
121
   *
122
   * @param {string} countryId
123
   * @returns {int} the number of networks in the country
124
   *                or null if no result or something went wrong
125
   */
126
  getNbNetworksInCountry: async (countryId) =>
NEW
127
    safeDBQuery(GET_NB_NETWORKS, countryId),
×
128

129
  /**
130
   *
131
   * @param {string} countryId
132
   * @returns {Object} the cave with the maximum depth in the country (id, name and depth)
133
   *                or null if no result or something went wrong
134
   */
135
  getCaveWithMaxDepthInCountry: async (countryId) =>
NEW
136
    safeDBQuery(FIND_CAVE_WITH_MAX_DEPTH_IN_COUNTRY, countryId),
×
137

138
  /**
139
   *
140
   * @param {string} countryId
141
   * @returns {Object} the cave with the maximum length in the country (id, name and length)
142
   *                or null if no result or something went wrong
143
   */
144
  getCaveWithMaxLengthInCountry: async (countryId) =>
NEW
145
    safeDBQuery(FIND_CAVE_WITH_MAX_LENGTH_IN_COUNTRY, countryId),
×
146

147
  /**
148
   *
149
   * @param {string} countryId
150
   * @returns {int} the number of caves which are diving in the country
151
   *                or null if no result or something went wrong
152
   */
153
  getNbCavesWhichAreDivingInCountry: async (countryId) =>
NEW
154
    safeDBQuery(GET_NB_CAVES_WHICH_ARE_DIVING_IN_COUNTRY, countryId),
×
155

156
  /**
157
   *
158
   * @param {string} countryId
159
   * @returns {Object} the average depth and length in the country
160
   *                or null if no result or something went wrong
161
   */
162
  getAvgDepthAndLengthInCountry: async (countryId) =>
NEW
163
    safeDBQuery(GET_AVG_DEPTH_AND_LENGTH_IN_COUNTRY, countryId),
×
164

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