upload photo controller fixed
This commit is contained in:
parent
473a741f10
commit
0e49fc53ab
1 changed files with 26 additions and 21 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../../db";
|
||||
import { uploads } from "../../db/schema";
|
||||
import { projects, uploads } from "../../db/schema";
|
||||
import { uploadToMinio } from "../../helper/upload/uploadToMinio";
|
||||
import { removeFromMinio } from "../../helper/upload/removeFromMinio";
|
||||
|
||||
|
|
@ -20,7 +20,9 @@ export const uploadPhoto = async (file: File, project_id: string, userId: string
|
|||
if (!file || !(file instanceof File) || !file.name) {
|
||||
return { status: 400, message: "Invalid or missing file", token };
|
||||
}
|
||||
const findProject = await db.select().from(projects).where(eq(projects.id, project_id));
|
||||
|
||||
if (findProject.length > 0) {
|
||||
// Extract file extension (e.g., ".jpg", ".png")
|
||||
const fileExtension = file.name.substring(file.name.lastIndexOf("."));
|
||||
|
||||
|
|
@ -42,7 +44,10 @@ export const uploadPhoto = async (file: File, project_id: string, userId: string
|
|||
}).returning();
|
||||
|
||||
return { status: 200, message: "File uploaded successfully", data: saveFile, token };
|
||||
|
||||
}
|
||||
else {
|
||||
return { status: 404, message: "No projects found with this project id", token }
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error("Error processing file:", error);
|
||||
return { status: 500, message: "An error occurred while uploading the photo", token };
|
||||
|
|
@ -52,7 +57,7 @@ export const uploadPhoto = async (file: File, project_id: string, userId: string
|
|||
export const deletePhoto = async (url: string, token: string) => {
|
||||
try {
|
||||
if (!url) {
|
||||
return { status: 404, message: "File ID is missing", token }
|
||||
return { status: 404, message: "File url is missing", token }
|
||||
}
|
||||
|
||||
const deleteFile = await db
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue