File tree Expand file tree Collapse file tree 2 files changed +2
-46
lines changed
Expand file tree Collapse file tree 2 files changed +2
-46
lines changed Original file line number Diff line number Diff line change @@ -40,45 +40,6 @@ export async function getWorkbookWithAuthor(
4040 return { workBook : workBook , isExistingAuthor : isExistingAuthor } ;
4141}
4242
43- /**
44- * Finds a workbook ID from a given slug string.
45- *
46- * This function first attempts to parse the slug as a direct workbook ID.
47- * If that fails, it tries to parse it as a workbook URL slug and looks up
48- * the corresponding workbook in the database.
49- *
50- * @param slug - The slug string to search for, can be either a numeric ID or URL slug
51- * @returns A Promise that resolves to the workbook ID if found, or null if not found
52- *
53- * @example
54- * ```typescript
55- * // Using numeric ID
56- * const id1 = await findWorkBookIdFrom("123");
57- *
58- * // Using URL slug
59- * const id2 = await findWorkBookIdFrom("union-find");
60- * ```
61- */
62- export async function findWorkBookIdFrom ( slug : string ) : Promise < number | null > {
63- const workBookId = parseWorkBookId ( slug ) ;
64-
65- if ( workBookId !== null ) {
66- return workBookId ;
67- }
68-
69- const workBookUrlSlug = parseWorkBookUrlSlug ( slug ) ;
70-
71- if ( workBookUrlSlug !== null ) {
72- const workBook = await workBookCrud . getWorkBookByUrlSlug ( slug ) ;
73-
74- if ( workBook !== null && workBook . id !== null ) {
75- return workBook . id ;
76- }
77- }
78-
79- return null ;
80- }
81-
8243export function parseWorkBookId ( slug : string ) : number | null {
8344 const isOnlyDigits = ( id : string ) => / ^ \d + $ / . test ( id ) ;
8445 const id = Number ( slug ) ;
Original file line number Diff line number Diff line change @@ -7,18 +7,13 @@ import * as taskResultsCrud from '$lib/services/task_results';
77import * as action from '$lib/actions/update_task_result' ;
88
99import { getLoggedInUser , isAdmin , canRead } from '$lib/utils/authorship' ;
10- import { getWorkbookWithAuthor , findWorkBookIdFrom } from '$lib/utils/workbook' ;
11- import { BAD_REQUEST , FORBIDDEN } from '$lib/constants/http-response-status-codes' ;
10+ import { getWorkbookWithAuthor } from '$lib/utils/workbook' ;
11+ import { FORBIDDEN } from '$lib/constants/http-response-status-codes' ;
1212
1313export async function load ( { locals, params } ) {
1414 const loggedInUser = await getLoggedInUser ( locals ) ;
1515 const loggedInAsAdmin = isAdmin ( loggedInUser ?. role as Roles ) ;
1616 const slug = params . slug . toLowerCase ( ) ;
17- const workBookId = await findWorkBookIdFrom ( slug ) ;
18-
19- if ( workBookId === null ) {
20- error ( BAD_REQUEST , '不正な問題集idです。' ) ;
21- }
2217
2318 const workbookWithAuthor = await getWorkbookWithAuthor ( slug ) ;
2419 const workBook = workbookWithAuthor . workBook ;
You can’t perform that action at this time.
0 commit comments