File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,13 +3,31 @@ import * as memberService from "../services/member.service";
33import { ApiError } from "../utils/apiError" ;
44import { deleteImage , uploadImage } from "../utils/imageUtils" ;
55import { SupabaseClient } from "@supabase/supabase-js" ;
6+ import { password } from "bun" ;
67
78// List all approved members
89export const listAllApprovedMembers = async ( req : Request , res : Response ) => {
10+
11+ const body = req . body ;
12+
13+ if ( body . email ) {
14+
15+ const user = memberService . getUserByEmail ( body . email ) ;
16+
17+ if ( ! user ) throw new ApiError ( 'Incorrect email' , 400 ) ;
18+
19+ res . status ( 200 ) . json ( {
20+ success : true ,
21+ user
22+ } )
23+ }
24+ else {
925 const user = await memberService . approvedMembers ( ) ;
1026 res
1127 . status ( 200 )
1228 . json ( { user, success : true , message : "Fetched approved users" } ) ;
29+ }
30+
1331} ;
1432
1533// Get details of a single user
Original file line number Diff line number Diff line change @@ -27,7 +27,17 @@ export default function membersRouter(
2727 * @apiName ListAllApprovedMembers
2828 * @apiGroup Member
2929 *
30- * @apiSuccess {Object[]} user List of approved members.
30+ * * @apiDescription
31+ * - Returns a list of all approved members if no email is provided.
32+ * - If `email` is provided in the request body, returns the member associated with that email.
33+ *
34+ * @apiBody {String} [email] Optional email to fetch a specific member.
35+ *
36+ * @apiSuccess {Boolean} success Whether the operation was successful.
37+ * @apiSuccess {Object|Object[]} user The user object (if email provided) or list of approved members.
38+ * @apiSuccess {String} [message] Message in case of full list fetch.
39+ *
40+ * @apiError (400) IncorrectEmail The provided email does not match any user.
3141 */
3242 router . get ( "/" , memberCtrl . listAllApprovedMembers ) ;
3343
Original file line number Diff line number Diff line change 11import { prisma } from "../db/client" ;
22import { ApiError } from "../utils/apiError" ;
33
4- export const checkAdmin = async ( adminId : string ) => {
4+ export const getUserByEmail = async ( email : string ) => {
55 return await prisma . member . findUnique ( {
66 where : {
7- id : adminId ,
8- isManager : true ,
7+ email : email
98 } ,
10- } ) ;
11- } ;
9+ select : {
10+ id : true ,
11+ accounts : {
12+ where : {
13+ provider : 'credentials' ,
14+ } ,
15+ select : {
16+ password : true ,
17+ } ,
18+ } ,
19+ }
20+ } )
21+ }
1222
1323export const approvedMembers = async ( ) => {
1424 return await prisma . member . findMany ( {
You can’t perform that action at this time.
0 commit comments