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

GrottoCenter / grottocenter-api / 11123282962

01 Oct 2024 10:00AM UTC coverage: 46.184%. First build
11123282962

push

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

740 of 2199 branches covered (33.65%)

Branch coverage included in aggregate %.

0 of 2 new or added lines in 2 files covered. (0.0%)

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

35.71
/api/services/StatisticsMassifService.js
1
const FIND_MASSIF_IN_VIEW = `
1✔
2
  SELECT id_massif
3
  FROM v_massif_info
4
  WHERE id_massif = $1
5
  LIMIT 1
6
`;
7

8
const GET_NB_CAVES = `
1✔
9
  SELECT COUNT(*) as nb_caves
10
  FROM v_massif_info
11
  WHERE id_massif = $1
12
`;
13

14
const GET_NB_NETWORKS = `
1✔
15
  SELECT COUNT(*) as nb_networks
16
  FROM v_massif_info
17
  WHERE id_massif = $1
18
  AND nb_entrances > 1
19
`;
20

21
const FIND_CAVE_WITH_MAX_DEPTH_IN_MASSIF = `
1✔
22
  SELECT id_cave, name_cave, depth_cave as value
23
  FROM v_massif_info
24
  WHERE id_massif = $1
25
  AND depth_cave IS NOT NULL
26
  ORDER BY depth_cave DESC
27
  LIMIT 1
28
`;
29

30
const FIND_CAVE_WITH_MAX_LENGTH_IN_MASSIF = `
1✔
31
  SELECT id_cave, name_cave, length_cave as value
32
  FROM v_massif_info
33
  WHERE id_massif = $1
34
  AND length_cave IS NOT NULL
35
  ORDER BY length_cave DESC
36
  LIMIT 1
37
`;
38

39
const GET_NB_CAVES_WHICH_ARE_DIVING_IN_MASSIF = `
1✔
40
  SELECT COUNT(*) as nb_diving_cave
41
  FROM v_massif_info
42
  WHERE is_diving_cave = true
43
  AND id_massif = $1
44
`;
45

46
const GET_AVG_DEPTH_AND_LENGTH_IN_MASSIF = `
1✔
47
  SELECT AVG(depth_cave) as avg_depth, AVG(length_cave) as avg_length
48
  FROM v_massif_info
49
  WHERE id_massif = $1
50
`;
51

52
const GET_TOTAL_LENGTH_IN_MASSIF = `
1✔
53
  SELECT SUM(length_cave) as value, COUNT(length_cave) as nb_data
54
  FROM v_massif_info
55
  WHERE length_cave IS NOT NULL
56
  AND id_massif = $1
57
`;
58

59
const CommonService = require('./CommonService');
1✔
60

61
async function safeDBQuery(sql, param) {
62
  try {
×
63
    const queryResult = await CommonService.query(sql, [param]);
×
64
    const result = queryResult.rows;
×
65
    if (result.length > 0) {
×
66
      return result[0];
×
67
    }
68
    return null;
×
69
  } catch (e) {
70
    return null;
×
71
  }
72
}
73

74
module.exports = {
1✔
75
  /**
76
   *
77
   * @param {int} massifId
78
   * @returns {boolean} true if there is some line about this massif, else false
79
   */
80
  isMassifInView: async (massifId) => {
81
    const result = await safeDBQuery(FIND_MASSIF_IN_VIEW, massifId);
×
NEW
82
    return result;
×
83
  },
84

85
  /**
86
   *
87
   * @param {int} massifId
88
   * @returns {int} the number of caves in the massif
89
   *                or null if no result or something went wrong
90
   */
91
  getNbCavesInMassif: async (massifId) => safeDBQuery(GET_NB_CAVES, massifId),
×
92

93
  /**
94
   *
95
   * @param {int} massifId
96
   * @returns {int} the number of networks in the massif
97
   *                or null if no result or something went wrong
98
   */
99
  getNbNetworksInMassif: async (massifId) =>
100
    safeDBQuery(GET_NB_NETWORKS, massifId),
×
101

102
  /**
103
   *
104
   * @param {int} massifId
105
   * @returns {Object} the cave with the maximum depth in the massif (id, name and depth)
106
   *                or null if no result or something went wrong
107
   */
108
  getCaveWithMaxDepthInMassif: async (massifId) =>
109
    safeDBQuery(FIND_CAVE_WITH_MAX_DEPTH_IN_MASSIF, massifId),
×
110

111
  /**
112
   *
113
   * @param {int} massifId
114
   * @returns {Object} the cave with the maximum length in the massif (id, name and length)
115
   *                or null if no result or something went wrong
116
   */
117
  getCaveWithMaxLengthInMassif: async (massifId) =>
118
    safeDBQuery(FIND_CAVE_WITH_MAX_LENGTH_IN_MASSIF, massifId),
×
119

120
  /**
121
   *
122
   * @param {int} massifId
123
   * @returns {int} the number of caves which are diving in the massif
124
   *                or null if no result or something went wrong
125
   */
126
  getNbCavesWhichAreDivingInMassif: async (massifId) =>
127
    safeDBQuery(GET_NB_CAVES_WHICH_ARE_DIVING_IN_MASSIF, massifId),
×
128

129
  /**
130
   *
131
   * @param {int} massifId
132
   * @returns {Object} the average depth and length in the massif
133
   *                or null if no result or something went wrong
134
   */
135
  getAvgDepthAndLengthInMassif: async (massifId) =>
136
    safeDBQuery(GET_AVG_DEPTH_AND_LENGTH_IN_MASSIF, massifId),
×
137

138
  /**
139
   *
140
   * @param {int} massifId
141
   * @returns {int} the sum of the lengths of each cave in the massif
142
   *                or null if no result or something went wrong
143
   */
144
  getTotalLength: async (massifId) =>
145
    safeDBQuery(GET_TOTAL_LENGTH_IN_MASSIF, massifId),
×
146
};
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