• 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

18.75
/api/controllers/v1/location/delete.js
1
const ControllerService = require('../../../services/ControllerService');
1✔
2
const NotificationService = require('../../../services/NotificationService');
1✔
3
const LocationService = require('../../../services/LocationService');
1✔
4
const { toSimpleLocation } = require('../../../services/mapping/converters');
1✔
5
const RightService = require('../../../services/RightService');
1✔
6

7
module.exports = async (req, res) => {
1✔
NEW
8
  const hasRight = RightService.hasGroup(
×
9
    req.token.groups,
10
    RightService.G.MODERATOR
11
  );
NEW
12
  if (!hasRight)
×
NEW
13
    return res.forbidden('You are not authorized to delete location.');
×
14

NEW
15
  const locationId = req.param('id');
×
NEW
16
  const location = await LocationService.getLocation(locationId);
×
NEW
17
  if (!location) {
×
NEW
18
    return res.notFound({ message: `Location of id ${locationId} not found.` });
×
19
  }
20

NEW
21
  if (!location.isDeleted) {
×
NEW
22
    await TLocation.destroyOne({ id: locationId }); // Soft delete
×
NEW
23
    location.isDeleted = true;
×
24
  }
25

NEW
26
  const deletePermanently = !!req.param('isPermanent');
×
NEW
27
  if (deletePermanently) {
×
NEW
28
    await HLocation.destroy({ t_id: locationId });
×
NEW
29
    await TLocation.destroyOne({ id: locationId }); // Hard delete
×
30
  }
31

NEW
32
  await NotificationService.notifySubscribers(
×
33
    req,
34
    location,
35
    req.token.id,
36
    deletePermanently
×
37
      ? NotificationService.NOTIFICATION_TYPES.PERMANENT_DELETE
38
      : NotificationService.NOTIFICATION_TYPES.DELETE,
39
    NotificationService.NOTIFICATION_ENTITIES.LOCATION
40
  );
41

NEW
42
  return ControllerService.treatAndConvert(
×
43
    req,
44
    null,
45
    location,
46
    { controllerMethod: 'LocationController.delete' },
47
    res,
48
    toSimpleLocation
49
  );
50
};
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