• 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

19.35
/api/controllers/v1/document/validate.js
1
const ControllerService = require('../../../services/ControllerService');
1✔
2
const DocumentService = require('../../../services/DocumentService');
1✔
3
const NotificationService = require('../../../services/NotificationService');
1✔
4
const RightService = require('../../../services/RightService');
1✔
5
const { toDocument } = require('../../../services/mapping/converters');
1✔
6

7
// Unused by front
8
// TODO Remove ?
9
// eslint-disable-next-line consistent-return
10
module.exports = async (req, res) => {
1✔
11
  const hasRight = RightService.hasGroup(
×
12
    req.token.groups,
13
    RightService.G.MODERATOR
14
  );
15
  if (!hasRight) {
×
16
    return res.forbidden('You are not authorized to validate a document.');
×
17
  }
18

19
  const isValidated = req.param('isValidated')
×
20
    ? !(req.param('isValidated').toLowerCase() === 'false')
21
    : true;
22
  const validationComment = req.param('validationComment', null);
×
23
  const id = req.param('id');
×
24

25
  if (isValidated === false && !validationComment) {
×
26
    return res.badRequest(
×
27
      `If the document with id ${id} is refused, a comment must be provided.`
28
    );
29
  }
30

NEW
31
  await TDocument.updateOne({ id }).set({
×
32
    dateValidation: new Date(),
33
    isValidated,
34
    validationComment,
35
    validator: req.token.id,
36
  });
37

38
  let populatedDoc;
NEW
39
  if (isValidated) {
×
NEW
40
    populatedDoc = await DocumentService.getPopulatedDocument(id);
×
NEW
41
    await DocumentService.createESDocument(populatedDoc);
×
42

NEW
43
    await NotificationService.notifySubscribers(
×
44
      req,
45
      populatedDoc,
46
      req.token.id,
47
      NotificationService.NOTIFICATION_TYPES.VALIDATE,
48
      NotificationService.NOTIFICATION_ENTITIES.DOCUMENT
49
    );
50
  }
51

NEW
52
  const params = {
×
53
    controllerMethod: 'DocumentController.validate',
54
    notFoundMessage: `Document of id ${id} not found`,
55
    searchedItem: `Document of id ${id}`,
56
  };
NEW
57
  return ControllerService.treatAndConvert(
×
58
    req,
59
    null,
60
    populatedDoc,
61
    params,
62
    res,
63
    toDocument
64
  );
65
};
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