-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathtenants.js
executable file
·38 lines (31 loc) · 1.19 KB
/
tenants.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
const express = require('express');
const router = express.Router({ mergeParams: true });
const { requireUSDRSuperAdminUser } = require('../lib/access-helpers');
const {
getTenants, setTenantDisplayName, knex,
} = require('../db');
const { createTenant, validateCreateTenantOptions } = require('../db/tenant_creation');
router.get('/', requireUSDRSuperAdminUser, async (req, res) => {
const allTenants = await getTenants();
res.json(allTenants);
});
router.post('/', requireUSDRSuperAdminUser, async (req, res) => {
const result = await knex.transaction(async (trns) => {
const options = req.body;
const valid = await validateCreateTenantOptions(options, trns);
if (valid !== true) {
res.status(400).json({ error: valid });
return null;
}
return createTenant(options, trns);
});
res.json(result);
});
router.put('/:tenantId', requireUSDRSuperAdminUser, async (req, res) => {
// Only display name is mutable after creation.
const { tenantId } = req.params;
const { displayName } = req.body;
const result = await setTenantDisplayName(tenantId, displayName);
res.json(result);
});
module.exports = router;