Advertisement
masiur

trello importer

May 7th, 2024
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.95 KB | Source Code | 0 0
  1.  
  2. // Make a file upload for user so that they can upload the json file. Then read the file
  3. const jsonfile = require('jsonfile');
  4.  
  5. const jsonFilePath = './premium.json';
  6.  
  7. async function importData() {
  8.     let data;
  9.     data = await jsonfile.readFile(jsonFilePath);
  10.     // console.log(data);
  11.  
  12.     let ProjectName = data.name;
  13.     console.log(ProjectName);
  14.  
  15.     const ProjectData = {
  16.         name: ProjectName,
  17.         description: data.desc, // need to strip tags if markdown to html find a library or something
  18.         businessId: 1, // getCurrentBusinessId()
  19.         leadId: 1, // getCurrentLeadId()
  20.         status : 'active', // as per your need
  21.     };
  22.     console.log(ProjectData);
  23.  
  24.     // now section/stage/list creation
  25.     let lists = data.lists;
  26.     let listSectionMapper = {};
  27.  
  28.     // create a foreach loop for lists
  29.     for (const list of lists) {
  30.         const sectionData = {
  31.             name: list.name,
  32.             projectId: 1, // newly created project id
  33.             order: list.pos,
  34.         };
  35.         console.log(sectionData);
  36.         // Create Section in Database Here
  37.         // let sectionId = 'Insert into ProjectSection in Database and get the sectionId here';
  38.         listSectionMapper[list.id] = sectionId;
  39.     }
  40.  
  41.     // now card/task creation
  42.     let cards = data.cards;
  43.     for (let card of cards) {
  44.         const taskData = {
  45.             title: card.name,
  46.             description: card.desc, // need to strip tags if markdown to html find a library or something
  47.             projectSectionId: listSectionMapper[card.idList], // get the sectionId from listSectionMapper
  48.             order: card.pos,
  49.             dueDate: card.due ? card.due : null, // format if necessary
  50.             // ... add columns if required
  51.         };
  52.         console.log(cardData);
  53.         // Create Card in Database Here
  54.     }
  55.     // Now map create labels and map to cards
  56.     let labels = data.labels;
  57.     // ....
  58.  
  59. }
  60.  
  61. importData();
  62.  
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement