Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

2.8 KB
Raw Blame
import { HttpMethod, httpClient } from '@activepieces/pieces-common';
import { wedofAuth } from '../../auth';
import { createAction, Property } from '@activepieces/pieces-framework';
import { wedofCommon } from '../../common/wedof';

export const cancelRegistrationFolder = createAction({
  auth: wedofAuth,
  name: 'cancelRegistrationFolder',
  classification: 'DESTRUCTIVE',
  displayName: 'Annuler le dossier de formation',
  description: 'Annuler le dossier de formation',
  audience: 'both',
  aiMetadata: {
    description:
      "Cancels a training registration folder, recording a required cancellation reason code and an optional explanatory note. Not idempotent: it advances the folder's lifecycle to a canceled state and should be called once. Distinct from refusing a folder, which uses a separate action and reason set.",
    idempotent: false,
  },
  props: {
    externalId: Property.ShortText({
      displayName: 'N° du dossier de formation',
      description:
        'Sélectionner la propriété {externalId} du dossier de formation',
      required: true,
    }),
    code: Property.Dropdown({
      auth: wedofAuth,
      displayName: "Raison de l'annulation du dossier de formation",
      description: "Sélectionner la raison de l'annulation",
      required: true,
      refreshers: ['auth'],
      refreshOnSearch: false,
      options: async ({ auth }) => {
        if (!auth) {
          return {
            disabled: true,
            options: [],
          };
        }
        const response = (
          await httpClient.sendRequest({
            method: HttpMethod.GET,
            url:
              wedofCommon.baseUrl + '/registrationFoldersReasons?type=canceled',
            headers: {
              'Content-Type': 'application/json',
              'X-Api-Key': auth.secret_text,
            },
          })
        ).body;
        const reasons = response.map(
          (reason: { label: string; code: string }) => {
            return { label: reason.label, value: reason.code };
          }
        );
        return {
          disabled: false,
          options: reasons,
        };
      },
    }),
    description: Property.LongText({
      displayName: 'Description',
      description: " Texte expliquant les raisons de l'annulation",
      required: false,
    }),
  },
  async run(context) {
    const message = {
      code: context.propsValue.code,
      description: context.propsValue.description,
    };

    return (
      await httpClient.sendRequest({
        method: HttpMethod.POST,
        url:
          wedofCommon.baseUrl +
          '/registrationFolders/' +
          context.propsValue.externalId +
          '/cancel',
        body: message,
        headers: {
          'Content-Type': 'application/json',
          'X-Api-Key': context.auth.secret_text,
        },
      })
    ).body;
  },
});