2019-12-13 17:59:07 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
async listWebhooks(ctx) {
|
2019-12-17 11:24:14 +01:00
|
|
|
const webhooks = await strapi.webhookStore.findWebhooks();
|
2019-12-13 17:59:07 +01:00
|
|
|
ctx.body = { data: webhooks };
|
|
|
|
},
|
|
|
|
|
|
|
|
async createWebhook(ctx) {
|
|
|
|
const { name, url, headers, events } = ctx.request.body;
|
|
|
|
|
2019-12-17 11:24:14 +01:00
|
|
|
const webhook = await strapi.webhookStore.createWebhook({
|
2019-12-13 17:59:07 +01:00
|
|
|
name,
|
|
|
|
url,
|
|
|
|
headers,
|
|
|
|
events,
|
2019-12-17 10:35:04 +01:00
|
|
|
isEnabled: true,
|
2019-12-13 17:59:07 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
ctx.body = { data: webhook };
|
|
|
|
},
|
|
|
|
|
|
|
|
async getWebhook(ctx) {
|
|
|
|
const { id } = ctx.params;
|
2019-12-17 11:24:14 +01:00
|
|
|
const webhook = await strapi.webhookStore.findWebhook(id);
|
2019-12-13 17:59:07 +01:00
|
|
|
|
|
|
|
ctx.body = { data: webhook };
|
|
|
|
},
|
|
|
|
|
|
|
|
async updateWebhook(ctx) {
|
|
|
|
const { id } = ctx.params;
|
2019-12-17 10:35:04 +01:00
|
|
|
const { name, url, headers, events, isEnabled } = ctx.request.body;
|
2019-12-13 17:59:07 +01:00
|
|
|
|
2019-12-17 11:24:14 +01:00
|
|
|
const webhook = await strapi.webhookStore.findWebhook(id);
|
2019-12-13 17:59:07 +01:00
|
|
|
|
|
|
|
if (!webhook) {
|
|
|
|
return ctx.send({ error: 'webhook.notFound' }, 404);
|
|
|
|
}
|
|
|
|
|
2019-12-17 11:24:14 +01:00
|
|
|
const updatedWebhook = await strapi.webhookStore.updateWebhook(id, {
|
2019-12-13 17:59:07 +01:00
|
|
|
name,
|
|
|
|
url,
|
|
|
|
headers,
|
|
|
|
events,
|
2019-12-17 10:35:04 +01:00
|
|
|
isEnabled,
|
2019-12-13 17:59:07 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
ctx.body = { data: updatedWebhook };
|
|
|
|
},
|
|
|
|
|
|
|
|
async deleteWebhook(ctx) {
|
|
|
|
const { id } = ctx.params;
|
2019-12-17 11:24:14 +01:00
|
|
|
const webhook = await strapi.webhookStore.findWebhook(id);
|
2019-12-13 17:59:07 +01:00
|
|
|
|
|
|
|
if (!webhook) {
|
|
|
|
return ctx.send({ error: 'webhook.notFound' }, 404);
|
|
|
|
}
|
|
|
|
|
2019-12-17 11:24:14 +01:00
|
|
|
await strapi.webhookStore.deleteWebhook(id);
|
2019-12-13 17:59:07 +01:00
|
|
|
ctx.body = { data: webhook };
|
|
|
|
},
|
|
|
|
|
|
|
|
triggerWebhook(ctx) {
|
|
|
|
ctx.body = { data: {} };
|
|
|
|
},
|
|
|
|
};
|