2021-03-22 17:39:11 +01:00
|
|
|
const builderDB = require("../../db/builder")
|
2020-07-02 17:53:09 +02:00
|
|
|
|
2020-07-06 09:06:59 +02:00
|
|
|
exports.fetch = async function(ctx) {
|
2021-03-22 17:39:11 +01:00
|
|
|
try {
|
|
|
|
const mainDoc = await builderDB.getBuilderMainDoc()
|
|
|
|
ctx.body = mainDoc.apiKeys ? mainDoc.apiKeys : {}
|
|
|
|
} catch (err) {
|
|
|
|
/* istanbul ignore next */
|
|
|
|
ctx.throw(400, err)
|
2020-07-06 09:06:59 +02:00
|
|
|
}
|
2020-07-02 17:53:09 +02:00
|
|
|
}
|
|
|
|
|
2020-07-06 09:06:59 +02:00
|
|
|
exports.update = async function(ctx) {
|
2021-03-22 17:39:11 +01:00
|
|
|
const key = ctx.params.key
|
2020-07-06 09:06:59 +02:00
|
|
|
const value = ctx.request.body.value
|
2020-10-28 21:35:06 +01:00
|
|
|
|
2021-03-22 17:39:11 +01:00
|
|
|
try {
|
|
|
|
const mainDoc = await builderDB.getBuilderMainDoc()
|
|
|
|
if (mainDoc.apiKeys == null) {
|
|
|
|
mainDoc.apiKeys = {}
|
2020-07-06 09:06:59 +02:00
|
|
|
}
|
2021-03-22 17:39:11 +01:00
|
|
|
mainDoc.apiKeys[key] = value
|
|
|
|
const resp = await builderDB.setBuilderMainDoc(mainDoc)
|
|
|
|
ctx.body = {
|
|
|
|
_id: resp.id,
|
|
|
|
_rev: resp.rev,
|
2020-07-06 09:06:59 +02:00
|
|
|
}
|
2021-03-22 17:39:11 +01:00
|
|
|
} catch (err) {
|
|
|
|
/* istanbul ignore next */
|
|
|
|
ctx.throw(400, err)
|
|
|
|
}
|
2020-07-02 17:53:09 +02:00
|
|
|
}
|