All files / src/commands/webhooks webhooks.remove.command.js

75% Statements 18/24
100% Branches 1/1
0% Functions 0/1
75% Lines 18/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x             193x 193x  
import { deleteWebhook } from '@clevercloud/client/esm/api/v2/notification.js';
import { defineCommand } from '../../lib/define-command.js';
import { Logger } from '../../logger.js';
import { getOwnerIdFromOrgIdOrName } from '../../models/ids-resolver.js';
import { sendToApi } from '../../models/send-to-api.js';
import { notificationIdArg } from '../global.args.js';
import { orgaIdOrNameOption } from '../global.options.js';
 
export const webhooksRemoveCommand = defineCommand({
  description: 'Remove an existing webhook',
  since: '0.6.0',
  options: {
    org: orgaIdOrNameOption,
  },
  args: [notificationIdArg],
  async handler(options, notificationId) {
    const { org } = options;

    const ownerId = await getOwnerIdFromOrgIdOrName(org);
    await deleteWebhook({ ownerId, id: notificationId }).then(sendToApi);

    Logger.println('The notification has been successfully removed');
  },
});