-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.js
62 lines (50 loc) · 1.72 KB
/
main.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use strict'
/*
* Primary file for App
*
*/
// Dependencies
const handlers = require('./lib/handlers')
const {
init: cliInit
} = require('./lib/cli')
const {
TenantRepository
} = require('./lib/repository')
// get the reference of EventEmitter class of events module
const events = require('events')
// create an object of EventEmitter class by using above reference
global.em = new events.EventEmitter()
// Declare the app
let app = {}
/**
* Init function
*
*/
app.init = async () => {
// Start the CLI
cliInit()
// Get a reference to the TenantRepository
const tenant = await new TenantRepository()
// Bind the connection event with the listener function
em.on('requestUrl', tenant.currentDB)
// Fire the requestUrl event.
em.emit('requestUrl', process.env.TENANCY_DEFAULT_HOSTNAME.toLowerCase())
}
// Export the app
module.exports = {
init: () => app.init(),
findAll: (modelName) => handlers.findAll(modelName),
createTenant: (fqdn) => handlers.createTenant(fqdn),
tenantExists: (fqdn) => handlers.tenantExists(fqdn),
deleteTenant: (fqdn) => handlers.deleteTenant(fqdn),
truncate: (modelName) => handlers.truncate(modelName),
delete: (modelName, key) => handlers.delete(modelName, key),
findById: (modelName, id) => handlers.findById(modelName, id),
executeQuery: (sqlCommand) => handlers.executeQuery(sqlCommand),
findFirst: (modelName, key) => handlers.findFirst(modelName, key),
getTenantConnectionString: () => handlers.getTenantConnectionString(),
create: (modelName, dataObject) => handlers.create(modelName, dataObject),
updateTenant: (fqdn, dataObject) => handlers.updateTenant(fqdn, dataObject),
update: (modelName, key, dataObject) => handlers.update(modelName, key, dataObject)
}