-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·42 lines (34 loc) · 1.22 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
/*
* Module initialization as Loopback component.
* Copyright (c) 2018. ALIA Technologies S.L.
* Project: loopback-component-traceability
* File: index.js
* Author: Juan Costa <[email protected]>
*/
const _ = require('lodash');
const EventType = require('./lib/event-type');
const EventService = require('./lib/event-service');
const Options = require('./lib/options-class');
const debug = require('./lib/debug').create('init');
/**
* Initialize module as Loopback component.
* @param {Object} app Loopback app instance
* @param {Object} componentOptions Loopback component options
*/
const Component = module.exports = function (app, componentOptions = {}) {
// Attach to app a reference to the component
app.__traceabilityComponent = Component;
// Build options
const options = Options.create(app);
options.extend(componentOptions);
// Configure event types
_.each(options.events, (eventOptions, eventType) => {
EventType.addType(eventType, eventOptions);
});
// Configure service
Component.service = EventService.getInstance(app, options);
// Configure model event dynamic relations once it's attached to app
app.models.ModelEvent.setupRelations(options);
debug('initialized');
};