@@ -6,21 +6,22 @@ export const getProjects = async ( req : Request , res : Response ) => {
66
77 try {
88 const projects = await projectService . getPrjects ( ) ;
9- res . json ( projects ) ;
9+ res . status ( 200 ) . json ( projects ) ;
1010 } catch ( error ) {
11- throw new ApiError ( "No project found !!!" , 404 )
11+ throw new ApiError ( "No project found !!!" , 500 )
1212 }
1313} ;
1414
1515export const getProjectById = async ( req : Request , res : Response ) => {
1616
1717 try {
1818 const projectId = parseInt ( req . params . projectId ) ;
19+ if ( ! projectId ) throw new ApiError ( " Field is missing !!!" , 400 ) ;
1920 const project = await projectService . getProjectById ( projectId ) ;
20- res . json ( project ) ;
21+ res . status ( 200 ) . json ( project ) ;
2122
2223 } catch ( error ) {
23- throw new ApiError ( "No project with this ID" , 404 ) ;
24+ throw new ApiError ( "No project with this ID" , 500 ) ;
2425 }
2526} ;
2627
@@ -36,10 +37,10 @@ export const createProject = async ( req : Request , res : Response ) => {
3637 } ;
3738
3839 const project = await projectService . createProject ( projectContent ) ;
39- res . json ( project ) ;
40+ res . status ( 200 ) . json ( project ) ;
4041
4142 } catch ( error ) {
42- throw new ApiError ( error as string , 404 ) ;
43+ throw new ApiError ( error as string , 500 ) ;
4344 }
4445} ;
4546
@@ -48,13 +49,13 @@ export const updateProjects = async ( req : Request , res : Response ) => {
4849 try {
4950 const projectInfo = req . body ;
5051 const projectId = parseInt ( req . params . projectId ) ;
51- if ( ! projectId ) throw new ApiError ( " Send The project id " , 401 ) ;
52+ if ( ! projectId ) throw new ApiError ( " Send The project id " , 400 ) ;
5253
5354 const project = await projectService . updateProjects ( projectInfo , projectId ) ;
54- res . json ( project )
55+ res . status ( 200 ) . json ( project )
5556
5657 } catch ( error ) {
57- throw new ApiError ( error as string , 404 ) ;
58+ throw new ApiError ( error as string , 500 ) ;
5859 }
5960}
6061
@@ -63,15 +64,15 @@ export const deleteProjects = async ( req : Request , res : Response ) => {
6364
6465 try {
6566 const projectId = parseInt ( req . params . projectId ) ;
66- if ( ! projectId ) throw new ApiError ( " Send The project id " , 401 ) ;
67+ if ( ! projectId ) throw new ApiError ( " Send The project id " , 400 ) ;
6768
6869
6970 const deleted = await projectService . deleteProjects ( projectId ) ;
70- res . json ( deleted )
71+ res . status ( 200 ) . json ( deleted )
7172
7273 } catch ( error ) {
7374 console . log ( error )
74- throw new ApiError ( error as string , 404 ) ;
75+ throw new ApiError ( error as string , 500 ) ;
7576 }
7677
7778}
@@ -81,14 +82,14 @@ export const getMembersByProjectId = async ( req : Request , res : Response ) =>
8182 try {
8283 const projectId = parseInt ( req . params . ProjectId ) ;
8384
84- if ( ! projectId ) throw new ApiError ( " Project Id required !!! " , 401 ) ;
85+ if ( ! projectId ) throw new ApiError ( " Project Id required !!! " , 400 ) ;
8586
8687 const members = await projectService . getMembersByProjectId ( projectId ) ;
87- res . json ( members )
88+ res . status ( 200 ) . json ( members )
8889
8990 }
9091 catch ( error ) {
91- throw new ApiError ( error as string , 404 ) ;
92+ throw new ApiError ( error as string , 500 ) ;
9293 }
9394
9495
@@ -103,10 +104,10 @@ export const addMembers = async ( req : Request , res : Response ) => {
103104 }
104105
105106 const member = await projectService . addMembers ( data ) ;
106- res . json ( member )
107+ res . status ( 200 ) . json ( member )
107108 } catch ( error ) {
108109 console . log ( error )
109- throw new ApiError ( error as string , 404 ) ;
110+ throw new ApiError ( error as string , 500 ) ;
110111 }
111112}
112113
@@ -120,10 +121,10 @@ export const removeMembers = async ( req : Request , res : Response ) => {
120121 }
121122
122123 const removedMember = await projectService . removeMembers ( data ) ;
123- res . json ( removedMember ) ;
124+ res . status ( 200 ) . json ( removedMember ) ;
124125
125126 } catch ( error ) {
126- throw new ApiError ( error as string , 404 ) ;
127+ throw new ApiError ( error as string , 500 ) ;
127128 }
128129}
129130
0 commit comments