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

GrottoCenter / grottocenter-api / 26025587471

18 May 2026 09:38AM UTC coverage: 86.841% (-0.2%) from 87.052%
26025587471

Pull #1566

github

dawoldo
refactor(1451): reformat object literals in account integration tests and update lockfile
Pull Request #1566: 1451 private messaging

3338 of 3994 branches covered (83.58%)

Branch coverage included in aggregate %.

206 of 245 new or added lines in 16 files covered. (84.08%)

3 existing lines in 1 file now uncovered.

6772 of 7648 relevant lines covered (88.55%)

55.11 hits per line

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

90.5
/api/services/NotificationService.js
1
const NameService = require('./NameService');
8✔
2
const CommonService = require('./CommonService');
8✔
3
const LanguageService = require('./LanguageService');
8✔
4

5
const NOTIFICATION_ENTITIES = {
8✔
6
  CAVE: 'cave',
7
  COMMENT: 'comment',
8
  DESCRIPTION: 'description',
9
  DOCUMENT: 'document',
10
  ENTRANCE: 'entrance',
11
  HISTORY: 'history',
12
  LOCATION: 'location',
13
  MASSIF: 'massif',
14
  ORGANIZATION: 'organization',
15
  RIGGING: 'rigging',
16
};
17

18
const NOTIFICATION_TYPES = {
8✔
19
  CREATE: 'CREATE',
20
  DELETE: 'DELETE',
21
  PERMANENT_DELETE: 'PERMANENT_DELETE',
22
  UPDATE: 'UPDATE',
23
  VALIDATE: 'VALIDATE',
24
  RESTORE: 'RESTORE',
25
  REJECT: 'REJECT',
26
};
27

28
async function removeOlderNotifications() {
29
  const query = `DELETE
×
30
                 FROM t_notification
31
                 WHERE date_inscription < current_timestamp - interval '2 month';`;
32
  await CommonService.query(query);
×
33
}
34

35
const safeGetPropId = (prop, data) => {
8✔
36
  if (data && data[prop]) {
1,920✔
37
    if (data[prop] instanceof Object) {
554✔
38
      return data[prop].id;
185✔
39
    }
40
    return data[prop];
369✔
41
  }
42
  return undefined;
1,366✔
43
};
44

