• 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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