From 0381ef3f95a6c73a435a7a13967a6418cd008e22 Mon Sep 17 00:00:00 2001 From: Gorbachev Egor <7gorbachevm@gmail.com> Date: Fri, 5 Jan 2024 18:43:05 +0700 Subject: [PATCH] f --- functions/db/deck/add-deck-to-mine-db.ts | 8 ++------ functions/get-shared-deck.ts | 5 +++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/functions/db/deck/add-deck-to-mine-db.ts b/functions/db/deck/add-deck-to-mine-db.ts index 951a6f5a..ec335789 100644 --- a/functions/db/deck/add-deck-to-mine-db.ts +++ b/functions/db/deck/add-deck-to-mine-db.ts @@ -1,6 +1,5 @@ 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, @@ -8,11 +7,8 @@ export const addDeckToMineDb = async ( ): Promise => { 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; }; diff --git a/functions/get-shared-deck.ts b/functions/get-shared-deck.ts index 4e9956ce..c3c21e0b 100644 --- a/functions/get-shared-deck.ts +++ b/functions/get-shared-deck.ts @@ -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; @@ -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, + }); } }