Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
kubk committed Jan 5, 2024
1 parent a7bf2cb commit 0381ef3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 2 additions & 6 deletions functions/db/deck/add-deck-to-mine-db.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { EnvSafe } from "../../env/env-schema.ts";
import { getDatabase } from "../get-database.ts";
import { DatabaseException } from "../database-exception.ts";

export const addDeckToMineDb = async (
env: EnvSafe,
body: { user_id: number; deck_id: number },
): Promise<null> => {
const db = getDatabase(env);

const { error } = await db.from("user_deck").insert([body]).single();

if (error) {
throw new DatabaseException(error);
}
// Ignore constraint violation
await db.from("user_deck").insert([body]).single();

return null;
};
5 changes: 5 additions & 0 deletions functions/get-shared-deck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { getDeckAccessByShareIdDb } from "./db/deck-access/get-deck-access-by-sh
import { startUsingDeckAccessDb } from "./db/deck-access/start-using-deck-access-db.ts";
import { getDeckWithCardsById } from "./db/deck/get-deck-with-cards-by-id-db.ts";
import { getDeckWithCardsByShareIdDb } from "./db/deck/get-deck-with-cards-by-share-id-db.ts";
import { addDeckToMineDb } from "./db/deck/add-deck-to-mine-db.ts";

export type GetSharedDeckResponse = {
deck: DeckWithCardsDbType;
Expand Down Expand Up @@ -43,6 +44,10 @@ export const onRequest = handleError(async ({ env, request }) => {
}
} else {
await startUsingDeckAccessDb(envSafe, user.id, shareId);
await addDeckToMineDb(envSafe, {
user_id: user.id,
deck_id: oneTimeShareLinkResultData.deck_id,
});
}
}

Expand Down

0 comments on commit 0381ef3

Please sign in to comment.