-
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
18 changed files
with
219 additions
and
110 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { EnvSafe } from "../../env/env-schema.ts"; | ||
import { getDatabase } from "../get-database.ts"; | ||
import { DatabaseException } from "../database-exception.ts"; | ||
|
||
export const deleteFolderById = async ( | ||
env: EnvSafe, | ||
folderId: number, | ||
): Promise<void> => { | ||
const db = getDatabase(env); | ||
const deleteFolderResult = await db | ||
.from("folder") | ||
.delete() | ||
.eq("id", folderId) | ||
.single(); | ||
|
||
if (deleteFolderResult.error) { | ||
throw new DatabaseException(deleteFolderResult.error); | ||
} | ||
}; |
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,35 @@ | ||
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 { createBadRequestResponse } from "./lib/json-response/create-bad-request-response.ts"; | ||
import { getFolderByIdAndAuthorId } from "./db/folder/get-folder-by-id-and-author-id.ts"; | ||
import { createJsonResponse } from "./lib/json-response/create-json-response.ts"; | ||
import { deleteFolderById } from "./db/folder/delete-folder-by-id.ts"; | ||
|
||
export const onRequestPost = handleError(async ({ request, env }) => { | ||
const user = await getUser(request, env); | ||
if (!user) { | ||
return createAuthFailedResponse(); | ||
} | ||
const envSafe = envSchema.parse(env); | ||
|
||
const url = new URL(request.url); | ||
const folderId = url.searchParams.get("folder_id"); | ||
if (!folderId) { | ||
return createBadRequestResponse(); | ||
} | ||
|
||
const canEdit = await getFolderByIdAndAuthorId( | ||
envSafe, | ||
parseInt(folderId), | ||
user, | ||
); | ||
if (!canEdit) { | ||
return createBadRequestResponse(); | ||
} | ||
|
||
await deleteFolderById(envSafe, parseInt(folderId)); | ||
|
||
return createJsonResponse(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
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.