Implement DB interface for Piece CRUD

This commit is contained in:
2024-08-13 23:17:48 +02:00
parent 1bd323bdd6
commit ac091b1dc9
5 changed files with 171 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
import { Schema as S } from "@effect/schema";
import { SessionId } from "common";
import { Login, Logout, Me } from "common/api";
import { CreatePiece, GetPieces, UpdatePiece, DeletePiece, Login, Logout, Me } from "common/api";
import { AccessLog, SessionData } from "common/db";
import { DateTime, Duration, Either as E, Effect, Match, Option as O, pipe } from "effect";
import { constant } from "effect/Function";
@@ -111,7 +111,15 @@ export const app = pipe(
yield* db.createAccessLog(accessLog);
console.log(`${DateTime.toDateUtc(accessLog.timestamp).toISOString()} ${accessLog.requestId} ${accessLog.method} ${accessLog.pathname}?${new URLSearchParams(accessLog.query).toString()} ${accessLog.ip}`);
if (yield* match(Login)) {
if (yield* match(CreatePiece)) {
return new Response(null, { status: 501 });
} else if (yield* match(GetPieces)) {
return new Response(null, { status: 501 });
} else if (yield* match(UpdatePiece)) {
return new Response(null, { status: 501 });
} else if (yield* match(DeletePiece)) {
return new Response(null, { status: 501 });
} else if (yield* match(Login)) {
const body = yield* requestJson(Login.props.request.schema);