Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeepMemo #444

Merged
merged 14 commits into from
Dec 2, 2024
16 changes: 16 additions & 0 deletions server/src/database/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,19 @@ export async function getMatchedUser(userId: UserID): Promise<Result<User[]>> {
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);
}
}
15 changes: 13 additions & 2 deletions server/src/router/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import express, { type Request, type Response } from "express";
import {
getPendingRequestsFromUser,
getPendingRequestsToUser,
matchWithMemo,
} from "../database/requests";
import {
createUser,
Expand Down Expand Up @@ -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);
});

Expand Down
29 changes: 18 additions & 11 deletions web/components/match/matching.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,24 @@ export default function Matchings() {
<p className="text-red-500">Error: {error.message}</p>
) : (
<ul className="mt-4 space-y-4">
{data?.map((matchedUser) => (
<HumanListItem
key={matchedUser.id}
id={matchedUser.id}
name={matchedUser.name}
pictureUrl={matchedUser.pictureUrl}
onOpen={() => openModal(matchedUser)}
onDelete={() => deleteMatch(matchedUser.id).then(() => reload())}
hasDots
/>
))}
{data?.map((matchedUser) =>
matchedUser.id === 0 ? (
//メモ帳
<div key={0} />
) : (
<HumanListItem
key={matchedUser.id}
id={matchedUser.id}
name={matchedUser.name}
pictureUrl={matchedUser.pictureUrl}
onOpen={() => openModal(matchedUser)}
onDelete={() =>
deleteMatch(matchedUser.id).then(() => reload())
}
hasDots
/>
),
)}
</ul>
)}
</div>
Expand Down