45
const sendNotificationEmail = async (
8✔
46
  entity,
47
  notificationType,
48
  notificationEntity,
49
  user
50
) => {
51
  // Resolve the recipient's preferred locale
52
  const locale = await LanguageService.getLocale(user.language);
301✔
53

54
  // Get entity name (handle all cases)
55
  const getEntityName = (entityData) => {
301✔
56
    if (entityData.name) return entityData.name;
301✔
57
    if (entityData.names) return entityData.names[0]?.name;
31✔
58
    if (entityData.title) return entityData.title;
30✔
59
    if (entityData.titles) return entityData.titles[0]?.text;
16✔
60
    if (entityData.body) return `${entityData.body.slice(0, 50)}...`;
15✔
61
    if (entityData.descriptions) return entityData.descriptions[0].title;
14✔
62
    return '';
13✔
63
  };
64

65
  const entityName = getEntityName(entity);
301✔
66

67
  // Format action verb
68
  const actionVerbMap = {
301✔
69
    [NOTIFICATION_TYPES.CREATE]: 'created',
70
    [NOTIFICATION_TYPES.DELETE]: 'deleted',
71
    [NOTIFICATION_TYPES.PERMANENT_DELETE]: 'permanently deleted',
72
    [NOTIFICATION_TYPES.UPDATE]: 'updated',
73
    [NOTIFICATION_TYPES.VALIDATE]: 'validated',
74
    [NOTIFICATION_TYPES.RESTORE]: 'restored',
75
    [NOTIFICATION_TYPES.REJECT]: 'rejected',
76
  };
77

78
  const actionVerb = actionVerbMap[notificationType];
301✔
79
  if (!actionVerb) {
301✔
80
    throw Error(`Unknown notification type: ${notificationType}`);
1✔
81
  }
82

83
  // Format entity Link
84
  const baseUrl = `${sails.config.custom.baseUrl}/ui/`;
300✔
85
  const relatedCaveId = safeGetPropId('cave', entity);
300✔
86
  const relatedEntranceId = safeGetPropId('entrance', entity);
300✔
87
  const relatedMassifId = safeGetPropId('massif', entity);
300✔
88

89
  const getRelatedEntityLink = () => {
300✔
90
    if (relatedCaveId) return `caves/${relatedCaveId}`;
22✔
91
    if (relatedEntranceId) return `entrances/${relatedEntranceId}`;
20✔
92
    if (relatedMassifId) return `massifs/${relatedMassifId}`;
5✔
93
    return null;
4✔
94
  };
95

96
  const directLinkEntities = {
300✔
97
    [NOTIFICATION_ENTITIES.CAVE]: `caves/${entity.id}`,
98
    [NOTIFICATION_ENTITIES.DOCUMENT]: `documents/${entity.id}`,
99
    [NOTIFICATION_ENTITIES.ENTRANCE]: `entrances/${entity.id}`,
100
    [NOTIFICATION_ENTITIES.MASSIF]: `massifs/${entity.id}`,
101
    [NOTIFICATION_ENTITIES.ORGANIZATION]: `organizations/${entity.id}`,
102
  };
103

104
  let entityLink;
105
  if (directLinkEntities[notificationEntity]) {
300✔
106
    entityLink = baseUrl + directLinkEntities[notificationEntity];
278✔
107
  } else {
108
    const relatedLink = getRelatedEntityLink();
22✔
109
    if (!relatedLink) {
22✔
110
      const entityTypeName = notificationEntity.toLowerCase();
4✔
111
      let requiredEntities;
112
      if (notificationEntity === NOTIFICATION_ENTITIES.DESCRIPTION) {
4✔
113
        requiredEntities = 'cave, entrance or massif';
1✔
114
      } else if (notificationEntity === NOTIFICATION_ENTITIES.LOCATION) {
3✔
115
        requiredEntities = 'entrance';
1✔
116
      } else {
117
        requiredEntities = 'cave or entrance';
2✔
118
      }
119
      throw Error(
4✔
120
        `Can't find related entity (${requiredEntities}) of the ${entityTypeName} with id ${entity.id}`
121
      );
122
    }
123
    entityLink = baseUrl + relatedLink;
18✔
124
  }
125

126
  await sails.helpers.sendEmail
296✔
127
    .with({
128
      allowResponse: false,
129
      emailSubject: 'Notification',
130
      locale,
131
      recipientEmail: user.mail,
132
      viewName: 'notification',
133
      viewValues: {
134
        actionVerb,
135
        entityLink,
136
        entityName,
137
        entityType: notificationEntity,
138
        recipientName: user.nickname,
139
        subscriptionName: user.subscriptionName,
140
        subscriptionType: user.subscriptionType,
141
        isAuthorNotification: user.isAuthorNotification || false,
391✔
142
        validationComment: user.validationComment || null,
411✔
143
      },
144
    })
145
    .intercept('sendSESEmailError', () => {
146
      sails.log.error(
×
147
        `The email service has encountered an error while trying to notify user ${user.nickname} (id=${user.id}).`
148
      );
149
      return false;
×
150
    });
151
};
152

