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

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

export const declareCertificationFolderToControl = createAction({
  auth: wedofAuth,
  name: 'declareCertificationFolderToControl',
  classification: 'WRITE',
  displayName: "Passer un dossier de certification à l'état : À contrôler",
  description: "Change l'état d'un dossier de certification vers : À contrôler",
  audience: 'both',
  aiMetadata: {
    description:
      "Transition a Wedof certification folder into the 'toControl' (to-be-reviewed) state, requiring the exam date and exam type plus optional enrollment/end dates, place, and comment. Pick this when the exam has been taken and the folder awaits review before a success/failure decision. Follows the certification-folder state machine and is not idempotent. Requires the folder's externalId.",
    idempotent: false,
  },
  props: {
    externalId: Property.ShortText({
      displayName: 'N° du dossier de certification',
      description:
        'Sélectionner la propriété {externalId} du dossier de certification',
      required: true,
    }),
    enrollmentDate: Property.DateTime({
      displayName: "Date d'inscription à la certification",
      description: 'Date au format YYYY-MM-DD.',
      required: false,
    }),
    examinationDate: Property.DateTime({
      displayName: "Date de passage de l'examen",
      description: 'Date au format YYYY-MM-DD.',
      required: true,
    }),
    examinationEndDate: Property.DateTime({
      displayName: "Date de fin de passage de l'examen",
      description: 'Date au format YYYY-MM-DD.',
      required: false,
    }),
    examinationType: Property.StaticDropdown({
      displayName: "Type de passage de l'examen",
      required: true,
      defaultValue: {
        value: 'A_DISTANCE',
        label: 'À distance',
      },
      options: {
        options: [
          {
            value: 'A_DISTANCE',
            label: 'À distance',
          },
          {
            value: 'EN_PRESENTIEL',
            label: 'En présentiel',
          },
          {
            value: 'MIXTE',
            label: 'Mixte',
          },
        ],
        disabled: false,
      },
    }),
    examinationPlace: Property.ShortText({
      displayName: "Lieu de passage de l'examen",
      required: false,
    }),
    comment: Property.LongText({
      displayName: 'Commentaire',
      required: false,
    }),
  },

  async run(context) {
    const message = {
      enrollmentDate: context.propsValue.enrollmentDate
        ? dayjs(context.propsValue.enrollmentDate).format('YYYY-MM-DD')
        : null,
      examinationDate: context.propsValue.examinationDate
        ? dayjs(context.propsValue.examinationDate).format('YYYY-MM-DD')
        : null,
      examinationEndDate: context.propsValue.examinationEndDate
        ? dayjs(context.propsValue.examinationEndDate).format('YYYY-MM-DD')
        : null,
      examinationType: context.propsValue.examinationType,
      examinationPlace: context.propsValue.examinationPlace,
      comment: context.propsValue.comment,
    };
    return (
      await httpClient.sendRequest({
        method: HttpMethod.POST,
        url:
          wedofCommon.baseUrl +
          '/certificationFolders/' +
          context.propsValue.externalId +
          '/control',
        body: message,
        headers: {
          'Content-Type': 'application/json',
          'X-Api-Key': context.auth.secret_text,
        },
      })
    ).body;
  },
});