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

GrottoCenter / grottocenter-api / 10996310862

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

push

github

vmarseguerra
feat(entities): adds delete / restore for document

740 of 2203 branches covered (33.59%)

Branch coverage included in aggregate %.

24 of 153 new or added lines in 17 files covered. (15.69%)

484 existing lines in 49 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

87.5
/api/services/NameService.js
1
/* eslint-disable no-param-reassign */
2

3
function extractMainName(entity) {
4
  const mainName = entity.names.find((n) => n.isMain);
93✔
5
  if (mainName) entity.name = mainName.name;
93✔
6
}
7

8
module.exports = {
7✔
9
  /**
10
   * @param {[string]} entitiesToComplete collection of entities for which we want the names
11
   * @param {string} entitiesType should be one of: cave, entrance, grotto, massif, point
12
   *
13
   * @returns {Promise} the entities with their attribute "names" completed
14
   */
15
  setNames: async (entitiesToComplete, entitiesType) => {
16
    if (!entitiesToComplete) return null;
101!
17

18
    const allIds = entitiesToComplete.map((e) => e.id);
101✔
19
    const allNames = await TName.find().where({ [entitiesType]: allIds });
101✔
20
    for (const entity of entitiesToComplete) {
101✔
21
      entity.names = allNames.filter((n) => n[entitiesType] === entity.id);
127✔
22
      extractMainName(entity);
86✔
23
    }
24

25
    if (entitiesType !== 'cave') return entitiesToComplete;
101✔
26
    // For a cave, if there is no name for it, search the name
27
    // of its first entrance (the only one): the name of the cave is the same as its entrance.
28
    const emptyNameCaves = entitiesToComplete.filter(
30✔
29
      (entity) => entity.names.length === 0
31✔
30
    );
31
    if (emptyNameCaves.length === 0) return entitiesToComplete;
30✔
32

33
    const caveIds = emptyNameCaves.map((c) => c.id);
7✔
34
    const entrances = await TEntrance.find({ cave: caveIds }).populate('names');
7✔
35
    for (const cave of emptyNameCaves) {
7✔
36
      cave.names = entrances.find((e) => e.cave === cave.id)?.names ?? [];
7✔
37
      extractMainName(cave);
7✔
38
    }
39

40
    return entitiesToComplete;
7✔
41
  },
42

43
  async permanentDelete(where) {
UNCOV
44
    await TName.destroy(where); // TName first soft delete
×
UNCOV
45
    await HName.destroy(where);
×
UNCOV
46
    await TName.destroy(where); // Hard delete
×
47
  },
48
};
49

50
/* eslint-enable no-param-reassign */
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