Skip to content

Commit

Permalink
streakを編集できないように変更
Browse files Browse the repository at this point in the history
  • Loading branch information
MurakawaTakuya committed Dec 20, 2024
1 parent adb92ca commit d8250be
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 12 deletions.
12 changes: 4 additions & 8 deletions functions/src/routers/userRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ router.get("/name/:userName", async (req: Request, res: Response) => {
router.post("/", async (req: Request, res: Response) => {
let userId: string;
let name: User["name"];
let streak: User["streak"];
let fcmToken: User["fcmToken"];

try {
({ name, userId, streak = 0, fcmToken = "" } = req.body);
({ name, userId, fcmToken = "" } = req.body);
} catch (error) {
return res.status(400).json({ message: "Invalid request body" });
}
Expand All @@ -108,7 +107,7 @@ router.post("/", async (req: Request, res: Response) => {
try {
await db.collection("user").doc(userId).set({
name: name,
streak: streak,
streak: 0,
fcmToken: fcmToken,
});

Expand All @@ -123,9 +122,9 @@ router.post("/", async (req: Request, res: Response) => {
// PUT: ユーザー情報を更新
router.put("/:userId", async (req: Request, res: Response) => {
const userId = req.params.userId;
const { name, streak, fcmToken }: Partial<User> = req.body;
const { name, fcmToken }: Partial<User> = req.body;

if (!name && !streak && fcmToken === undefined) {
if (!name && fcmToken === undefined) {
return res.status(400).json({
message: "At least one of name, streak, or fcmToken is required",
});
Expand All @@ -135,9 +134,6 @@ router.put("/:userId", async (req: Request, res: Response) => {
if (name) {
updateData.name = name;
}
if (streak) {
updateData.streak = streak;
}
if (fcmToken !== undefined) {
updateData.fcmToken = fcmToken;
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface UserData {
userId: string;
name: string;
streak: number;
streak?: number;
loginType: LoginType;
isMailVerified: boolean;
}
Expand Down
1 change: 0 additions & 1 deletion src/utils/Auth/signInWithGoogleAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const signInWithGoogleAccount = async () => {
updateUser({
userId: result.user.uid,
name: result.user.displayName ?? "no name",
streak: 0,
loginType: "Google",
isMailVerified: result.user.emailVerified,
});
Expand Down
1 change: 0 additions & 1 deletion src/utils/Auth/signUpWithMail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const signUpWithMail = async (
updateUser({
userId: user.uid,
name: name,
streak: 0,
loginType: "Mail",
isMailVerified: user.emailVerified,
});
Expand Down
1 change: 0 additions & 1 deletion src/utils/UserContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export const UserProvider = ({ children }: Props) => {
const guestData: UserData = {
userId: firebaseUser.uid,
name: "Guest Login",
streak: 0,
loginType: "Guest",
isMailVerified: true,
};
Expand Down

0 comments on commit d8250be

Please sign in to comment.