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 { 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 declareCertificationFolderSuccess = createAction({
  auth: wedofAuth,
  name: 'declareCertificationFolderSuccess',
  classification: 'WRITE',
  displayName: "Passer un dossier de certification à l'état : Réussi",
  description: "Change l'état d'un dossier de certification vers : Réussi",
  audience: 'both',
  aiMetadata: {
    description:
      "Transition a Wedof certification folder into the 'success' (passed) state, recording the required issue date plus optional detailed result, European language level, digital-proof link, and grade. Pick this when the candidate has obtained the certification; use the 'failed' or 'toRetake' actions for other outcomes. 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,
    }),
    detailedResult: Property.ShortText({
      displayName: "Détail du résultat de l'examen",
      required: false,
    }),
    europeanLanguageLevel: wedofCommon.europeanLanguageLevel,
    issueDate: Property.DateTime({
      displayName: "Date d'obtention de la certification",
      description: 'Date au format YYYY-MM-DD.',
      required: true,
    }),
    digitalProofLink: Property.ShortText({
      displayName:
        "Lien vers la preuve numérique de l'obtention de la certification",
      required: false,
    }),
    gradePass: wedofCommon.gradePass,
    comment: Property.LongText({
      displayName: 'Commentaire',
      required: false,
    }),
  },
  async run(context) {
    const message = {
      detailedResult: context.propsValue.detailedResult,
      issueDate: context.propsValue.issueDate
        ? dayjs(context.propsValue.issueDate).format('YYYY-MM-DD')
        : null,
      digitalProofLink: context.propsValue.digitalProofLink,
      europeanLanguageLevel: context.propsValue.europeanLanguageLevel,
      gradePass: context.propsValue.gradePass,
      comment: context.propsValue.comment,
    };
    return (
      await httpClient.sendRequest({
        method: HttpMethod.POST,
        url:
          wedofCommon.baseUrl +
          '/certificationFolders/' +
          context.propsValue.externalId +
          '/success',
        body: message,
        headers: {
          'Content-Type': 'application/json',
          'X-Api-Key': context.auth.secret_text,
        },
      })
    ).body;
  },
});