-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Allow to remove deck
- Loading branch information
Showing
23 changed files
with
345 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { EnvType } from "../../env/env-schema.ts"; | ||
import { getDatabase } from "../get-database.ts"; | ||
import { DatabaseException } from "../database-exception.ts"; | ||
|
||
export const removeDeckFromMineDb = async ( | ||
env: EnvType, | ||
body: { user_id: number; deck_id: number }, | ||
): Promise<null> => { | ||
const db = getDatabase(env); | ||
|
||
const { error } = await db.from("user_deck").delete().match(body); | ||
|
||
if (error) { | ||
throw new DatabaseException(error); | ||
} | ||
|
||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { handleError } from "./lib/handle-error/handle-error.ts"; | ||
import { getUser } from "./services/get-user.ts"; | ||
import { createAuthFailedResponse } from "./lib/json-response/create-auth-failed-response.ts"; | ||
import { z } from "zod"; | ||
import { envSchema } from "./env/env-schema.ts"; | ||
import { createBadRequestResponse } from "./lib/json-response/create-bad-request-response.ts"; | ||
import { createJsonResponse } from "./lib/json-response/create-json-response.ts"; | ||
import { removeDeckFromMineDb } from "./db/deck/remove-deck-from-mine-db.ts"; | ||
import { getDeckByIdAndAuthorId } from "./db/deck/get-deck-by-id-and-author-id.ts"; | ||
import { createForbiddenRequestResponse } from "./lib/json-response/create-forbidden-request-response.ts"; | ||
|
||
const requestSchema = z.object({ | ||
deckId: z.number(), | ||
}); | ||
|
||
export type RemoveDeckFromMineRequest = z.infer<typeof requestSchema>; | ||
export type RemoveDeckFromMineResponse = null; | ||
|
||
export const onRequestPost = handleError(async ({ env, request }) => { | ||
const user = await getUser(request, env); | ||
if (!user) return createAuthFailedResponse(); | ||
const input = requestSchema.safeParse(await request.json()); | ||
if (!input.success) { | ||
return createBadRequestResponse(); | ||
} | ||
|
||
const envSafe = envSchema.parse(env); | ||
|
||
const canEdit = await getDeckByIdAndAuthorId( | ||
envSafe, | ||
input.data.deckId, | ||
user.id, | ||
); | ||
if (!canEdit) { | ||
return createForbiddenRequestResponse(); | ||
} | ||
|
||
await removeDeckFromMineDb(envSafe, { | ||
user_id: user.id, | ||
deck_id: input.data.deckId, | ||
}); | ||
|
||
return createJsonResponse<RemoveDeckFromMineResponse>(null); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { css } from "@emotion/css"; | ||
import React from "react"; | ||
import { observer } from "mobx-react-lite"; | ||
|
||
type Props = { | ||
items: Array<unknown>; | ||
color: string; | ||
}; | ||
|
||
export const CardsToReviewCount = observer((props: Props) => { | ||
const { items, color } = props; | ||
|
||
return items.length > 0 ? ( | ||
<div | ||
className={css({ | ||
color: color, | ||
fontWeight: 600, | ||
})} | ||
> | ||
{items.length} | ||
</div> | ||
) : null; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { css } from "@emotion/css"; | ||
import { theme } from "../../ui/theme.tsx"; | ||
import React from "react"; | ||
|
||
export const FullScreenLoader = () => { | ||
return ( | ||
<div | ||
className={css({ | ||
display: "flex", | ||
height: "100vh", | ||
backgroundColor: theme.bgColor, | ||
alignItems: "center", | ||
justifyContent: "center", | ||
})} | ||
> | ||
<i className={"mdi mdi-loading mdi-spin mdi-48px"} /> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.