• 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

22.22
/api/controllers/v1/organization/delete-one.js
1
const ElasticsearchService = require('../../../services/ElasticsearchService');
1✔
2
const NotificationService = require('../../../services/NotificationService');
1✔
3
const RightService = require('../../../services/RightService');
1✔
4
const {
5
  NOTIFICATION_TYPES,
6
  NOTIFICATION_ENTITIES,
7
} = require('../../../services/NotificationService');
1✔
8
const NameService = require('../../../services/NameService');
1✔
9

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 delete an organization.');
×
17
  }
18

19
  // Check if organization exists and if it's not already deleted
20
  const organizationId = req.param('id');
×
21
  const currentOrganization = await TGrotto.findOne(organizationId);
×
22
  await NameService.setNames([currentOrganization], 'grotto');
×
23
  if (currentOrganization) {
×
24
    if (currentOrganization.isDeleted) {
×
25
      return res.status(410).send({
×
26
        message: `The organization with id ${organizationId} has already been deleted.`,
27
      });
28
    }
29
  } else {
30
    return res.notFound({
×
31
      message: `Organization of id ${organizationId} not found.`,
32
    });
33
  }
34

35
  // Delete Organization
36
  await TGrotto.destroyOne({
×
37
    id: organizationId,
38
  }).intercept(() =>
39
    res.serverError(
×
40
      `An unexpected error occured when trying to delete organization with id ${organizationId}.`
41
    )
42
  );
43

44
  await ElasticsearchService.deleteResource('grottos', organizationId);
×
45

46
  await NotificationService.notifySubscribers(
×
47
    req,
48
    currentOrganization,
49
    req.token.id,
50
    NOTIFICATION_TYPES.DELETE,
51
    NOTIFICATION_ENTITIES.ORGANIZATION
52
  );
53
  return res.ok();
×
54
};
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