11import * as projectService from "../services/project.service" ;
22import { Request , Response } from "express" ;
33import { ApiError } from "../utils/apiError" ;
4+ import { error } from "console" ;
45
56export const getProjects = async ( req : Request , res : Response ) => {
67
78 try {
8- const projects = await projectService . getPrjects ( ) ;
9+ const projects = await projectService . getProjects ( ) ;
910 res . status ( 200 ) . json ( projects ) ;
1011 } catch ( error ) {
1112 throw new ApiError ( "No project found !!!" , 500 )
@@ -17,6 +18,7 @@ export const getProjectById = async ( req : Request , res : Response ) => {
1718 try {
1819 const projectId = parseInt ( req . params . projectId ) ;
1920 if ( ! projectId ) throw new ApiError ( " Field is missing !!!" , 400 ) ;
21+
2022 const project = await projectService . getProjectById ( projectId ) ;
2123 res . status ( 200 ) . json ( project ) ;
2224
@@ -28,13 +30,9 @@ export const getProjectById = async ( req : Request , res : Response ) => {
2830export const createProject = async ( req : Request , res : Response ) => {
2931
3032 try {
31- const projectContent = {
32- name : req . body . name ,
33- imageUrl : req . body . imageUrl ,
34- githubUrl : req . body . githubUrl ,
35- deployUrl : req . body . deployUrl ,
36- adminId : req . AdminId ,
37- } ;
33+ const projectContent = req . body ;
34+
35+ if ( ! projectContent . name || ! projectContent . githubUrl ) throw new ApiError ( " Field is missing !!!" , 400 ) ;
3836
3937 const project = await projectService . createProject ( projectContent ) ;
4038 res . status ( 200 ) . json ( project ) ;
@@ -66,12 +64,10 @@ export const deleteProjects = async ( req : Request , res : Response ) => {
6664 const projectId = parseInt ( req . params . projectId ) ;
6765 if ( ! projectId ) throw new ApiError ( " Send The project id " , 400 ) ;
6866
69-
7067 const deleted = await projectService . deleteProjects ( projectId ) ;
7168 res . status ( 200 ) . json ( deleted )
7269
7370 } catch ( error ) {
74- console . log ( error )
7571 throw new ApiError ( error as string , 500 ) ;
7672 }
7773
@@ -81,7 +77,6 @@ export const getMembersByProjectId = async ( req : Request , res : Response ) =>
8177
8278 try {
8379 const projectId = parseInt ( req . params . ProjectId ) ;
84-
8580 if ( ! projectId ) throw new ApiError ( " Project Id required !!! " , 400 ) ;
8681
8782 const members = await projectService . getMembersByProjectId ( projectId ) ;
@@ -98,15 +93,19 @@ export const getMembersByProjectId = async ( req : Request , res : Response ) =>
9893export const addMembers = async ( req : Request , res : Response ) => {
9994
10095 try {
101- const data = {
102- projectId : parseInt ( req . params . projectId ) ,
103- memberId : req . body . memberId
104- }
96+ const projectId = parseInt ( req . params . projectId ) ;
97+ const memberData = req . body . memberId ;
98+ if ( ! projectId || memberData . length === 0 ) throw new ApiError ( " field is missing " , 400 ) ;
99+
100+ const data = memberData . map ( ( memberId : string ) => ( {
101+ projectId,
102+ memberId
103+ } ) )
105104
106105 const member = await projectService . addMembers ( data ) ;
107- res . status ( 200 ) . json ( member )
106+ res . status ( 200 ) . json ( member ) ;
107+
108108 } catch ( error ) {
109- console . log ( error )
110109 throw new ApiError ( error as string , 500 ) ;
111110 }
112111}
0 commit comments