Skip to content

Commit b1ba19e

Browse files
committed
🐛 Fix type errors (#2199)
1 parent ca857f4 commit b1ba19e

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/routes/workbooks/[slug]/+page.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@
7575
return getContestIdFrom(taskId) + '-' + taskId;
7676
};
7777
78-
// HACK:: `updatingModal` is updated, but is not declared with `$state(...)`. Changing its value will not correctly trigger updates.
79-
let updatingModal: UpdatingModal | null = null;
78+
let updatingModal: UpdatingModal | null = $state(null);
8079
8180
// HACK: clickを1回実行するとactionsが2回実行されてしまう。原因と修正方法が分かっていない。
8281
function handleClick(taskId: string) {

src/routes/workbooks/create/+page.server.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ import { error, fail, redirect } from '@sveltejs/kit';
22
import { superValidate } from 'sveltekit-superforms/server';
33
import { zod } from 'sveltekit-superforms/adapters';
44

5-
import { getLoggedInUser } from '$lib/utils/authorship';
65
import { workBookSchema } from '$lib/zod/schema';
6+
77
import * as workBooksCrud from '$lib/services/workbooks';
8+
import * as tasksCrud from '$lib/services/tasks';
9+
810
import { Roles } from '$lib/types/user';
9-
import type { WorkBook } from '$lib/types/workbook';
11+
12+
import { getLoggedInUser } from '$lib/utils/authorship';
1013
import {
1114
BAD_REQUEST,
1215
FORBIDDEN,
1316
TEMPORARY_REDIRECT,
1417
} from '$lib/constants/http-response-status-codes';
15-
import * as tasksCrud from '$lib/services/tasks';
1618

1719
export const load = async ({ locals }) => {
1820
// ログインしていない場合は、ログイン画面へ遷移させる
@@ -39,7 +41,12 @@ export const load = async ({ locals }) => {
3941
export const actions = {
4042
default: async ({ locals, request }) => {
4143
console.log('form -> actions -> create');
42-
await getLoggedInUser(locals);
44+
const author = await getLoggedInUser(locals);
45+
46+
if (!author) {
47+
return fail(FORBIDDEN, { message: 'ログインが必要です。' });
48+
}
49+
4350
const form = await superValidate(request, zod(workBookSchema));
4451

4552
if (!form.valid) {
@@ -52,7 +59,11 @@ export const actions = {
5259
});
5360
}
5461

55-
const workBook: WorkBook = form.data;
62+
// Note: form.data includes authorId
63+
const workBook = {
64+
...form.data,
65+
id: 0, // Dummy id (Prisma will auto-generate it)
66+
};
5667

5768
try {
5869
await workBooksCrud.createWorkBook(workBook);

src/routes/workbooks/edit/[slug]/+page.server.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ export async function load({ locals, params }) {
2121
const workBookWithAuthor = await getWorkbookWithAuthor(slug);
2222

2323
const form = await superValidate(null, zod(workBookSchema));
24-
form.data = { ...form.data, ...workBookWithAuthor.workBook };
24+
const workBook = {
25+
...workBookWithAuthor.workBook,
26+
urlSlug: workBookWithAuthor.workBook.urlSlug ?? undefined,
27+
};
28+
form.data = { ...form.data, ...workBook };
2529
const tasks = await tasksCrud.getTasks();
2630
const tasksMapByIds = await tasksCrud.getTasksByTaskId();
2731

0 commit comments

Comments
 (0)