diff --git a/lib/trello-csv.js b/lib/trello-csv.js index b753011..a8b782c 100644 --- a/lib/trello-csv.js +++ b/lib/trello-csv.js @@ -20,6 +20,33 @@ class TrelloCSV { this.LISTS_URL = `https://trello.com/1/boards/$$BOARD_ID$$/lists?fields=name,url&key=${config.KEY}&token=${config.TOKEN}` this.CARDS_URL = `https://trello.com/1/lists/$$LIST_ID$$/cards?key=${config.KEY}&token=${config.TOKEN}&fields=name,labels,idMembers,desc,shortUrl` this.ACTIONS_URL = `https://trello.com/1/cards/$$CARD_ID$$/actions?key=${config.KEY}&token=${config.TOKEN}&filter=all` + this.clearRawData() + } + + getRawData() { + return { + _boards: this._boards, + _members: this._members, + _lists: this._lists, + _cards: this._cards, + _actions: this._actions, + } + } + + setRawData(datas) { + this._boards = datas._boards + this._members = datas._members + this._lists = datas._lists + this._cards = datas._cards + this._actions = datas._actions + } + + clearRawData() { + this._boards = null + this._members = {} + this._lists = {} + this._cards = {} + this._actions = {} } async _getDataFromTrello(url) { @@ -28,31 +55,46 @@ class TrelloCSV { } async loadBoards() { - return this._getDataFromTrello(this.BOARDS_URL) + if (!this._boards) { + this._boards = await this._getDataFromTrello(this.BOARDS_URL) + } + return this._boards } async loadMember(memberId) { - return this._getDataFromTrello( - this.MEMBERS_URL.replace('$$MEMBER_ID$$', memberId) - ) + if (!this._members[memberId]) { + this._members[memberId] = await this._getDataFromTrello( + this.MEMBERS_URL.replace('$$MEMBER_ID$$', memberId) + ) + } + return this._members[memberId] } async loadLists(boardId) { - return this._getDataFromTrello( - this.LISTS_URL.replace('$$BOARD_ID$$', boardId) - ) + if (!this._lists[boardId]) { + this._lists[boardId] = await this._getDataFromTrello( + this.LISTS_URL.replace('$$BOARD_ID$$', boardId) + ) + } + return this._lists[boardId] } async loadCards(listId) { - return this._getDataFromTrello( - this.CARDS_URL.replace('$$LIST_ID$$', listId) - ) + if (!this._cards[listId]) { + this._cards[listId] = await this._getDataFromTrello( + this.CARDS_URL.replace('$$LIST_ID$$', listId) + ) + } + return this._cards[listId] } async loadActions(cardId) { - return this._getDataFromTrello( - this.ACTIONS_URL.replace('$$CARD_ID$$', cardId) - ) + if (!this._actions[cardId]) { + this._actions[cardId] = await this._getDataFromTrello( + this.ACTIONS_URL.replace('$$CARD_ID$$', cardId) + ) + } + return this._actions[cardId] } async parseBoard(board) { diff --git a/package.json b/package.json index f333982..c96d20d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "trello-csv", - "version": "1.1.0", + "version": "1.2.3", "description": "", "main": "index.js", "scripts": {