11import * as projectService from "../services/project.service" ;
22import { Request , Response } from "express" ;
33import { ApiError } from "../utils/apiError" ;
4- import { error } from "console" ;
54import { uploadImage } from "../utils/imageUtils" ;
65import { supabase } from "../app" ;
76
7+
88export const getProjects = async ( req : Request , res : Response ) => {
99
1010 try {
1111 const projects = await projectService . getProjects ( ) ;
1212 res . status ( 200 ) . json ( projects ) ;
13- } catch ( error ) {
14- throw new ApiError ( "No project found !!!" , 500 )
13+ } catch ( error ) {
14+ res . status ( 500 ) . json ( { error : "Failed to fetch projects" } ) ;
1515 }
1616} ;
1717
18+
1819export const getProjectById = async ( req : Request , res : Response ) => {
1920
2021 try {
2122 const projectId = parseInt ( req . params . projectId ) ;
2223
23- if ( ! projectId ) throw new ApiError ( " Field is missing !!! " , 400 ) ;
24+ if ( isNaN ( projectId ) ) throw new ApiError ( "Invalid project ID " , 400 ) ;
2425
2526 const project = await projectService . getProjectById ( projectId ) ;
2627 res . status ( 200 ) . json ( project ) ;
@@ -34,7 +35,7 @@ export const createProject = async ( req : Request , res : Response ) => {
3435
3536 try {
3637 const file = req . file ;
37- if ( ! file ) throw new ApiError ( 'Image file is not find ' , 400 ) ;
38+ if ( ! file ) throw new ApiError ( 'Image file not found ' , 400 ) ;
3839
3940 const imageUrl = await uploadImage ( supabase , file , 'projects' ) ;
4041
@@ -54,7 +55,7 @@ export const createProject = async ( req : Request , res : Response ) => {
5455 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
0 commit comments