diff --git a/server/src/database/requests.ts b/server/src/database/requests.ts index 0642a3b1..e1e2efaa 100644 --- a/server/src/database/requests.ts +++ b/server/src/database/requests.ts @@ -183,3 +183,19 @@ export async function getMatchedUser(userId: UserID): Promise> { return Err(e); } } + +export async function matchWithMemo(userId: UserID) { + try { + const result = await prisma.relationship.create({ + data: { + status: "MATCHED", + sendingUserId: userId, + receivingUserId: 0, //KeepメモのUserId + }, + }); + + return result; + } catch (error) { + return Err(error); + } +} diff --git a/server/src/router/users.ts b/server/src/router/users.ts index ae0dd6b3..5be8fcf8 100644 --- a/server/src/router/users.ts +++ b/server/src/router/users.ts @@ -9,6 +9,7 @@ import express, { type Request, type Response } from "express"; import { getPendingRequestsFromUser, getPendingRequestsToUser, + matchWithMemo, } from "../database/requests"; import { createUser, @@ -124,10 +125,20 @@ router.get("/id/:id", async (req: Request, res: Response) => { // INSERT INTO "User" VALUES (body...) router.post("/", async (req: Request, res: Response) => { const partialUser = InitUserSchema.safeParse(req.body); - if (!partialUser.success) return res.status(400).send("invalid format"); + if (!partialUser.success) + return res.status(400).send({ + error: "Invalid input format", + details: partialUser.error.errors, + }); const user = await createUser(partialUser.data); - if (!user.ok) return res.status(500).send(); + if (!user.ok) return res.status(500).send({ error: "Failed to create user" }); + + //ユーザー作成と同時にメモとマッチング + const result = await matchWithMemo(user.value.id); + if ("ok" in result && !result.ok) { + return res.status(500).send({ error: "Failed to match user with memo" }); + } res.status(201).json(user.value); }); diff --git a/web/components/match/matching.tsx b/web/components/match/matching.tsx index c38d7c39..c15962f3 100644 --- a/web/components/match/matching.tsx +++ b/web/components/match/matching.tsx @@ -25,17 +25,24 @@ export default function Matchings() {

Error: {error.message}

) : ( )}