Skip to content

Commit 8f52a32

Browse files
committed
ユーザー作成時にメモとマッチするように
1 parent e91365f commit 8f52a32

File tree

7 files changed

+19
-62
lines changed

7 files changed

+19
-62
lines changed

server/src/database/requests.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,20 +184,18 @@ export async function getMatchedUser(userId: UserID): Promise<Result<User[]>> {
184184
}
185185
}
186186

187-
export async function autoMatch(userId: UserID) {
187+
export async function matchWithMemo(userId: UserID) {
188188
try {
189189
const result = await prisma.relationship.create({
190190
data: {
191191
status: "MATCHED",
192192
sendingUserId: userId,
193-
receivingUserId: 0, //Keepメモ
193+
receivingUserId: 0, //KeepメモのUserId
194194
},
195195
});
196196

197-
console.log("New relationship record created:", result);
198197
return result;
199198
} catch (error) {
200-
console.error("Error creating new relationship:", error);
201-
throw new Error("Failed to create a new match.");
199+
return Err(error);
202200
}
203201
}

server/src/router/requests.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import express, { type Request, type Response } from "express";
44
import { safeParseInt } from "common/lib/result/safeParseInt";
55
import {
66
approveRequest,
7-
autoMatch,
87
cancelRequest,
98
rejectRequest,
109
sendRequest,
@@ -85,18 +84,4 @@ router.put("/reject/:opponentId", async (req: Request, res: Response) => {
8584
}
8685
});
8786

88-
//オートマッチ(メモ帳、運営等に使用)
89-
router.post("/autoMatch", async (req: Request, res: Response) => {
90-
const requesterId = await safeGetUserId(req);
91-
if (!requesterId.ok) return res.status(401).send("auth error");
92-
93-
try {
94-
await autoMatch(requesterId.value as UserID);
95-
res.status(204).send();
96-
} catch (error) {
97-
console.error("Error rejecting match request:", error);
98-
res.status(500).json({ error: "Failed to reject match request" });
99-
}
100-
});
101-
10287
export default router;

server/src/router/users.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import express, { type Request, type Response } from "express";
99
import {
1010
getPendingRequestsFromUser,
1111
getPendingRequestsToUser,
12+
matchWithMemo,
1213
} from "../database/requests";
1314
import {
1415
createUser,
@@ -124,10 +125,20 @@ router.get("/id/:id", async (req: Request, res: Response) => {
124125
// INSERT INTO "User" VALUES (body...)
125126
router.post("/", async (req: Request, res: Response) => {
126127
const partialUser = InitUserSchema.safeParse(req.body);
127-
if (!partialUser.success) return res.status(400).send("invalid format");
128+
if (!partialUser.success)
129+
return res.status(400).send({
130+
error: "Invalid input format",
131+
details: partialUser.error.errors,
132+
});
128133

129134
const user = await createUser(partialUser.data);
130-
if (!user.ok) return res.status(500).send();
135+
if (!user.ok) return res.status(500).send({ error: "Failed to create user" });
136+
137+
//ユーザー作成と同時にメモとマッチング
138+
const result = await matchWithMemo(user.value.id);
139+
if ("ok" in result && !result.ok) {
140+
return res.status(500).send({ error: "Failed to match user with memo" });
141+
}
131142
res.status(201).json(user.value);
132143
});
133144

web/api/internal/endpoints.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,6 @@ export const rejectRequest = (opponentId: UserID) => {
280280
return `${origin}/requests/reject/${opponentId}`;
281281
};
282282

283-
export const autoMatch = () => {
284-
return `${origin}/requests/autoMatch/`;
285-
};
286-
287283
/**
288284
* []実装済み
289285
* GET -> get personalized room overviews.
@@ -385,7 +381,6 @@ export default {
385381
sendRequest,
386382
acceptRequest,
387383
rejectRequest,
388-
autoMatch,
389384
cancelRequest,
390385
coursesUserId,
391386
coursesDayPeriod,

web/api/request.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,8 @@ export async function accept(senderId: UserID) {
2626
return data;
2727
}
2828

29-
export async function autoMatch() {
30-
const res = await credFetch("POST", endpoints.autoMatch());
31-
const data = await res.text();
32-
return data;
33-
}
34-
3529
export default {
3630
send,
3731
reject,
3832
accept,
39-
autoMatch,
4033
};

web/app/signup/page.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { useState } from "react";
55

66
import type { Step1User } from "common/zod/types";
77
import { useRouter } from "next/navigation";
8-
import request from "~/api/request";
98
import Header from "~/components/Header";
109
import { NavigateByAuthState } from "~/components/common/NavigateByAuthState";
1110
import { register } from "./functions";
@@ -14,10 +13,6 @@ import Step2, { type Step2Data } from "./steps/step2_img";
1413
import Confirmation from "./steps/step3_confirmation";
1514
import Step4 from "./steps/step4_course";
1615

17-
function matchWithMemo() {
18-
request.autoMatch();
19-
}
20-
2116
function Registration() {
2217
const { enqueueSnackbar } = useSnackbar();
2318
const router = useRouter();
@@ -63,7 +58,6 @@ function Registration() {
6358
};
6459
try {
6560
await register(concat, { enqueueSnackbar, router });
66-
matchWithMemo();
6761
setStep(4);
6862
} catch (error) {
6963
enqueueSnackbar("サインアップに失敗しました", {

web/components/chat/RoomList.tsx

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ export function RoomList(props: RoomListProps) {
1919
*/
2020
const navigateToRoom = (room: Extract<RoomOverview, { isDM: true }>) => {
2121
router.push(
22-
`./?friendId=${room.friendId}&roomData=${encodeURIComponent(JSON.stringify(room))}`,
22+
`./?friendId=${room.friendId}&roomData=${encodeURIComponent(
23+
JSON.stringify(room),
24+
)}`,
2325
);
2426
};
2527

@@ -41,27 +43,6 @@ export function RoomList(props: RoomListProps) {
4143
</p>
4244
{roomsData?.map((room) => {
4345
if (room.isDM) {
44-
if (room.friendId === 0) {
45-
//Keepメモ
46-
return (
47-
<Box
48-
key={room.friendId}
49-
onClick={() => {
50-
// `state`を使って`room`データを渡す
51-
navigate("./memo", { state: { room } });
52-
}}
53-
>
54-
<HumanListItem
55-
key={room.friendId}
56-
id={room.friendId}
57-
name={room.name}
58-
pictureUrl={room.thumbnail}
59-
rollUpName={true}
60-
lastMessage={room.lastMsg?.content}
61-
/>
62-
</Box>
63-
);
64-
}
6546
return (
6647
<Box
6748
key={room.friendId}

0 commit comments

Comments
 (0)