Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Make a file upload for user so that they can upload the json file. Then read the file
- const jsonfile = require('jsonfile');
- const jsonFilePath = './premium.json';
- async function importData() {
- let data;
- data = await jsonfile.readFile(jsonFilePath);
- // console.log(data);
- let ProjectName = data.name;
- console.log(ProjectName);
- const ProjectData = {
- name: ProjectName,
- description: data.desc, // need to strip tags if markdown to html find a library or something
- businessId: 1, // getCurrentBusinessId()
- leadId: 1, // getCurrentLeadId()
- status : 'active', // as per your need
- };
- console.log(ProjectData);
- // now section/stage/list creation
- let lists = data.lists;
- let listSectionMapper = {};
- // create a foreach loop for lists
- for (const list of lists) {
- const sectionData = {
- name: list.name,
- projectId: 1, // newly created project id
- order: list.pos,
- };
- console.log(sectionData);
- // Create Section in Database Here
- // let sectionId = 'Insert into ProjectSection in Database and get the sectionId here';
- listSectionMapper[list.id] = sectionId;
- }
- // now card/task creation
- let cards = data.cards;
- for (let card of cards) {
- const taskData = {
- title: card.name,
- description: card.desc, // need to strip tags if markdown to html find a library or something
- projectSectionId: listSectionMapper[card.idList], // get the sectionId from listSectionMapper
- order: card.pos,
- dueDate: card.due ? card.due : null, // format if necessary
- // ... add columns if required
- };
- console.log(cardData);
- // Create Card in Database Here
- }
- // Now map create labels and map to cards
- let labels = data.labels;
- // ....
- }
- importData();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement