Ghost/core/server/api/v2/webhooks.js
Rish 0a834d4223 Added webhooks controller to API v2
refs #9866

- Added new webhooks controller to v2 API
- Added webhooks tests to v2 API
2018-10-12 18:42:23 +05:30

47 lines
1.2 KiB
JavaScript

const models = require('../../models');
const common = require('../../lib/common');
module.exports = {
docName: 'webhooks',
add: {
statusCode: 201,
headers: {},
options: [],
permissions: true,
query(frame) {
return models.Webhook.getByEventAndTarget(
frame.data.webhooks[0].event,
frame.data.webhooks[0].target_url,
frame.options
).then((webhook) => {
if (webhook) {
return Promise.reject(
new common.errors.ValidationError({message: common.i18n.t('errors.api.webhooks.webhookAlreadyExists')})
);
}
return models.Webhook.add(frame.data.webhooks[0], frame.options);
});
}
},
destroy: {
statusCode: 204,
headers: {},
options: [
'id'
],
validation: {
options: {
id: {
required: true
}
}
},
permissions: true,
query(frame) {
frame.options.require = true;
return models.Webhook.destroy(frame.options).return(null);
}
}
};