From f6f41270de1b5a2d3ff6aa4ca7d433915dd29bd9 Mon Sep 17 00:00:00 2001 From: Xavier Priour Date: Fri, 13 Nov 2015 15:52:14 +0100 Subject: Import members: working on card import --- models/import.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'models') diff --git a/models/import.js b/models/import.js index a6e9f3d5..ab23f0a9 100644 --- a/models/import.js +++ b/models/import.js @@ -4,7 +4,7 @@ const DateString = Match.Where(function (dateAsString) { }); class TrelloCreator { - constructor() { + constructor(data) { // The object creation dates, indexed by Trello id (so we only parse actions // once!) this.createdAt = { @@ -18,6 +18,8 @@ class TrelloCreator { this.lists = {}; // The comments, indexed by Trello card id (to map when importing cards) this.comments = {}; + // the members, indexed by Trello member id => Wekan user ID + this.members = data.membersMapping ? data.membersMapping : {}; } checkActions(trelloActions) { @@ -191,6 +193,19 @@ class TrelloCreator { return this.labels[trelloId]; }); } + // add members { + if(card.idMembers) { + const wekanMembers = []; + // we can't just map, as some members may not have been mapped + card.idMembers.forEach((id) => { + if(this.members[id]) { + wekanMembers.push(this.members[id]); + } + }); + if(wekanMembers.length>0) { + cardToCreate.members = wekanMembers; + } + } // insert card const cardId = Cards.direct.insert(cardToCreate); // log activity @@ -298,7 +313,7 @@ class TrelloCreator { Meteor.methods({ importTrelloBoard(trelloBoard, data) { - const trelloCreator = new TrelloCreator(); + const trelloCreator = new TrelloCreator(data); // 1. check all parameters are ok from a syntax point of view try { @@ -326,13 +341,14 @@ Meteor.methods({ }, importTrelloCard(trelloCard, data) { - const trelloCreator = new TrelloCreator(); + const trelloCreator = new TrelloCreator(data); // 1. check parameters are ok from a syntax point of view try { check(data, { listId: String, sortIndex: Number, + membersMapping: Match.Optional(Object), }); trelloCreator.checkCards([trelloCard]); trelloCreator.checkLabels(trelloCard.labels); -- cgit v1.2.3-1-g7c22