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

GrottoCenter / grottocenter-api / 5631056675

pending completion
5631056675

push

github

vmarseguerra
refactor(right): replaces rights with a static groups system

751 of 1944 branches covered (38.63%)

Branch coverage included in aggregate %.

59 of 59 new or added lines in 35 files covered. (100.0%)

2702 of 5007 relevant lines covered (53.96%)

14.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.14
/api/controllers/v1/document/update.js
1
const ControllerService = require('../../../services/ControllerService');
1✔
2
const DocumentService = require('../../../services/DocumentService');
1✔
3
const ErrorService = require('../../../services/ErrorService');
1✔
4
const FileService = require('../../../services/FileService');
1✔
5
const RightService = require('../../../services/RightService');
1✔
6
const { toDocument } = require('../../../services/mapping/converters');
1✔
7

8
const { INVALID_FORMAT, INVALID_NAME, ERROR_DURING_UPLOAD_TO_AZURE } =
9
  FileService;
1✔
10

11
module.exports = async (req, res) => {
1✔
12
  const docWithModif = await TDocument.findOne({
2✔
13
    id: req.param('id'),
14
    modifiedDocJson: { '!=': null },
15
  });
16

17
  if (docWithModif) {
2✔
18
    const hasRight = RightService.hasGroup(
1✔
19
      req.token.groups,
20
      RightService.G.MODERATOR
21
    );
22

23
    if (!hasRight) {
1!
24
      return res.forbidden(
×
25
        `You are not authorized to update a document with modifications waiting a moderator approval.`
26
      );
27
    }
28
  }
29

30
  // Add new files
31
  const newFilesArray = [];
2✔
32
  if (req.files && req.files.files) {
2!
33
    const { files } = req.files;
×
34
    try {
×
35
      await Promise.all(
×
36
        files.map(async (file) => {
37
          const createdFile = await FileService.document.create(
×
38
            file,
39
            req.param('id'),
40
            true,
41
            false
42
          );
43
          newFilesArray.push(createdFile);
×
44
        })
45
      );
46
    } catch (err) {
47
      const { message, fileName } = err;
×
48
      switch (message) {
×
49
        case INVALID_FORMAT:
50
          return res.badRequest(
×
51
            `The format of the file "${fileName}" is invalid.`
52
          );
53
        case INVALID_NAME:
54
          return res.badRequest(
×
55
            `The name of the file "${fileName}" is invalid.`
56
          );
57
        case ERROR_DURING_UPLOAD_TO_AZURE:
58
        default:
59
          return res.serverError(
×
60
            'An error occured when trying to upload the file to Azure.'
61
          );
62
      }
63
    }
64
  }
65

66
  // Update json data (upcoming modifications which need to be validated)
67
  const dataFromClient = await DocumentService.getConvertedDataFromClient(req);
2✔
68
  const descriptionData = await DocumentService.getLangDescDataFromClient(req);
2✔
69

70
  try {
2✔
71
    const updatedDocument = await DocumentService.updateDocument(
2✔
72
      req,
73
      dataFromClient,
74
      descriptionData,
75
      newFilesArray
76
    );
77
    if (!updatedDocument) {
2!
78
      return res.notFound();
×
79
    }
80

81
    const params = {};
2✔
82
    params.controllerMethod = 'DocumentController.update';
2✔
83
    return ControllerService.treatAndConvert(
2✔
84
      req,
85
      null,
86
      updatedDocument,
87
      params,
88
      res,
89
      toDocument
90
    );
91
  } catch (e) {
92
    return ErrorService.getDefaultErrorHandler(res)(e);
×
93
  }
94
};
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