• 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

43.4
/api/services/DescriptionService.js
1
module.exports = {
6✔
2
  /**
3
   * @param {string} document to document to set names including its parent if present
4
   * @param {Boolean} [setParent=true] specify if the document parent description must be set
5
   *    (recursive and cost a lot of resources)
6
   */
7
  setDocumentDescriptions: async (document, setParent = true) => {
3✔
8
    if (!document?.id) return;
3✔
9
    // eslint-disable-next-line no-param-reassign
10
    document.descriptions = await TDescription.find()
2✔
11
      .where({ document: document.id })
12
      .populate('language');
13
    if (setParent && (document?.parent?.id ?? null)) {
2✔
14
      await module.exports.setDocumentDescriptions(document.parent);
1✔
15
    }
16
  },
17

18
  getMassifDescriptions: async (massifId) => {
19
    if (!massifId) return [];
3!
20
    return TDescription.find({ massif: massifId })
3✔
21
      .populate('author')
22
      .populate('reviewer');
23
  },
24

25
  getCaveDescriptions: async (caveId, where = {}) => {
×
26
    if (!caveId) return [];
8!
27
    return TDescription.find({ ...where, cave: caveId })
8✔
28
      .populate('author')
29
      .populate('reviewer');
30
  },
31

32
  getEntranceDescriptions: async (entranceId, where = {}) => {
×
33
    if (!entranceId) return [];
8!
34
    return TDescription.find({ ...where, entrance: entranceId })
8✔
35
      .populate('author')
36
      .populate('reviewer');
37
  },
38

39
  getEntranceHDescriptions: async (entranceId, where = {}) => {
×
UNCOV
40
    if (!entranceId) return [];
×
NEW
41
    const descriptionIds = await TDescription.find({
×
42
      where: { ...where, entrance: entranceId },
43
      select: ['id'],
44
    });
NEW
45
    return module.exports.getHDescription(descriptionIds.map((e) => e.id));
×
46
  },
47

48
  getDescription: async (descriptionId) =>
NEW
49
    TDescription.findOne({ id: descriptionId })
×
50
      .populate('author')
51
      .populate('reviewer'),
52

53
  getHDescription: async (descriptionId) =>
54
    HDescription.find({ t_id: descriptionId })
2✔
55
      .populate('reviewer')
56
      .populate('author'),
57

58
  getHDescriptionsOfDocument: async (documentId) => {
59
    const hDescriptions = await HDescription.find()
×
60
      .where({
61
        document: documentId,
62
      })
63
      .sort('id DESC')
64
      .populate('author')
65
      .populate('language')
66
      .populate('reviewer');
67
    const tDescription = await TDescription.find()
×
68
      .where({
69
        document: documentId,
70
      })
71
      .populate('author')
72
      .populate('language')
73
      .populate('reviewer');
74
    if (tDescription.length > 0) {
×
75
      // Transform TDescritpion object to keep same model as HDescription
76
      tDescription[0].t_id = tDescription[0].id;
×
77
      tDescription[0].id = tDescription[0].dateReviewed;
×
78
      hDescriptions.push(tDescription[0]);
×
79
    }
80
    return hDescriptions;
×
81
  },
82

83
  compareDescriptionDate(documentDate, newDescDate, oldDescDate) {
84
    // Go back 2 minutes to not be affected by the database save time
85
    newDescDate.setMinutes(newDescDate.getMinutes() - 2);
×
86
    if (documentDate.getTime() >= newDescDate.getTime()) {
×
87
      if (newDescDate.getTime() > oldDescDate.getTime()) {
×
88
        return true;
×
89
      }
90
    }
91
    return false;
×
92
  },
93
};
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