43 lines
No EOL
1.2 KiB
TypeScript
43 lines
No EOL
1.2 KiB
TypeScript
import { Elysia, t } from "elysia";
|
|
import { deletePhoto, getAllPhoto, uploadPhoto } from "./upload.controller";
|
|
import { verifyAuth } from "../../middlewares/auth.middlewares";
|
|
|
|
export const uploadRoutes = new Elysia({
|
|
prefix: "/uploads",
|
|
tags: ["Uploads"],
|
|
detail: {
|
|
description: "Routes for uploading and managing photos",
|
|
}
|
|
}).derive(async ({ cookie, request }) => {
|
|
const authData = await verifyAuth(cookie, request);
|
|
if (authData.status !== 200) {
|
|
return { authData };
|
|
}
|
|
return { userId: authData.userId }; // Inject into context
|
|
});
|
|
|
|
uploadRoutes.post("/add", async ({ body, userId }) => {
|
|
const user_id: String | any = userId;
|
|
const { id: project_id, file } = body;
|
|
return uploadPhoto(file, project_id, user_id);
|
|
}, {
|
|
body: t.Object({
|
|
file: t.File(),
|
|
id: t.String(),
|
|
})
|
|
});
|
|
|
|
uploadRoutes.delete("/delete", async ({ query }) => {
|
|
const { url } = query;
|
|
return deletePhoto(url);
|
|
}, {
|
|
query: t.Object({
|
|
url: t.String(),
|
|
})
|
|
});
|
|
|
|
uploadRoutes.get("/getAll/:id", async ({ params: { id } }) => getAllPhoto(id), {
|
|
params: t.Object({
|
|
id: t.String()
|
|
})
|
|
}); |