all requirement updated, and integrated with dev version of canvas
This commit is contained in:
parent
f91ff472d0
commit
c76b18346a
8 changed files with 58 additions and 6 deletions
5
.env
5
.env
|
|
@ -1,5 +1,5 @@
|
||||||
SERVER_URL=http://localhost
|
SERVER_URL=http://localhost
|
||||||
SERVER_PORT=3000
|
SERVER_PORT=3001
|
||||||
|
|
||||||
DATABASE_URL=postgres://postgres:saimon%40567@localhost:5432/planpost_canvas
|
DATABASE_URL=postgres://postgres:saimon%40567@localhost:5432/planpost_canvas
|
||||||
|
|
||||||
|
|
@ -14,6 +14,9 @@ JWT_ACCESS_TOKEN_SECRET=planpostai%^$_%43%65576canvas%%$$
|
||||||
|
|
||||||
JWT_REFRESH_TOKEN_SECRET=planpostai!@43223_canvas$%^$349332$$
|
JWT_REFRESH_TOKEN_SECRET=planpostai!@43223_canvas$%^$349332$$
|
||||||
|
|
||||||
|
# developer canvas server url
|
||||||
|
CANVAS_SERVER_URL_DEV=http://localhost:3000/api
|
||||||
|
|
||||||
PEXELS_URL=https://api.pexels.com/v1
|
PEXELS_URL=https://api.pexels.com/v1
|
||||||
PEXELS_ACCESS_KEY=6PK7hLvOuG6nFsmC8c9EV0P8hGkyHeIhYpiRxhkEfh2ePK0GhiQypBhI
|
PEXELS_ACCESS_KEY=6PK7hLvOuG6nFsmC8c9EV0P8hGkyHeIhYpiRxhkEfh2ePK0GhiQypBhI
|
||||||
|
|
||||||
|
|
|
||||||
18
src/api/design/design.controller.ts
Normal file
18
src/api/design/design.controller.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { ENV } from "../../config/env";
|
||||||
|
|
||||||
|
export const getAllDesign = async (token: string) => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${ENV.CANVAS_SERVER_URL_DEV}/design`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const data = await response.json();
|
||||||
|
return data;
|
||||||
|
} catch (error: any) {
|
||||||
|
console.log(error);
|
||||||
|
return { status: 500, message: error.message, token };
|
||||||
|
}
|
||||||
|
}
|
||||||
24
src/api/design/design.route.ts
Normal file
24
src/api/design/design.route.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
import Elysia from "elysia";
|
||||||
|
import { verifyAuth } from "../../middlewares/auth.middlewares";
|
||||||
|
import { getAllDesign } from "./design.controller";
|
||||||
|
|
||||||
|
export const designRoute = new Elysia({
|
||||||
|
prefix: "/design",
|
||||||
|
tags: ["Design"],
|
||||||
|
detail: {
|
||||||
|
description: "Routes for managing designs",
|
||||||
|
}
|
||||||
|
}).derive(async ({ cookie }) => {
|
||||||
|
const authData = await verifyAuth(cookie);
|
||||||
|
return { authData }; // Inject into context
|
||||||
|
})
|
||||||
|
|
||||||
|
designRoute.get("/", async ({ authData }) => {
|
||||||
|
if (authData.status !== 200)
|
||||||
|
return authData;
|
||||||
|
else {
|
||||||
|
const token = authData.token;
|
||||||
|
const response = await getAllDesign(token);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
@ -4,6 +4,7 @@ import { uploadRoutes } from "./upload/upload.route";
|
||||||
import { authRoute } from "./auth/auth.route";
|
import { authRoute } from "./auth/auth.route";
|
||||||
import { downloadRoute } from "./downloadCount/download.count.route";
|
import { downloadRoute } from "./downloadCount/download.count.route";
|
||||||
import { photoLibraryRoutes } from "./photoLibrary/photo.library.route";
|
import { photoLibraryRoutes } from "./photoLibrary/photo.library.route";
|
||||||
|
import { designRoute } from "./design/design.route";
|
||||||
|
|
||||||
export const api = new Elysia({
|
export const api = new Elysia({
|
||||||
prefix: "/api",
|
prefix: "/api",
|
||||||
|
|
@ -17,4 +18,5 @@ api.use(authRoute);
|
||||||
api.use(projectRoutes);
|
api.use(projectRoutes);
|
||||||
api.use(uploadRoutes);
|
api.use(uploadRoutes);
|
||||||
api.use(downloadRoute);
|
api.use(downloadRoute);
|
||||||
api.use(photoLibraryRoutes);
|
api.use(photoLibraryRoutes);
|
||||||
|
api.use(designRoute);
|
||||||
|
|
@ -86,10 +86,10 @@ export const createProject = async (userId: string, token: string) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateProject = async (id: string, body: any, token: string) => {
|
export const updateProject = async (id: string, body: any, token: string, user_id: string) => {
|
||||||
try {
|
try {
|
||||||
// 1. Validate if project exists
|
// 1. Validate if project exists
|
||||||
const existingProject = await db.select().from(projects).where(eq(projects.id, id)).limit(1);
|
const existingProject = await db.select().from(projects).where(eq(projects.id, id));
|
||||||
if (existingProject.length === 0) {
|
if (existingProject.length === 0) {
|
||||||
return { status: 404, message: "Project not found", token };
|
return { status: 404, message: "Project not found", token };
|
||||||
}
|
}
|
||||||
|
|
@ -101,7 +101,8 @@ export const updateProject = async (id: string, body: any, token: string) => {
|
||||||
object,
|
object,
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
preview_url
|
preview_url,
|
||||||
|
userId: user_id,
|
||||||
}).where(eq(projects.id, id)).returning({
|
}).where(eq(projects.id, id)).returning({
|
||||||
id: projects.id,
|
id: projects.id,
|
||||||
object: projects.object,
|
object: projects.object,
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,9 @@ projectRoutes.put("/update/:project_id", async ({ body, params: { project_id },
|
||||||
return authData;
|
return authData;
|
||||||
else {
|
else {
|
||||||
const token = authData.token;
|
const token = authData.token;
|
||||||
const response = await updateProject(project_id, body, token);
|
const user_id = authData?.userId;
|
||||||
|
// sending user_id to the controller to update the project with the user_id, when user tried to design a existing project from the design project panel
|
||||||
|
const response = await updateProject(project_id, body, token, user_id as string);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import { api } from "./api";
|
||||||
|
|
||||||
const allowedOrigins = [
|
const allowedOrigins = [
|
||||||
"http://localhost:5175",
|
"http://localhost:5175",
|
||||||
|
"http://localhost:5174",
|
||||||
"http://localhost:5173",
|
"http://localhost:5173",
|
||||||
"https://dashboard.planpostai.com",
|
"https://dashboard.planpostai.com",
|
||||||
"https://canvas.planpostai.com",
|
"https://canvas.planpostai.com",
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import 'dotenv/config'
|
||||||
export const ENV = {
|
export const ENV = {
|
||||||
SERVER_URL: process.env.SERVER_URL,
|
SERVER_URL: process.env.SERVER_URL,
|
||||||
SERVER_PORT: process.env.SERVER_PORT || 5000,
|
SERVER_PORT: process.env.SERVER_PORT || 5000,
|
||||||
|
CANVAS_SERVER_URL_DEV: process.env.CANVAS_SERVER_URL_DEV,
|
||||||
DATABASE_URL: process.env.DATABASE_URL,
|
DATABASE_URL: process.env.DATABASE_URL,
|
||||||
MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
|
MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
|
||||||
MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
|
MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue