Skip to content

Commit

Permalink
feature #11: Depopulate Cards
Browse files Browse the repository at this point in the history
  • Loading branch information
Boosmith committed Sep 1, 2019
1 parent ce2e6c1 commit 149da85
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/api/cardApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ import { handleResponse, handleError } from "./apiUtils";
import { bearerHeaders } from "../tools/auth";
const baseUrl = process.env.REACT_APP_API_URL + "/api/cards/";

export function depopulateCard(card) {
card.owner = card.owner._id;
let members = [];
card.members.forEach(member => {
members.push(member._id);
});
card.members = members;
return card;
}

export function getCards() {
return fetch(baseUrl, bearerHeaders())
.then(handleResponse)
Expand All @@ -18,7 +28,7 @@ export function saveCard(Card) {
return fetch(baseUrl + (Card._id || ""), {
method: Card._id ? "PUT" : "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify(Card)
body: JSON.stringify(depopulateCard(Card))
})
.then(handleResponse)
.catch(handleError);
Expand Down
40 changes: 40 additions & 0 deletions src/api/cardApi.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { depopulateCard } from "./cardApi";

it("should clean up referenced members", function() {
const card = {
_id: "5d6aa2c0b3c3b66d9e80ceb6",
number: "#8",
title: "hold how",
description:
"Id fugiat et aliqua nisi. Ea laborum dolor exercitation sit. Veniam ea dolore ad est ad anim excepteur. Eiusmod magna aliquip duis. Anim deserunt dolor eu velit eiusmod aliquip eu consectetur Lorem.",
status: "",
board: "",
comments: "",
activity: "",
attachments: "",
owner: {
_id: "5d42e5d5e1e3d731df26010a",
firstName: "Andrew",
lastName: "Smith"
},
members: [
{
_id: "5d42104a7979bd071c129606",
firstName: "Dale",
lastName: "Fitzgerald"
},
{
_id: "5d42104a7979bd071c129609",
firstName: "Adeline",
lastName: "Fitzgerald"
}
],
createdDate: "2019-08-31T16:39:28.780Z",
modifiedDate: "2019-08-31T16:39:28.780Z"
};

expect(depopulateCard(card).members).toEqual([
"5d42104a7979bd071c129606",
"5d42104a7979bd071c129609"
]);
});

0 comments on commit 149da85

Please sign in to comment.