From 2bdc500336bde0b32701349e7e6bee84061358e7 Mon Sep 17 00:00:00 2001 From: Shotaro Nakamura <79000684+nakasyou@users.noreply.github.com> Date: Sun, 1 Oct 2023 13:52:59 +0900 Subject: [PATCH] Update index.ts --- routes/admin/api/index.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/routes/admin/api/index.ts b/routes/admin/api/index.ts index ebb4ada..6f28bf2 100644 --- a/routes/admin/api/index.ts +++ b/routes/admin/api/index.ts @@ -1,5 +1,5 @@ import { toHashString } from '$std/crypto/to_hash_string.ts' -import type { Schools } from '~/types/schools.ts' +import type { School } from '~/types/schools.ts' const kv = await Deno.openKv() @@ -29,17 +29,23 @@ export const handler: Handlers = { switch (data.type) { case 'create_school': { const schoolId = crypto.randomUUID() + await kv.atomic() + .set(['schools', schoolId], { + schoolName: data.schoolName, + schoolId, + }) + .commit() return jsonResp({ schoolId: schoolId, }) break } case 'get_schools_data': { - const result: Schools[] = [] + const result: School[] = [] const entries = kv.list({ prefix: ["schools"] }) // schools一覧をDBから取得 for await (const entry of entries) { - const data = entry.value as Schools + const data = entry.value as School result.push(data) } return jsonResp({