@@ -7,33 +7,29 @@ import { supabase } from "../app";
77
88export const getProjects = async ( req : Request , res : Response ) => {
99
10- try {
10+
1111 const projects = await projectService . getProjects ( ) ;
1212 res . status ( 200 ) . json ( projects ) ;
13- } catch ( error ) {
14- res . status ( 500 ) . json ( { error : "Failed to fetch projects" } ) ;
15- }
13+
1614} ;
1715
1816
1917export const getProjectById = async ( req : Request , res : Response ) => {
2018
21- try {
19+
2220 const projectId = parseInt ( req . params . projectId ) ;
2321
2422 if ( isNaN ( projectId ) ) throw new ApiError ( "Invalid project ID" , 400 ) ;
2523
2624 const project = await projectService . getProjectById ( projectId ) ;
2725 res . status ( 200 ) . json ( project ) ;
2826
29- } catch ( error ) {
30- throw new ApiError ( "No project with this ID" , 500 ) ;
31- }
27+
3228} ;
3329
3430export const createProject = async ( req : Request , res : Response ) => {
3531
36- try {
32+
3733 const file = req . file ;
3834 if ( ! file ) throw new ApiError ( 'Image file not found' , 400 ) ;
3935
@@ -54,14 +50,11 @@ export const createProject = async ( req : Request , res : Response ) => {
5450 const project = await projectService . createProject ( projectContent ) ;
5551 res . status ( 200 ) . json ( project ) ;
5652
57- } catch ( error ) {
58- throw new ApiError ( error as string , 500 ) ;
59- }
6053} ;
6154
6255export const updateProjects = async ( req : Request , res : Response ) => {
6356
64- try {
57+
6558 const projectInfo = req . body . projectData ;
6659 const projectId = parseInt ( req . params . projectId ) ;
6760 const updatedById = projectInfo . updatedById ;
@@ -83,47 +76,40 @@ export const updateProjects = async ( req : Request , res : Response ) => {
8376 const project = await projectService . updateProjects ( projectInfo , projectId ) ;
8477 res . status ( 200 ) . json ( project )
8578
86- } catch ( error ) {
87- throw new ApiError ( error as string , 500 ) ;
88- }
79+
8980}
9081
9182
9283export const deleteProjects = async ( req : Request , res : Response ) => {
9384
94- try {
85+
9586 const projectId = parseInt ( req . params . projectId ) ;
9687 if ( ! projectId ) throw new ApiError ( " Send The project id " , 400 ) ;
9788
9889 const deleted = await projectService . deleteProjects ( projectId ) ;
9990 res . status ( 200 ) . json ( deleted )
10091
101- } catch ( error ) {
102- throw new ApiError ( error as string , 500 ) ;
103- }
92+
10493
10594}
10695
10796export const getMembersByProjectId = async ( req : Request , res : Response ) => {
10897
109- try {
98+
11099 const projectId = parseInt ( req . params . projectId ) ;
111100 if ( ! projectId ) throw new ApiError ( " Project Id required !!! " , 400 ) ;
112101
113102 const members = await projectService . getMembersByProjectId ( projectId ) ;
114103 res . status ( 200 ) . json ( members )
115104
116- }
117- catch ( error ) {
118- throw new ApiError ( error as string , 500 ) ;
119- }
105+
120106
121107
122108}
123109
124110export const addMembers = async ( req : Request , res : Response ) => {
125111
126- try {
112+
127113 const projectId = parseInt ( req . params . projectId ) ;
128114 const memberData = req . body . memberId ;
129115 if ( ! projectId || ! memberData || memberData . length === 0 ) throw new ApiError ( " field is missing " , 400 ) ;
@@ -136,15 +122,13 @@ export const addMembers = async ( req : Request , res : Response ) => {
136122 const member = await projectService . addMembers ( data ) ;
137123 res . status ( 200 ) . json ( member ) ;
138124
139- } catch ( error ) {
140- throw new ApiError ( error as string , 500 ) ;
141- }
125+
142126}
143127
144128
145129export const removeMembers = async ( req : Request , res : Response ) => {
146130
147- try {
131+
148132 const data = {
149133 projectId : parseInt ( req . params . projectId ) ,
150134 memberId : req . params . memberId
@@ -155,8 +139,6 @@ export const removeMembers = async ( req : Request , res : Response ) => {
155139 const removedMember = await projectService . removeMembers ( data ) ;
156140 res . status ( 200 ) . json ( removedMember ) ;
157141
158- } catch ( error ) {
159- throw new ApiError ( error as string , 500 ) ;
160- }
142+
161143}
162144
0 commit comments