|  | 
|  | 1 | +/* eslint-disable */ | 
|  | 2 | +const _ = require('lodash') | 
|  | 3 | +const axios = require('axios'); | 
|  | 4 | +const Promise = require('bluebird'); | 
|  | 5 | + | 
|  | 6 | + | 
|  | 7 | +var url = 'https://api.topcoder-dev.com/v4/projects/metadata'; | 
|  | 8 | +var targetUrl = 'http://localhost:8001/v4/'; | 
|  | 9 | +var destUrl = targetUrl + 'projects/'; | 
|  | 10 | +var destTimelines = targetUrl; | 
|  | 11 | + | 
|  | 12 | +axios.get(url) | 
|  | 13 | +  .then(async function (response) { | 
|  | 14 | +    let data = response.data; | 
|  | 15 | + | 
|  | 16 | +    var headers = { | 
|  | 17 | +      'Content-Type': 'application/json', | 
|  | 18 | +      'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIiwiYWRtaW5pc3RyYXRvciJdLCJpc3MiOiJodHRwczovL2FwaS50b3Bjb2Rlci1kZXYuY29tIiwiaGFuZGxlIjoidGVzdDEiLCJleHAiOjI1NjMwNzY2ODksInVzZXJJZCI6IjQwMDUxMzMzIiwiaWF0IjoxNDYzMDc2MDg5LCJlbWFpbCI6InRlc3RAdG9wY29kZXIuY29tIiwianRpIjoiYjMzYjc3Y2QtYjUyZS00MGZlLTgzN2UtYmViOGUwYWU2YTRhIn0.wKWUe0-SaiFVN-VR_-GwgFlvWaDkSbc8H55ktb9LAVw'  | 
|  | 19 | +    } | 
|  | 20 | + | 
|  | 21 | + | 
|  | 22 | +    let promises = _(data.result.content.projectTypes).map(pt=>{ | 
|  | 23 | +      return axios.post(destUrl+'metadata/projectTypes',{param:pt}, {headers:headers}) | 
|  | 24 | +    }); | 
|  | 25 | +    try{ | 
|  | 26 | +      await Promise.all(promises); | 
|  | 27 | +    }catch(ex){ | 
|  | 28 | +      //ignore the error | 
|  | 29 | +    } | 
|  | 30 | + | 
|  | 31 | +    promises = _(data.result.content.projectTemplates).map(pt=>{ | 
|  | 32 | +      return axios.post(destUrl+'metadata/projectTemplates',{param:pt}, {headers:headers}) | 
|  | 33 | +    }); | 
|  | 34 | +    try{ | 
|  | 35 | +      await Promise.all(promises); | 
|  | 36 | +    }catch(ex){ | 
|  | 37 | +      //ignore the error | 
|  | 38 | +    } | 
|  | 39 | + | 
|  | 40 | +    promises = _(data.result.content.productCategories).map(pt=>{ | 
|  | 41 | +      return axios.post(destUrl+'metadata/productCategories',{param:pt}, {headers:headers}) | 
|  | 42 | +    }); | 
|  | 43 | +    try{ | 
|  | 44 | +      await Promise.all(promises); | 
|  | 45 | +    }catch(ex){ | 
|  | 46 | +      //ignore the error | 
|  | 47 | +    } | 
|  | 48 | + | 
|  | 49 | +    promises = _(data.result.content.productTemplates).map(pt=>{ | 
|  | 50 | +      return axios.post(destUrl+'metadata/productTemplates',{param:pt}, {headers:headers}) | 
|  | 51 | +    }); | 
|  | 52 | +    try{ | 
|  | 53 | +      await Promise.all(promises); | 
|  | 54 | +    }catch(ex){ | 
|  | 55 | +      //ignore the error | 
|  | 56 | +    } | 
|  | 57 | + | 
|  | 58 | +    await Promise.each(data.result.content.milestoneTemplates,pt=>{ | 
|  | 59 | +      return new Promise((resolve,reject)=>{ | 
|  | 60 | +        axios.post(destTimelines+'timelines/metadata/milestoneTemplates',{param:pt}, {headers:headers}) | 
|  | 61 | +        .then(r=>resolve()) | 
|  | 62 | +        .catch(e=>resolve()); //ignore the error | 
|  | 63 | +      }) | 
|  | 64 | +    }); | 
|  | 65 | +     | 
|  | 66 | + | 
|  | 67 | + | 
|  | 68 | +    // handle success | 
|  | 69 | +    console.log('Done'); | 
|  | 70 | +  }).catch(err=>{ | 
|  | 71 | +    console.log(err); | 
|  | 72 | +  }); | 
0 commit comments