mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
47 lines
1.2 KiB
JavaScript
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);
|
||
|
}
|
||
|
}
|
||
|
};
|