1
0
Fork 0
mirror of synced 2024-09-18 10:20:11 +12:00
budibase/packages/server/src/api/controllers/client.js

32 lines
791 B
JavaScript
Raw Normal View History

2020-05-15 02:12:30 +12:00
const { create, destroy } = require("../../db/clientDb")
const env = require("../../environment")
exports.getClientId = async function(ctx) {
2020-05-15 02:12:30 +12:00
ctx.body = env.CLIENT_ID
2020-05-07 21:53:34 +12:00
}
2020-04-10 03:53:48 +12:00
exports.create = async function(ctx) {
const clientId = getClientId(ctx)
await create(clientId)
2020-05-15 02:12:30 +12:00
ctx.status = 200
ctx.message = `Client Database ${clientId} successfully provisioned.`
2020-05-07 21:53:34 +12:00
}
2020-04-10 03:53:48 +12:00
exports.destroy = async function(ctx) {
const clientId = getClientId(ctx)
await destroy(clientId)
2020-05-15 02:12:30 +12:00
ctx.status = 200
ctx.message = `Client Database ${clientId} successfully deleted.`
}
const getClientId = ctx => {
const clientId =
(ctx.query && ctx.query.clientId) ||
(ctx.body && ctx.body.clientId) ||
env.CLIENT_ID
if (!clientId) {
ctx.throw(400, "ClientId not suplied")
}
return clientId
2020-05-07 21:53:34 +12:00
}