Skip to content

Commit 84a13ab

Browse files
KeepMemo (#444)
<!--変更したい場合は、`/.github/pull_request_template.md` を修正して下さい。--> # PRの概要 オートマッチの機能を作った。後々には運営アカウントのチャットを作ったり、問い合わせ機能の移管などができる。 <!-- 変更の目的 もしくは 関連する Issue 番号 --> <!-- 以下のように書くと Issue にリンクでき、マージ時に自動で Issue を閉じられる--> <!-- closes #1 --> closes #418 ## 具体的な変更内容 <!-- ビューの変更がある場合はスクショによる比較などがあるとわかりやすい --> ## 影響範囲 <!-- この関数を変更したのでこの機能にも影響がある、など --> ## 動作要件 <!-- 動作に必要な 環境変数 / 依存関係 / DBの更新 など --> DBにID=0の"Keepメモ"を作ってください。 いらすとやの https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvpbYflYCwbG_c11ADWhZUaf93zrtmvYYjSvY4NNxcF4Ri-XO6jiFZq-1InXfcxBjTD9_8jQntvnzML5F0geA04H9etzy3dcZ7SaqpbfKX4PmFgg8nplhaSLBCWo6zOIwq-jJc9tjrXxKV/s1600/bunbougu_memo.png をpictureUrlに用いるのがおすすめ ## 補足 <!-- レビューをする際に見てほしい点、ローカル環境で試す際の注意点、など --> ## レビューリクエストを出す前にチェック! - [ ] 改めてセルフレビューしたか - [ ] 手動での動作検証を行ったか - [ ] server の機能追加ならば、テストを書いたか - 理由: 書いた | server の機能追加ではない - [ ] 間違った使い方が存在するならば、それのドキュメントをコメントで書いたか - 理由: 書いた | 間違った使い方は存在しない - [ ] わかりやすいPRになっているか <!-- レビューリクエスト後は、Slackでもメンションしてお願いすることを推奨します。 --> --------- Co-authored-by: KaichiManabe <[email protected]>
1 parent 7a845bb commit 84a13ab

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed

server/src/database/requests.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,19 @@ export async function getMatchedUser(userId: UserID): Promise<Result<User[]>> {
183183
return Err(e);
184184
}
185185
}
186+
187+
export async function matchWithMemo(userId: UserID) {
188+
try {
189+
const result = await prisma.relationship.create({
190+
data: {
191+
status: "MATCHED",
192+
sendingUserId: userId,
193+
receivingUserId: 0, //KeepメモのUserId
194+
},
195+
});
196+
197+
return result;
198+
} catch (error) {
199+
return Err(error);
200+
}
201+
}

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/components/match/matching.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,24 @@ export default function Matchings() {
2525
<p className="text-red-500">Error: {error.message}</p>
2626
) : (
2727
<ul className="mt-4 space-y-4">
28-
{data?.map((matchedUser) => (
29-
<HumanListItem
30-
key={matchedUser.id}
31-
id={matchedUser.id}
32-
name={matchedUser.name}
33-
pictureUrl={matchedUser.pictureUrl}
34-
onOpen={() => openModal(matchedUser)}
35-
onDelete={() => deleteMatch(matchedUser.id).then(() => reload())}
36-
hasDots
37-
/>
38-
))}
28+
{data?.map((matchedUser) =>
29+
matchedUser.id === 0 ? (
30+
//メモ帳
31+
<div key={0} />
32+
) : (
33+
<HumanListItem
34+
key={matchedUser.id}
35+
id={matchedUser.id}
36+
name={matchedUser.name}
37+
pictureUrl={matchedUser.pictureUrl}
38+
onOpen={() => openModal(matchedUser)}
39+
onDelete={() =>
40+
deleteMatch(matchedUser.id).then(() => reload())
41+
}
42+
hasDots
43+
/>
44+
),
45+
)}
3946
</ul>
4047
)}
4148
</div>

0 commit comments

Comments
 (0)