Skip to content

Commit 44214a6

Browse files
committed
improvement is done accoding to the suggestion
1 parent df43cee commit 44214a6

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/controllers/project.controller.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
import * as projectService from "../services/project.service";
22
import { Request , Response } from "express";
33
import { ApiError } from "../utils/apiError";
4-
import { error } from "console";
54
import { uploadImage } from "../utils/imageUtils";
65
import { supabase } from "../app";
76

7+
88
export 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+
1819
export 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

Comments
 (0)