• 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

15.38
/api/controllers/v1/document-duplicate/find.js
1
const ControllerService = require('../../../services/ControllerService');
1✔
2
const DescriptionService = require('../../../services/DescriptionService');
1✔
3
const DocumentService = require('../../../services/DocumentService');
1✔
4
const RightService = require('../../../services/RightService');
1✔
5
const { toDocumentDuplicate } = require('../../../services/mapping/converters');
1✔
6

7
module.exports = async (req, res) => {
1✔
8
  const hasRight = RightService.hasGroup(
×
9
    req.token.groups,
10
    RightService.G.MODERATOR
11
  );
12
  if (!hasRight) {
×
13
    return res.forbidden(
×
14
      'You are not authorized to find a document duplicate.'
15
    );
16
  }
17

18
  if (
×
19
    !(await sails.helpers.checkIfExists.with({
20
      attributeName: 'id',
21
      attributeValue: req.param('id'),
22
      sailsModel: TDocumentDuplicate,
23
    }))
24
  ) {
25
    return res.badRequest(
×
26
      `Could not find duplicate with id ${req.param('id')}.`
27
    );
28
  }
29
  const duplicate = await TDocumentDuplicate.findOne(req.param('id')).populate(
×
30
    'author'
31
  );
32

33
  // Populate the document
34
  const found = await TDocument.findOne(duplicate.document)
×
35
    .populate('author')
36
    .populate('authorizationDocument')
37
    .populate('authors')
38
    .populate('cave')
39
    .populate('editor')
40
    .populate('entrance')
41
    .populate('files')
42
    .populate('identifierType')
43
    .populate('languages')
44
    .populate('library')
45
    .populate('license')
46
    .populate('massif')
47
    .populate('option')
48
    .populate('parent')
49
    .populate('regions')
50
    .populate('reviewer')
51
    .populate('subjects')
52
    .populate('type');
53
  await DescriptionService.setDocumentDescriptions(found);
×
54
  duplicate.document = found;
×
55

56
  // Populate the duplicate
57
  const duplicateDoc = duplicate.content.document;
×
58
  const duplicateDesc = duplicate.content.description;
×
59
  let descLang;
60
  if (duplicateDesc.documentMainLanguage?.id) {
×
61
    duplicateDoc.languages = [duplicateDesc.documentMainLanguage.id];
×
62
    duplicateDesc.documentMainLanguage = undefined;
×
63
  }
64
  if (duplicateDesc.titleAndDescriptionLanguage?.id) {
×
65
    descLang = duplicateDesc.titleAndDescriptionLanguage.id;
×
66
    duplicateDesc.titleAndDescriptionLanguage = undefined;
×
67
  }
68

69
  const popDuplicate = await DocumentService.populateJSON(duplicateDoc);
×
70
  const descLangTable = descLang
×
71
    ? await TLanguage.findOne(descLang)
72
    : undefined;
73
  popDuplicate.descriptions = [
×
74
    {
75
      ...duplicateDesc,
76
      language: descLangTable,
77
    },
78
  ];
79
  duplicate.content = popDuplicate;
×
80

81
  const params = {
×
82
    searchedItem: `Document Duplicate of id ${duplicate.id}`,
83
  };
84

85
  return ControllerService.treatAndConvert(
×
86
    req,
87
    null,
88
    duplicate,
89
    params,
90
    res,
91
    toDocumentDuplicate
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