153
const getCountryMassifAndRegionSubscribers = async (
8✔
154
  entityCountryId,
155
  entityMassifIds,
156
  entityRegionId
157
) => {
158
  const countrySubscribers = [];
146✔
159
  const massifsSubscribers = [];
146✔
160
  const regionSubscribers = [];
146✔
161
  if (entityCountryId) {
146✔
162
    const country =
163
      await TCountry.findOne(entityCountryId).populate('subscribedCavers');
3✔
164
    if (country) {
3!
165
      countrySubscribers.push(
3✔
166
        ...country.subscribedCavers.map((caver) => ({
3✔
167
          ...caver,
168
          subscriptionName: country.nativeName,
169
          subscriptionType: 'country',
170
        }))
171
      );
172
    }
173
  }
174
  if (entityMassifIds) {
146!
175
    await Promise.all(
146✔
176
      entityMassifIds.map(async (massifId) => {
177
        const massif =
178
          await TMassif.findOne(massifId).populate('subscribedCavers');
77✔
179
        if (massif) {
77✔
180
          await NameService.setNames([massif], 'massif');
73✔
181
          massifsSubscribers.push(
73✔
182
            ...massif.subscribedCavers.map((caver) => ({
63✔
183
              ...caver,
184
              subscriptionType: 'massif',
185
              subscriptionName: massif.names[0]?.name,
186
            }))
187
          );
188
        }
189
      })
190
    );
191
  }
192
  if (entityRegionId) {
146✔
193
    const region =
194
      await TISO31662.findOne(entityRegionId).populate('subscribedCavers');
3✔
195
    if (region) {
3!
196
      regionSubscribers.push(
3✔
197
        ...region.subscribedCavers.map((caver) => ({
3✔
198
          ...caver,
199
          subscriptionName: region.name,
200
          subscriptionType: 'region',
201
        }))
202
      );
203
    }
204
  }
205
  return { countrySubscribers, massifsSubscribers, regionSubscribers };
146✔
206
};
207

