-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
894 additions
and
243 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 was deleted.
Oops, something went wrong.
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 { EnvSafe } from "../../env/env-schema.ts"; | ||
import { getDatabase } from "../get-database.ts"; | ||
import { DatabaseException } from "../database-exception.ts"; | ||
|
||
export const getFolderByIdAndAuthorId = async ( | ||
envSafe: EnvSafe, | ||
folderId: number, | ||
user: { id: number; is_admin: boolean }, | ||
) => { | ||
const db = getDatabase(envSafe); | ||
|
||
let query = db.from("folder").select().eq("id", folderId); | ||
if (!user.is_admin) { | ||
query = query.eq("author_id", user.id); | ||
} | ||
|
||
const canEditResult = await query.single(); | ||
if (canEditResult.error) { | ||
throw new DatabaseException(canEditResult.error); | ||
} | ||
|
||
return canEditResult.data ?? 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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 { envSchema } from "./env/env-schema.ts"; | ||
import { getDecksCreatedByMe } from "./db/deck/get-decks-created-by-me.ts"; | ||
import { DeckWithoutCardsDbType } from "./db/deck/decks-with-cards-schema.ts"; | ||
import { createJsonResponse } from "./lib/json-response/create-json-response.ts"; | ||
|
||
export type DecksMineResponse = { | ||
decks: DeckWithoutCardsDbType[]; | ||
}; | ||
|
||
export const onRequest = handleError(async ({ request, env }) => { | ||
const user = await getUser(request, env); | ||
if (!user) return createAuthFailedResponse(); | ||
const envSafe = envSchema.parse(env); | ||
|
||
const decks = await getDecksCreatedByMe(envSafe, user.id); | ||
|
||
return createJsonResponse<DecksMineResponse>({ decks: decks }); | ||
}); |
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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
export type FieldWithValue<T> = { | ||
value: T; | ||
}; | ||
|
||
export const isFieldWithValue = ( | ||
object: unknown, | ||
): object is FieldWithValue<unknown> => { | ||
return typeof object === "object" && object !== null && "value" in object; | ||
}; |
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.