Skip to content

Commit

Permalink
Update index.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
nakasyou authored Oct 1, 2023
1 parent 498e2ad commit 2bdc500
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions routes/admin/api/index.ts
Original file line number Diff line number Diff line change
@@ -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()

Expand Down Expand Up @@ -29,17 +29,23 @@ export const handler: Handlers<User | null> = {
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({
Expand Down

0 comments on commit 2bdc500

Please sign in to comment.