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

GrottoCenter / grottocenter-api / 11146286809

02 Oct 2024 02:52PM UTC coverage: 46.184% (+0.08%) from 46.105%
11146286809

Pull #1322

github

vmarseguerra
fix(entities): small issues
- document description body is not saved when importing a csv
- cannot get statistics for country and massif
- broken sql dev setup
- missing 'names' key in massif converter
- stop validating the mimeType when uploading a file
Pull Request #1322: Fix small issues in entities

740 of 2199 branches covered (33.65%)

Branch coverage included in aggregate %.

24 of 51 new or added lines in 24 files covered. (47.06%)

12 existing lines in 12 files now uncovered.

2485 of 4784 relevant lines covered (51.94%)

4.46 hits per line

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

36.67
/api/services/StatisticsCountryService.js
1
const FIND_COUNTRY_IN_VIEW = `
1✔
2
  SELECT id_country
3
  FROM v_country_info
4
  WHERE id_country = $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_country_info
13
    WHERE id_country = $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_country_info
21
    WHERE id_country = $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_country_info
29
    WHERE id_country = $1
30
    AND nb_entrances > 1) as tmp;
31
`;
32

33
const FIND_CAVE_WITH_MAX_DEPTH_IN_COUNTRY = `
1✔
34
  SELECT id_cave, name_cave, depth_cave as value
35
  FROM v_country_info
36
  WHERE id_country = $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_COUNTRY = `
1✔
43
  SELECT id_cave, name_cave, length_cave as value
44
  FROM v_country_info
45
  WHERE id_country = $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_COUNTRY = `
1✔
52
  SELECT COUNT(*) as nb_diving_cave
53
  FROM (
54
    SELECT DISTINCT id_cave
55
    FROM v_country_info
56
    WHERE id_country = $1
57
    AND is_diving_cave = true) as tmp;
58
`;
59

60
const GET_AVG_DEPTH_AND_LENGTH_IN_COUNTRY = `
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_country_info
65
    WHERE id_country = $1) as tmp;
66
`;
67

68
const GET_TOTAL_LENGTH_IN_COUNTRY = `
1✔
69
  SELECT SUM(length_cave) as value, COUNT(length_cave) as nb_data
70
  FROM (
71
    SELECT DISTINCT id_country, id_cave, depth_cave, length_cave
72
    FROM v_country_info
73
    WHERE id_country = $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) {
80
  try {
×
81
    const queryResult = await CommonService.query(sql, [param]);
×
82
    const result = queryResult.rows;
×
83
    if (result.length > 0) {
×
84
      return result[0];
×
85
    }
86
    return null;
×
87
  } catch (e) {
88
    return null;
×
89
  }
90
}
91

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

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

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

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

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

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

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

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

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