Skip to content

Commit 20befe4

Browse files
committed
Updated update member route to accept password field
1 parent 99ba66f commit 20befe4

3 files changed

Lines changed: 17 additions & 15 deletions

File tree

src/controllers/member.controller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as memberService from "../services/member.service";
33
import { ApiError } from "../utils/apiError";
44
import { uploadImage } from "../utils/imageUtils";
55
import { SupabaseClient } from "@supabase/supabase-js";
6+
import { password } from "bun";
67

78
// List all approved members
89
export const listAllApprovedMembers = async (req: Request, res: Response) => {
@@ -46,7 +47,7 @@ export const createAMember =
4647
(supabase: SupabaseClient) => async (req: Request, res: Response) => {
4748
const {email, name, password, passoutYear, provider} = req.body;
4849

49-
if (!email || !name || !password || !passoutYear) {
50+
if (!email || !name || !password || !passoutYear || !provider) {
5051
throw new ApiError("Required fields absent", 400);
5152
}
5253

src/services/member.service.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,28 @@ export const createMember = async (
6666

6767
export const updateMember = async (
6868
id: string,
69-
payload: UpdateMemberPayload,
69+
payload: UpdateMemberPayload
7070
) => {
71-
const { name, ...rest } = payload;
71+
const { name, password, ...rest } = payload;
7272

73-
const member = await prisma.member.findUnique({
74-
where: {
75-
id: id,
76-
},
77-
});
73+
if (password) {
74+
const account = await prisma.account.findFirst({
75+
where: { memberId: id },
76+
});
77+
78+
if (!account) throw new ApiError("Associated account not found", 404);
7879

79-
if (!member) {
80-
throw new ApiError("Member not found", 404);
80+
return await prisma.account.update({
81+
where: { id: account.id },
82+
data: { password },
83+
});
8184
}
8285

8386
const dataToUpdate = Object.fromEntries(
84-
Object.entries(rest).filter(([_, v]) => v !== undefined),
87+
Object.entries({ name, ...rest }).filter(([_, v]) => v !== undefined)
8588
);
8689

87-
if (JSON.stringify(dataToUpdate) === "{}")
88-
throw new ApiError("No fields passed", 400);
90+
if (JSON.stringify(dataToUpdate) === "{}" && !password) throw new ApiError("No fields passed", 400);
8991

9092
return await prisma.member.update({
9193
where: { id },

src/types/members.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ declare global {
1515
leetcode?: string;
1616
codechef?: string;
1717
codeforces?: string;
18-
isApproved?: boolean;
19-
approvedBy?: string;
18+
password?: string
2019
}
2120
}

0 commit comments

Comments
 (0)