208
module.exports = {
8✔
209
  NOTIFICATION_ENTITIES,
210
  notifyMessageRecipient: async (req, senderId, conversationId) => {
211
    try {
7✔
212
      const sender = await TCaver.findOne({ id: senderId });
7✔
213
      if (!sender) return;
7!
214
      const query = `SELECT id_caver FROM j_participant WHERE id_conversation = $1 AND id_caver != $2`;
7✔
215
      const result = await CommonService.query(query, [
7✔
216
        conversationId,
217
        senderId,
218
      ]);
219
      if (result.rows.length === 0) return;
7!
220
      await Promise.all(
7✔
221
        result.rows.map(async (row) => {
222
          const recipient = await TCaver.findOne({ id: row.id_caver });
7✔
223
          if (!recipient || !recipient.sendMessageNotificationByEmail) return;
7✔
224
          const conversationLink = `${sails.config.custom.frontendUrl}/ui/messages/${conversationId}`;
5✔
225
          await sails.helpers.sendEmail
5✔
226
            .with({
227
              allowResponse: false,
228
              emailSubject: 'New Message',
229
              i18n: req.i18n,
230
              recipientEmail: recipient.mail,
231
              viewName: 'new-message',
232
              viewValues: {
233
                senderNickname: sender.nickname,
234
                conversationLink,
235
                recipientName: recipient.nickname,
236
              },
237
            })
238
            .intercept('sendSESEmailError', () => {
NEW
239
              sails.log.error(
×
240
                `The email service error notifying user ${recipient.nickname}.`
241
              );
NEW
242
              return false;
×
243
            });
244
        })
245
      );
246
    } catch (error) {
247
      sails.log.error(
5✔
248
        `An error occurred in notifyMessageRecipient: ${error.message}`
249
      );
250
    }
251
  },
252
  NOTIFICATION_TYPES,
253
  ...(process.env.NODE_ENV === 'test' ? { sendNotificationEmail } : undefined),
8!
254

255
  /**
256
   *
257
   * @param {*} entity
258
   * @param {Number} notifierId
259
   * @param {NOTIFICATION_TYPES} notificationType
260
   * @param {NOTIFICATION_ENTITIES} notificationEntity
261
   * @return {Boolean} true if everything went well, else false
262
   */
263
  notifySubscribers: async (
264
    entity,
265
    notifierId,
266
    notificationType,
267
    notificationEntity
268
  ) => {
269
    // Had to require in the function to avoid a circular dependency with notifySubscribers() in CaveService.createCave()
270
    // eslint-disable-next-line global-require
271
    const CaveService = require('./CaveService');
157✔
272

273
    // Check params and silently fail to avoid sending an error to the client
274
    if (!Object.values(NOTIFICATION_ENTITIES).includes(notificationEntity)) {
157✔
275
      throw new Error(`Invalid notification entity: ${notificationEntity}`);
1✔
276
    }
277
    if (!Object.values(NOTIFICATION_TYPES).includes(notificationType)) {
156✔
278
      throw new Error(`Invalid notification type: ${notificationType}`);
1✔
279
    }
280
    if (!notifierId) {
155✔
281
      throw new Error(`Missing notifier id`);
1✔
282
    }
283

284
    try {
154✔
285
      // For the populateEntities() method, must use "grotto" instead of "organization"
286
      const entityKey =
287
        notificationEntity === NOTIFICATION_ENTITIES.ORGANIZATION
154✔
288
          ? 'grotto'
289
          : notificationEntity;
290

291
      // Format notification and populate entity
292
      const notification = await module.exports.populateEntities({
154✔
293
        dateInscription: new Date(),
294
        notificationType: (
295
          await TNotificationType.findOne({
296
            name: notificationType,
297
          })
298
        ).id,
299
        notifier: notifierId,
300
        [entityKey]: entity,
301
      });
302

303
      const populatedEntity = notification[entityKey];
154✔
304

305
      const caveId = safeGetPropId('cave', populatedEntity);
154✔
306
      const entranceId = safeGetPropId('entrance', populatedEntity);
154✔
307
      const massifId = safeGetPropId('massif', populatedEntity);
154✔
308

309
      const getMassifIdsFromCave = async (id) =>
154✔
310
        (await CaveService.getMassifs(id)).map((m) => m.id);
76✔
311
      const getCountryId = (id) => safeGetPropId('country', id);
154✔
312
      const getRegionId = (entityData) => entityData?.iso_3166_2;
154✔
313

314
      const getCountryFromCaveEntrances = (cave) => {
154✔
315
        if (cave?.entrances?.length > 0) {
16✔
316
          return getCountryId(cave.entrances[0]);
5✔
317
        }
318
        return null;
11✔
319
      };
320

321
      const resolveLocationFromCaveOrEntrance = async (
154✔
322
        relatedCaveId,
323
        relatedEntranceId,
324
        entityData
325
      ) => {
326
        if (relatedCaveId) {
65✔
327
          return {
3✔
328
            countryId: getCountryFromCaveEntrances(entityData.cave),
329
            massifIds: await getMassifIdsFromCave(relatedCaveId),
330
            regionId: entityData.cave?.entrances?.[0]
3!
331
              ? getRegionId(entityData.cave.entrances[0])
332
              : null,
333
          };
334
        }
335
        if (relatedEntranceId) {
62✔
336
          return {
19✔
337
            countryId: getCountryId(entityData.entrance),
338
            massifIds: await getMassifIdsFromCave(
339
              safeGetPropId('cave', entityData.entrance)
340
            ),
341
            regionId: getRegionId(entityData.entrance),
342
          };
343
        }
344
        return { countryId: null, massifIds: [], regionId: null };
43✔
345
      };
346

347
      // Entity-specific location resolution
348
      const entityResolvers = {
154✔
349
        [NOTIFICATION_ENTITIES.CAVE]: async () => ({
13✔
350
          countryId: getCountryFromCaveEntrances(populatedEntity),
351
          massifIds: await getMassifIdsFromCave(populatedEntity.id),
352
          regionId: populatedEntity?.entrances?.[0]
13✔
353
            ? getRegionId(populatedEntity.entrances[0])
354
            : null,
355
        }),
356

357
        [NOTIFICATION_ENTITIES.ENTRANCE]: async () => ({
38✔
358
          countryId: getCountryId(populatedEntity),
359
          massifIds: populatedEntity?.cave
38✔
360
            ? await getMassifIdsFromCave(safeGetPropId('cave', populatedEntity))
361
            : [],
362
          regionId: getRegionId(populatedEntity),
363
        }),
364

365
        [NOTIFICATION_ENTITIES.MASSIF]: async () => ({
11✔
366
          countryId: null,
367
          massifIds: [populatedEntity.id],
368
          regionId: null,
369
        }),
370

371
        [NOTIFICATION_ENTITIES.ORGANIZATION]: async () => ({
16✔
372
          countryId: getCountryId(populatedEntity),
373
          massifIds: [],
374
          regionId: getRegionId(populatedEntity),
375
        }),
376

377
        [NOTIFICATION_ENTITIES.LOCATION]: async () => {
378
          if (!entranceId)
11✔
379
            throw new Error(`Can't retrieve related entrance id.`);
2✔
380
          return {
9✔
381
            countryId: getCountryId(populatedEntity.entrance),
382
            massifIds: await getMassifIdsFromCave(
383
              safeGetPropId('cave', populatedEntity.entrance)
384
            ),
385
            regionId: getRegionId(populatedEntity.entrance),
386
          };
387
        },
388
      };
389

390
      // Entities that can relate to cave, entrance, or massif
391
      const multiRelationEntities = [
154✔
392
        NOTIFICATION_ENTITIES.COMMENT,
393
        NOTIFICATION_ENTITIES.DESCRIPTION,
394
        NOTIFICATION_ENTITIES.HISTORY,
395
        NOTIFICATION_ENTITIES.RIGGING,
396
      ];
397

398
      // Find massifs and country concerned about the notification
399
      let result;
400
      if (entityResolvers[notificationEntity]) {
154✔
401
        result = await entityResolvers[notificationEntity]();
89✔
402
      } else if (multiRelationEntities.includes(notificationEntity)) {
65✔
403
        result = await resolveLocationFromCaveOrEntrance(
30✔
404
          caveId,
405
          entranceId,
406
          populatedEntity
407
        );
408

409
        // Handle massif-only case for description and document
410
        if (!result.countryId && !result.massifIds.length && massifId) {
30!
411
          result.massifIds = [safeGetPropId('massif', populatedEntity)];
×
412
        }
413

414
        // Require cave or entrance for most entities
415
        if (
30✔
416
          !caveId &&
65✔
417
          !entranceId &&
418
          ![
419
            NOTIFICATION_ENTITIES.DESCRIPTION,
420
            NOTIFICATION_ENTITIES.DOCUMENT,
421
          ].includes(notificationEntity)
422
        ) {
423
          throw new Error(`Can't retrieve related cave or entrance id.`);
6✔
424
        }
425
      } else if (notificationEntity === NOTIFICATION_ENTITIES.DOCUMENT) {
35!
426
        result = await resolveLocationFromCaveOrEntrance(
35✔
427
          caveId,
428
          entranceId,
429
          populatedEntity
430
        );
431
        if (!result.countryId && !result.massifIds.length && massifId) {
35!
432
          result.massifIds = [safeGetPropId('massif', populatedEntity)];
×
433
        }
434
      } else {
435
        throw new Error(
×
436
          `Can't find what to do with the following notification entity value: ${notificationEntity}`
437
        );
438
      }
439

440
      const entityCountryId = result.countryId;
146✔
441
      const entityMassifIds = result.massifIds;
146✔
442
      const entityRegionId = result.regionId;
146✔
443

444
      // Find subscribers to the entity.
445
      const { countrySubscribers, massifsSubscribers, regionSubscribers } =
446
        await getCountryMassifAndRegionSubscribers(
146✔
447
          entityCountryId,
448
          entityMassifIds,
449
          entityRegionId
450
        );
451
      // Consolidate subscribers by user ID and combine subscription types
452
      const subscriberMap = new Map();
146✔
453

454
      const addSubscribers = (subscribers) => {
146✔
455
        subscribers
438✔
456
          .filter((u) => u.id !== notifierId)
69✔
457
          .forEach((user) => {
458
            if (subscriberMap.has(user.id)) {
69✔
459
              const existing = subscriberMap.get(user.id);
2✔
460
              existing.subscriptionNames.push(user.subscriptionName);
2✔
461
              existing.subscriptionTypes.push(user.subscriptionType);
2✔
462
            } else {
463
              subscriberMap.set(user.id, {
67✔
464
                ...user,
465
                subscriptionNames: [user.subscriptionName],
466
                subscriptionTypes: [user.subscriptionType],
467
              });
468
            }
469
          });
470
      };
471

472
      addSubscribers(countrySubscribers);
146✔
473
      addSubscribers(massifsSubscribers);
146✔
474
      addSubscribers(regionSubscribers);
146✔
475

476
      const uniqueUsers = Array.from(subscriberMap.values()).map((user) => ({
146✔
477
        ...user,
478
        subscriptionName: user.subscriptionNames.join(' and '),
479
        subscriptionType: user.subscriptionTypes.join(', '),
480
      }));
481

482
      // Create notifications & optionally send email
483
      const res = await Promise.all(
146✔
484
        uniqueUsers.map(async (user) => {
485
          try {
67✔
486
            await TNotification.create({
67✔
487
              ...notification,
488
              notified: user.id,
489
              [entityKey]: notification[entityKey].id, // id only for the DB storage
490
            });
491
          } catch (e) {
492
            sails.log.error(
×
493
              `An error occured when trying to create a notification: ${e.message}`
494
            );
495
            return false;
×
496
          }
497

498
          if (user.sendNotificationByEmail) {
67!
499
            await sendNotificationEmail(
×
500
              populatedEntity,
501
              notificationType,
502
              notificationEntity,
503
              user
504
            );
505
          }
506
          return true;
67✔
507
        })
508
      );
509

510
      // 5% chance to also remove older notifications
511
      if (process.env.NODE_ENV !== 'test' && Math.random() < 0.05) {
146!
512
        try {
×
513
          await removeOlderNotifications();
×
514
        } catch (cleanupError) {
515
          sails.log.error(
×
516
            `Error during notification cleanup: ${cleanupError.message}`
517
          );
518
        }
519
      }
520

521
      return res;
146✔
522
    } catch (error) {
523
      // Fail silently to avoid sending an error to the user
524
      sails.log.error(
8✔
525
        `An error occurred when trying to notify subscribers: ${error.message} ${error.stack}`
526
      );
527
      return false;
8✔
528
    }
529
  },
530

531
  /**
532
   * Create an in-app notification for the document author and optionally send an email.
533
   *
534
   * @param {Object}  document         - Populated TDocument (must have .author)
535
   * @param {Number}  moderatorId      - ID of the moderator who made the decision
536
   * @param {String}  notificationType - NOTIFICATION_TYPES.VALIDATE or NOTIFICATION_TYPES.REJECT
537
   * @param {String|null} validationComment - Moderator's comment (required for REJECT)
538
   * @returns {Boolean} true on success, false on silent failure
539
   */
540
  notifyAuthor: async (
541
    document,
542
    moderatorId,
543
    notificationType,
544
    validationComment
545
  ) => {
546
    const authorId = safeGetPropId('author', document);
323✔
547
    if (!authorId) {
323✔
548
      sails.log.debug(
1✔
549
        `notifyAuthor: document ${document.id} has no author, skipping notification`
550
      );
551
      return true;
1✔
552
    }
553
    if (authorId === moderatorId) {
322✔
554
      return true;
103✔
555
    }
556

557
    if (!Object.values(NOTIFICATION_TYPES).includes(notificationType)) {
219!
558
      throw new Error(`Invalid notification type: ${notificationType}`);
×
559
    }
560

561
    try {
219✔
562
      const notificationTypeRecord = await TNotificationType.findOne({
219✔
563
        name: notificationType,
564
      });
565

566
      if (!notificationTypeRecord) {
219!
567
        throw new Error(
×
568
          `Notification type '${notificationType}' not found in DB — migration may not have run`
569
        );
570
      }
571

572
      await TNotification.create({
219✔
573
        dateInscription: new Date(),
574
        notificationType: notificationTypeRecord.id,
575
        notifier: moderatorId,
576
        notified: authorId,
577
        document: document.id,
578
      });
579

580
      const author = await TCaver.findOne(authorId);
219✔
581

582
      if (author && author.sendNotificationByEmail) {
219✔
583
        await sendNotificationEmail(
57✔
584
          document,
585
          notificationType,
586
          NOTIFICATION_ENTITIES.DOCUMENT,
587
          {
588
            ...author,
589
            isAuthorNotification: true,
590
            validationComment,
591
          }
592
        );
593
      }
594

595
      return true;
219✔
596
    } catch (error) {
597
      sails.log.error(
×
598
        `An error occurred when trying to notify the document author: ${error.message} ${error.stack}`
599
      );
600
      return false;
×
601
    }
602
  },
603

604
  populateEntities: async (notification) => {
605
    const populatedNotification = notification;
204✔
606
    if (populatedNotification.cave) {
204✔
607
      await NameService.setNames([populatedNotification.cave], 'cave');
15✔
608
    }
609
    if (populatedNotification.comment) {
204✔
610
      populatedNotification.comment = await TComment.findOne(
11✔
611
        safeGetPropId('comment', notification)
612
      )
613
        .populate('cave')
614
        .populate('entrance');
615
    }
616
    if (populatedNotification.description) {
204✔
617
      populatedNotification.description = await TDescription.findOne(
10✔
618
        safeGetPropId('description', notification)
619
      )
620
        .populate('cave')
621
        .populate('document')
622
        .populate('entrance')
623
        .populate('massif');
624
    }
625
    if (populatedNotification.document) {
204✔
626
      // Had to require in the function to avoid a circular dependency with notifySubscribers() in DocumentService.createDocument()
627
      // eslint-disable-next-line global-require
628
      const DocumentService = require('./DocumentService');
42✔
629
      const populatedDocuments = await DocumentService.getDocuments([
42✔
630
        safeGetPropId('document', notification),
631
      ]);
632
      populatedNotification.document = populatedDocuments[0];
42✔
633
    }
634
    if (populatedNotification.entrance) {
204✔
635
      await NameService.setNames([populatedNotification.entrance], 'entrance');
53✔
636
    }
637
    if (populatedNotification.grotto) {
204✔
638
      await NameService.setNames([populatedNotification.grotto], 'grotto');
16✔
639
    }
640
    if (populatedNotification.history) {
204✔
641
      populatedNotification.history = await THistory.findOne(
7✔
642
        safeGetPropId('history', notification)
643
      )
644
        .populate('cave')
645
        .populate('entrance');
646
    }
647
    if (populatedNotification.location) {
204✔
648
      populatedNotification.location = await TLocation.findOne(
12✔
649
        safeGetPropId('location', notification)
650
      ).populate('entrance');
651
    }
652
    if (populatedNotification.massif) {
204✔
653
      await NameService.setNames([populatedNotification.massif], 'massif');
11✔
654
    }
655
    if (populatedNotification.rigging) {
204✔
656
      populatedNotification.rigging = await TRigging.findOne(
6✔
657
        safeGetPropId('rigging', notification)
658
      )
659
        .populate('entrance')
660
        .populate('cave');
661
    }
662
    return populatedNotification;
204✔
663
  },
664
};
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