Refactor imported -> linked in models

This commit is contained in:
Andrés Manelli 2018-05-02 14:20:55 -03:00
parent bce2242528
commit 6adfcb3513
3 changed files with 102 additions and 102 deletions

View file

@ -320,12 +320,12 @@ Boards.helpers({
return _id; return _id;
}, },
searchCards(term, excludeImported) { searchCards(term, excludeLinked) {
check(term, Match.OneOf(String, null, undefined)); check(term, Match.OneOf(String, null, undefined));
const query = { boardId: this._id }; const query = { boardId: this._id };
if (excludeImported) { if (excludeLinked) {
query.importedId = null; query.linkedId = null;
} }
const projection = { limit: 10, sort: { createdAt: -1 } }; const projection = { limit: 10, sort: { createdAt: -1 } };

View file

@ -136,7 +136,7 @@ Cards.attachSchema(new SimpleSchema({
type: { type: {
type: String, type: String,
}, },
importedId: { linkedId: {
type: String, type: String,
optional: true, optional: true,
}, },
@ -185,26 +185,26 @@ Cards.helpers({
}, },
activities() { activities() {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
return Activities.find({cardId: this.importedId}, {sort: {createdAt: -1}}); return Activities.find({cardId: this.linkedId}, {sort: {createdAt: -1}});
} else if (this.isImportedBoard()) { } else if (this.isLinkedBoard()) {
return Activities.find({boardId: this.importedId}, {sort: {createdAt: -1}}); return Activities.find({boardId: this.linkedId}, {sort: {createdAt: -1}});
} else { } else {
return Activities.find({cardId: this._id}, {sort: {createdAt: -1}}); return Activities.find({cardId: this._id}, {sort: {createdAt: -1}});
} }
}, },
comments() { comments() {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
return CardComments.find({cardId: this.importedId}, {sort: {createdAt: -1}}); return CardComments.find({cardId: this.linkedId}, {sort: {createdAt: -1}});
} else { } else {
return CardComments.find({cardId: this._id}, {sort: {createdAt: -1}}); return CardComments.find({cardId: this._id}, {sort: {createdAt: -1}});
} }
}, },
attachments() { attachments() {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
return Attachments.find({cardId: this.importedId}, {sort: {uploadedAt: -1}}); return Attachments.find({cardId: this.linkedId}, {sort: {uploadedAt: -1}});
} else { } else {
return Attachments.find({cardId: this._id}, {sort: {uploadedAt: -1}}); return Attachments.find({cardId: this._id}, {sort: {uploadedAt: -1}});
} }
@ -218,8 +218,8 @@ Cards.helpers({
}, },
checklists() { checklists() {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
return Checklists.find({cardId: this.importedId}, {sort: { sort: 1 } }); return Checklists.find({cardId: this.linkedId}, {sort: { sort: 1 } });
} else { } else {
return Checklists.find({cardId: this._id}, {sort: { sort: 1 } }); return Checklists.find({cardId: this._id}, {sort: { sort: 1 } });
} }
@ -412,23 +412,23 @@ Cards.helpers({
return this.parentId === ''; return this.parentId === '';
}, },
isImportedCard() { isLinkedCard() {
return this.type === 'cardType-importedCard'; return this.type === 'cardType-linkedCard';
}, },
isImportedBoard() { isLinkedBoard() {
return this.type === 'cardType-importedBoard'; return this.type === 'cardType-linkedBoard';
}, },
isImported() { isLinked() {
return this.isImportedCard() || this.isImportedBoard(); return this.isLinkedCard() || this.isLinkedBoard();
}, },
setDescription(description) { setDescription(description) {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
return Cards.update({_id: this.importedId}, {$set: {description}}); return Cards.update({_id: this.linkedId}, {$set: {description}});
} else if (this.isImportedBoard()) { } else if (this.isLinkedBoard()) {
return Boards.update({_id: this.importedId}, {$set: {description}}); return Boards.update({_id: this.linkedId}, {$set: {description}});
} else { } else {
return Cards.update( return Cards.update(
{_id: this._id}, {_id: this._id},
@ -438,14 +438,14 @@ Cards.helpers({
}, },
getDescription() { getDescription() {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
const card = Cards.findOne({_id: this.importedId}); const card = Cards.findOne({_id: this.linkedId});
if (card && card.description) if (card && card.description)
return card.description; return card.description;
else else
return null; return null;
} else if (this.isImportedBoard()) { } else if (this.isLinkedBoard()) {
const board = Boards.findOne({_id: this.importedId}); const board = Boards.findOne({_id: this.linkedId});
if (board && board.description) if (board && board.description)
return board.description; return board.description;
else else
@ -458,11 +458,11 @@ Cards.helpers({
}, },
getMembers() { getMembers() {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
const card = Cards.findOne({_id: this.importedId}); const card = Cards.findOne({_id: this.linkedId});
return card.members; return card.members;
} else if (this.isImportedBoard()) { } else if (this.isLinkedBoard()) {
const board = Boards.findOne({_id: this.importedId}); const board = Boards.findOne({_id: this.linkedId});
return board.activeMembers().map((member) => { return board.activeMembers().map((member) => {
return member.userId; return member.userId;
}); });
@ -472,13 +472,13 @@ Cards.helpers({
}, },
assignMember(memberId) { assignMember(memberId) {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
return Cards.update( return Cards.update(
{ _id: this.importedId }, { _id: this.linkedId },
{ $addToSet: { members: memberId }} { $addToSet: { members: memberId }}
); );
} else if (this.isImportedBoard()) { } else if (this.isLinkedBoard()) {
const board = Boards.findOne({_id: this.importedId}); const board = Boards.findOne({_id: this.linkedId});
return board.addMember(memberId); return board.addMember(memberId);
} else { } else {
return Cards.update( return Cards.update(
@ -489,13 +489,13 @@ Cards.helpers({
}, },
unassignMember(memberId) { unassignMember(memberId) {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
return Cards.update( return Cards.update(
{ _id: this.importedId }, { _id: this.linkedId },
{ $pull: { members: memberId }} { $pull: { members: memberId }}
); );
} else if (this.isImportedBoard()) { } else if (this.isLinkedBoard()) {
const board = Boards.findOne({_id: this.importedId}); const board = Boards.findOne({_id: this.linkedId});
return board.removeMember(memberId); return board.removeMember(memberId);
} else { } else {
return Cards.update( return Cards.update(
@ -514,8 +514,8 @@ Cards.helpers({
}, },
getReceived() { getReceived() {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
const card = Cards.findOne({_id: this.importedId}); const card = Cards.findOne({_id: this.linkedId});
return card.receivedAt; return card.receivedAt;
} else { } else {
return this.receivedAt; return this.receivedAt;
@ -523,9 +523,9 @@ Cards.helpers({
}, },
setReceived(receivedAt) { setReceived(receivedAt) {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
return Cards.update( return Cards.update(
{_id: this.importedId}, {_id: this.linkedId},
{$set: {receivedAt}} {$set: {receivedAt}}
); );
} else { } else {
@ -537,11 +537,11 @@ Cards.helpers({
}, },
getStart() { getStart() {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
const card = Cards.findOne({_id: this.importedId}); const card = Cards.findOne({_id: this.linkedId});
return card.startAt; return card.startAt;
} else if (this.isImportedBoard()) { } else if (this.isLinkedBoard()) {
const board = Boards.findOne({_id: this.importedId}); const board = Boards.findOne({_id: this.linkedId});
return board.startAt; return board.startAt;
} else { } else {
return this.startAt; return this.startAt;
@ -549,14 +549,14 @@ Cards.helpers({
}, },
setStart(startAt) { setStart(startAt) {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
return Cards.update( return Cards.update(
{ _id: this.importedId }, { _id: this.linkedId },
{$set: {startAt}} {$set: {startAt}}
); );
} else if (this.isImportedBoard()) { } else if (this.isLinkedBoard()) {
return Boards.update( return Boards.update(
{_id: this.importedId}, {_id: this.linkedId},
{$set: {startAt}} {$set: {startAt}}
); );
} else { } else {
@ -568,11 +568,11 @@ Cards.helpers({
}, },
getDue() { getDue() {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
const card = Cards.findOne({_id: this.importedId}); const card = Cards.findOne({_id: this.linkedId});
return card.dueAt; return card.dueAt;
} else if (this.isImportedBoard()) { } else if (this.isLinkedBoard()) {
const board = Boards.findOne({_id: this.importedId}); const board = Boards.findOne({_id: this.linkedId});
return board.dueAt; return board.dueAt;
} else { } else {
return this.dueAt; return this.dueAt;
@ -580,14 +580,14 @@ Cards.helpers({
}, },
setDue(dueAt) { setDue(dueAt) {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
return Cards.update( return Cards.update(
{ _id: this.importedId }, { _id: this.linkedId },
{$set: {dueAt}} {$set: {dueAt}}
); );
} else if (this.isImportedBoard()) { } else if (this.isLinkedBoard()) {
return Boards.update( return Boards.update(
{_id: this.importedId}, {_id: this.linkedId},
{$set: {dueAt}} {$set: {dueAt}}
); );
} else { } else {
@ -599,11 +599,11 @@ Cards.helpers({
}, },
getEnd() { getEnd() {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
const card = Cards.findOne({_id: this.importedId}); const card = Cards.findOne({_id: this.linkedId});
return card.endAt; return card.endAt;
} else if (this.isImportedBoard()) { } else if (this.isLinkedBoard()) {
const board = Boards.findOne({_id: this.importedId}); const board = Boards.findOne({_id: this.linkedId});
return board.endAt; return board.endAt;
} else { } else {
return this.endAt; return this.endAt;
@ -611,14 +611,14 @@ Cards.helpers({
}, },
setEnd(endAt) { setEnd(endAt) {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
return Cards.update( return Cards.update(
{ _id: this.importedId }, { _id: this.linkedId },
{$set: {endAt}} {$set: {endAt}}
); );
} else if (this.isImportedBoard()) { } else if (this.isLinkedBoard()) {
return Boards.update( return Boards.update(
{_id: this.importedId}, {_id: this.linkedId},
{$set: {endAt}} {$set: {endAt}}
); );
} else { } else {
@ -630,11 +630,11 @@ Cards.helpers({
}, },
getIsOvertime() { getIsOvertime() {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.importedId }); const card = Cards.findOne({ _id: this.linkedId });
return card.isOvertime; return card.isOvertime;
} else if (this.isImportedBoard()) { } else if (this.isLinkedBoard()) {
const board = Boards.findOne({ _id: this.importedId}); const board = Boards.findOne({ _id: this.linkedId});
return board.isOvertime; return board.isOvertime;
} else { } else {
return this.isOvertime; return this.isOvertime;
@ -642,14 +642,14 @@ Cards.helpers({
}, },
setIsOvertime(isOvertime) { setIsOvertime(isOvertime) {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
return Cards.update( return Cards.update(
{ _id: this.importedId }, { _id: this.linkedId },
{$set: {isOvertime}} {$set: {isOvertime}}
); );
} else if (this.isImportedBoard()) { } else if (this.isLinkedBoard()) {
return Boards.update( return Boards.update(
{_id: this.importedId}, {_id: this.linkedId},
{$set: {isOvertime}} {$set: {isOvertime}}
); );
} else { } else {
@ -661,11 +661,11 @@ Cards.helpers({
}, },
getSpentTime() { getSpentTime() {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.importedId }); const card = Cards.findOne({ _id: this.linkedId });
return card.spentTime; return card.spentTime;
} else if (this.isImportedBoard()) { } else if (this.isLinkedBoard()) {
const board = Boards.findOne({ _id: this.importedId}); const board = Boards.findOne({ _id: this.linkedId});
return board.spentTime; return board.spentTime;
} else { } else {
return this.spentTime; return this.spentTime;
@ -673,14 +673,14 @@ Cards.helpers({
}, },
setSpentTime(spentTime) { setSpentTime(spentTime) {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
return Cards.update( return Cards.update(
{ _id: this.importedId }, { _id: this.linkedId },
{$set: {spentTime}} {$set: {spentTime}}
); );
} else if (this.isImportedBoard()) { } else if (this.isLinkedBoard()) {
return Boards.update( return Boards.update(
{_id: this.importedId}, {_id: this.linkedId},
{$set: {spentTime}} {$set: {spentTime}}
); );
} else { } else {
@ -692,11 +692,11 @@ Cards.helpers({
}, },
getTitle() { getTitle() {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.importedId }); const card = Cards.findOne({ _id: this.linkedId });
return card.title; return card.title;
} else if (this.isImportedBoard()) { } else if (this.isLinkedBoard()) {
const board = Boards.findOne({ _id: this.importedId}); const board = Boards.findOne({ _id: this.linkedId});
return board.title; return board.title;
} else { } else {
return this.title; return this.title;
@ -704,12 +704,12 @@ Cards.helpers({
}, },
getBoardTitle() { getBoardTitle() {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.importedId }); const card = Cards.findOne({ _id: this.linkedId });
const board = Boards.findOne({ _id: card.boardId }); const board = Boards.findOne({ _id: card.boardId });
return board.title; return board.title;
} else if (this.isImportedBoard()) { } else if (this.isLinkedBoard()) {
const board = Boards.findOne({ _id: this.importedId}); const board = Boards.findOne({ _id: this.linkedId});
return board.title; return board.title;
} else { } else {
const board = Boards.findOne({ _id: this.boardId }); const board = Boards.findOne({ _id: this.boardId });
@ -718,14 +718,14 @@ Cards.helpers({
}, },
setTitle(title) { setTitle(title) {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
return Cards.update( return Cards.update(
{ _id: this.importedId }, { _id: this.linkedId },
{$set: {title}} {$set: {title}}
); );
} else if (this.isImportedBoard()) { } else if (this.isLinkedBoard()) {
return Boards.update( return Boards.update(
{_id: this.importedId}, {_id: this.linkedId},
{$set: {title}} {$set: {title}}
); );
} else { } else {
@ -737,11 +737,11 @@ Cards.helpers({
}, },
getArchived() { getArchived() {
if (this.isImportedCard()) { if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.importedId }); const card = Cards.findOne({ _id: this.linkedId });
return card.archived; return card.archived;
} else if (this.isImportedBoard()) { } else if (this.isLinkedBoard()) {
const board = Boards.findOne({ _id: this.importedId}); const board = Boards.findOne({ _id: this.linkedId});
return board.archived; return board.archived;
} else { } else {
return this.archived; return this.archived;

View file

@ -45,7 +45,7 @@ class Exporter {
build() { build() {
const byBoard = { boardId: this._boardId }; const byBoard = { boardId: this._boardId };
const byBoardNoImported = { boardId: this._boardId, importedId: null }; const byBoardNoLinked = { boardId: this._boardId, linkedId: null };
// we do not want to retrieve boardId in related elements // we do not want to retrieve boardId in related elements
const noBoardId = { fields: { boardId: 0 } }; const noBoardId = { fields: { boardId: 0 } };
const result = { const result = {
@ -53,7 +53,7 @@ class Exporter {
}; };
_.extend(result, Boards.findOne(this._boardId, { fields: { stars: 0 } })); _.extend(result, Boards.findOne(this._boardId, { fields: { stars: 0 } }));
result.lists = Lists.find(byBoard, noBoardId).fetch(); result.lists = Lists.find(byBoard, noBoardId).fetch();
result.cards = Cards.find(byBoardNoImported, noBoardId).fetch(); result.cards = Cards.find(byBoardNoLinked, noBoardId).fetch();
result.swimlanes = Swimlanes.find(byBoard, noBoardId).fetch(); result.swimlanes = Swimlanes.find(byBoard, noBoardId).fetch();
result.comments = CardComments.find(byBoard, noBoardId).fetch(); result.comments = CardComments.find(byBoard, noBoardId).fetch();
result.activities = Activities.find(byBoard, noBoardId).fetch(); result.activities = Activities.find(byBoard, noBoardId).fetch();