UNPKG

ade-planning-api

Version:

An unofficial API wrapper for ADE Planning from Adesoft

33 lines (32 loc) 1.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getProjects = getProjects; exports.setProject = setProject; /** * Get the projects list * @param fetcher ADEFetcher instance * @returns A list of projects (Project[]) */ async function getProjects(fetcher) { const data = await fetcher.get({ function: "getProjects", detail: 2 }); // Fetch the projects data // Convert the data to the Projects interface return data.projects.project.map(item => { if (!item.$.id || !item.$.name || !item.$.uid) { // Check if the data is valid throw new Error("Invalid project data"); } return { id: parseInt(item.$.id, 10), name: item.$.name, uid: parseInt(item.$.uid, 10), }; }); } /** * Set the project * @param fetcher ADEFetcher instance * @param project The project to set * @returns void */ async function setProject(fetcher, project) { await fetcher.get({ function: "setProject", projectId: project.id }); // Set the project }