Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): not returning entry list if there are entries deleted #225

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions apps/api/src/features/entry/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,26 @@ export const EntryRoutes = new Elysia().group("/entry", (app) =>
user.id,
);

const safeEntries = unsafeUserEntries.map((entry) => {
const notDeletedEntryList = unsafeUserEntries.filter((entry) => {
const { entry: notDeletedEntry } = EntryAdapter.toNotDeleted(entry);

if (!notDeletedEntry) {
throw new Error("entry is deleted");
return false;
}

const { safeEntry } = EntryAdapter.toSafeEntry(notDeletedEntry);
return true;
});

const safeEntries = notDeletedEntryList.map((entry) => {
const { safeEntry } = EntryAdapter.toSafeEntry(entry);

return safeEntry;
});

set.status = "OK";
return safeEntries;
} catch (e) {
console.log({ e });
return error("Internal Server Error", {});
}
},
Expand Down
56 changes: 28 additions & 28 deletions apps/api/tests/integration/entry/patch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,37 @@ import { createUser } from "@/tests/lib/user";
import { endpointPath } from ".";

describe("Test PATCH method on entries endpoints", () => {
describe("Succesfull request", async () => {
const { cookie } = await createUser({});
describe("Succesfull request", async () => {
const { cookie } = await createUser({});

const { EntryId } = await createNewEntry(
{ title: "untitled", content: EXAMPLE_DOCUMENT_CONTENT, word_count: 0 },
cookie,
);
const { EntryId } = await createNewEntry(
{ title: "untitled", content: EXAMPLE_DOCUMENT_CONTENT, word_count: 0 },
cookie,
);

const res = await app.handle(
new Request(`${endpointPath}/${EntryId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json; charset=utf-8",
cookie: cookie,
},
body: JSON.stringify({
title: "test",
content: EXAMPLE_DOCUMENT_CONTENT,
word_count: 291,
}),
}),
);
const res = await app.handle(
new Request(`${endpointPath}/${EntryId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json; charset=utf-8",
cookie: cookie,
},
body: JSON.stringify({
title: "test",
content: EXAMPLE_DOCUMENT_CONTENT,
word_count: 291,
}),
}),
);

it("Should return status code 204", () => {
expect(res.status).toBe(204);
});
it("Should return status code 204", () => {
expect(res.status).toBe(204);
});

it("Should return empty object on body", async () => {
const body = await res.json();
it("Should return empty object on body", async () => {
const body = await res.json();

expect(body).toBeEmptyObject();
});
});
expect(body).toBeEmptyObject();
});
});
});
2 changes: 1 addition & 1 deletion apps/api/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"dev": {
"dependsOn": ["setup"],
"cache": true,
"cache": false,
"inputs": ["./src/**", "!./tests/**"]
},
"setup": {
Expand Down