Compare commits
No commits in common. "main" and "dev" have entirely different histories.
17 changed files with 436 additions and 745 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
# Build stage
|
# Build stage
|
||||||
FROM oven/bun:1 AS builder
|
FROM oven/bun:1 AS builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy package files
|
# Copy package files
|
||||||
COPY package.json .
|
COPY package.json .
|
||||||
COPY bun.lockb .
|
COPY bun.lockb .
|
||||||
|
|
@ -14,8 +16,6 @@ COPY . .
|
||||||
# Build the application
|
# Build the application
|
||||||
RUN bun run build
|
RUN bun run build
|
||||||
|
|
||||||
EXPOSE 5005
|
|
||||||
|
|
||||||
# Production stage
|
# Production stage
|
||||||
# FROM debian:bookworm-slim
|
# FROM debian:bookworm-slim
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ services:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
ports:
|
# ports:
|
||||||
- "5005:5005"
|
# - "${SERVER_PORT}:${SERVER_PORT}"
|
||||||
depends_on:
|
depends_on:
|
||||||
db:
|
db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import { defineConfig } from "drizzle-kit";
|
import { defineConfig } from 'drizzle-kit';
|
||||||
import { ENV } from "./src/config/env";
|
import { ENV } from './src/config/env';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
out: "./drizzle",
|
out: './drizzle',
|
||||||
schema: "./src/db/schema.ts",
|
schema: './src/db/schema.ts',
|
||||||
dialect: "postgresql",
|
dialect: 'postgresql',
|
||||||
dbCredentials: {
|
dbCredentials: {
|
||||||
url: ENV.DATABASE_URL!,
|
url: ENV.DATABASE_URL!,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
21
env.example
21
env.example
|
|
@ -1,21 +0,0 @@
|
||||||
SERVER_URL=
|
|
||||||
SERVER_PORT=
|
|
||||||
|
|
||||||
DATABASE_URL=
|
|
||||||
|
|
||||||
MINIO_ACCESS_KEY=
|
|
||||||
MINIO_SECRET_KEY=
|
|
||||||
MINIO_ENDPOINT=
|
|
||||||
MINIO_PORT=
|
|
||||||
|
|
||||||
CLERK_SECRET_KEY=
|
|
||||||
|
|
||||||
JWT_ACCESS_TOKEN_SECRET=
|
|
||||||
|
|
||||||
JWT_REFRESH_TOKEN_SECRET=
|
|
||||||
|
|
||||||
# developer canvas server url
|
|
||||||
CANVAS_SERVER_URL_DEV=
|
|
||||||
|
|
||||||
PEXELS_URL=
|
|
||||||
PEXELS_ACCESS_KEY=
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { createClerkClient } from "@clerk/backend";
|
import { createClerkClient } from "@clerk/backend";
|
||||||
import { ENV } from "../../config/env";
|
import { ENV } from "../../config/env"
|
||||||
import { users } from "../../db/schema";
|
import { users } from "../../db/schema";
|
||||||
import { db } from "../../db";
|
import { db } from "../../db";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
|
|
@ -7,11 +7,7 @@ import { eq } from "drizzle-orm";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import jwt from "jsonwebtoken";
|
import jwt from "jsonwebtoken";
|
||||||
|
|
||||||
import {
|
import { checkUserInDB, createUser, storeRefreshToken } from "../../helper/auth/auth.helper";
|
||||||
checkUserInDB,
|
|
||||||
createUser,
|
|
||||||
storeRefreshToken,
|
|
||||||
} from "../../helper/auth/auth.helper";
|
|
||||||
import { verifyAuth } from "../../middlewares/auth.middlewares";
|
import { verifyAuth } from "../../middlewares/auth.middlewares";
|
||||||
|
|
||||||
// Initialize Clerk with your API key
|
// Initialize Clerk with your API key
|
||||||
|
|
@ -21,10 +17,11 @@ export const getUserData = async (userId: string) => {
|
||||||
try {
|
try {
|
||||||
const [user, checkInDB] = await Promise.all([
|
const [user, checkInDB] = await Promise.all([
|
||||||
clerk.users.getUser(userId),
|
clerk.users.getUser(userId),
|
||||||
checkUserInDB(userId),
|
checkUserInDB(userId)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (user && !checkInDB.found) {
|
if (user && !checkInDB.found) {
|
||||||
|
|
||||||
// Validate and transform user data
|
// Validate and transform user data
|
||||||
const userDBData = {
|
const userDBData = {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
|
|
@ -36,18 +33,10 @@ export const getUserData = async (userId: string) => {
|
||||||
|
|
||||||
const userData = await createUser(userDBData);
|
const userData = await createUser(userDBData);
|
||||||
|
|
||||||
return {
|
return { status: 200, message: "User retrieved successfully", data: userData };
|
||||||
status: 200,
|
|
||||||
message: "User retrieved successfully",
|
|
||||||
data: userData,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
if (user && checkInDB.found) {
|
if (user && checkInDB.found) {
|
||||||
return {
|
return { status: 200, message: "User retrieved successfully", data: checkInDB };
|
||||||
status: 200,
|
|
||||||
message: "User retrieved successfully",
|
|
||||||
data: checkInDB,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return { status: 404, message: "User not found" };
|
return { status: 404, message: "User not found" };
|
||||||
|
|
@ -58,36 +47,20 @@ export const getUserData = async (userId: string) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateUser = async (
|
export const updateUser = async (id: string, body: {
|
||||||
id: string,
|
paid_status: string,
|
||||||
body: {
|
package_expire_date: string,
|
||||||
paid_status: string;
|
}) => {
|
||||||
package_expire_date: string;
|
|
||||||
}
|
|
||||||
) => {
|
|
||||||
try {
|
try {
|
||||||
const updateUserData = await db
|
const updateUserData = await db.update(users).set({ paid_status: body?.paid_status, expires_in: body?.package_expire_date }).where(eq(users.id, id)).returning({ updatedId: users.id });
|
||||||
.update(users)
|
|
||||||
.set({
|
return { status: 200, message: "User updated successfully", updateUserData };
|
||||||
paid_status: body?.paid_status,
|
|
||||||
expires_in: body?.package_expire_date,
|
|
||||||
})
|
|
||||||
.where(eq(users.id, id))
|
|
||||||
.returning({ updatedId: users.id });
|
|
||||||
|
|
||||||
return {
|
|
||||||
status: 200,
|
|
||||||
message: "User updated successfully",
|
|
||||||
updateUserData,
|
|
||||||
};
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error("Error in updateUser:", error.message || error.toString());
|
console.error("Error in updateUser:", error.message || error.toString());
|
||||||
return {
|
return { status: 500, message: `An error occurred while updating the user` };
|
||||||
status: 500,
|
|
||||||
message: `An error occurred while updating the user`,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const generateToken = async (context: any) => {
|
export const generateToken = async (context: any) => {
|
||||||
try {
|
try {
|
||||||
|
|
@ -98,24 +71,16 @@ export const generateToken = async (context: any) => {
|
||||||
if (access_cookie !== undefined || refresh_cookie !== undefined) {
|
if (access_cookie !== undefined || refresh_cookie !== undefined) {
|
||||||
const verify = await verifyAuth(context?.cookie);
|
const verify = await verifyAuth(context?.cookie);
|
||||||
return verify;
|
return verify;
|
||||||
} else if (
|
}
|
||||||
access_cookie === undefined &&
|
else if (access_cookie === undefined && refresh_cookie === undefined && userId !== undefined) {
|
||||||
refresh_cookie === undefined &&
|
|
||||||
userId !== undefined
|
|
||||||
) {
|
|
||||||
const user = await checkUserInDB(userId);
|
const user = await checkUserInDB(userId);
|
||||||
if (user?.found === true) {
|
if (user?.found === true) {
|
||||||
|
|
||||||
// generate access token
|
// generate access token
|
||||||
const accessToken = jwt.sign({ userId }, ENV.JWT_ACCESS_TOKEN_SECRET, {
|
const accessToken = jwt.sign({ userId }, ENV.JWT_ACCESS_TOKEN_SECRET, { expiresIn: '3h' });
|
||||||
expiresIn: "3h",
|
|
||||||
});
|
|
||||||
|
|
||||||
// generate refresh token
|
// generate refresh token
|
||||||
const refreshToken = jwt.sign(
|
const refreshToken = jwt.sign({ userId }, ENV.JWT_REFRESH_TOKEN_SECRET, { expiresIn: '7d' });
|
||||||
{ userId },
|
|
||||||
ENV.JWT_REFRESH_TOKEN_SECRET,
|
|
||||||
{ expiresIn: "7d" }
|
|
||||||
);
|
|
||||||
|
|
||||||
// store refresh token in db
|
// store refresh token in db
|
||||||
const storeRToken = await storeRefreshToken(userId, refreshToken);
|
const storeRToken = await storeRefreshToken(userId, refreshToken);
|
||||||
|
|
@ -125,7 +90,7 @@ export const generateToken = async (context: any) => {
|
||||||
value: accessToken,
|
value: accessToken,
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
secure: true, // Set to true in production
|
secure: true, // Set to true in production
|
||||||
sameSite: "none", // Adjust based on your needs
|
sameSite: 'none', // Adjust based on your needs
|
||||||
path: "/",
|
path: "/",
|
||||||
maxAge: 3 * 60 * 60, // 3 hours in seconds
|
maxAge: 3 * 60 * 60, // 3 hours in seconds
|
||||||
});
|
});
|
||||||
|
|
@ -134,33 +99,27 @@ export const generateToken = async (context: any) => {
|
||||||
value: refreshToken,
|
value: refreshToken,
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
secure: true, // Set to true in production
|
secure: true, // Set to true in production
|
||||||
sameSite: "none", // Adjust based on your needs
|
sameSite: 'none', // Adjust based on your needs
|
||||||
path: "/",
|
path: "/",
|
||||||
maxAge: 7 * 24 * 60 * 60, // 7 days in seconds
|
maxAge: 7 * 24 * 60 * 60, // 7 days in seconds
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return { status: 201, message: "Token generated successfully", token: accessToken, user: user.user };
|
||||||
status: 201,
|
|
||||||
message: "Token generated successfully",
|
|
||||||
token: accessToken,
|
|
||||||
user: user.user,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
return {
|
return { status: 500, message: "An error occurred while storing the refresh token" };
|
||||||
status: 500,
|
}
|
||||||
message: "An error occurred while storing the refresh token",
|
else {
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return { status: 404, message: "User not found" };
|
return { status: 404, message: "User not found" };
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return { status: 404, message: "Unauthorized!!!" };
|
return { status: 404, message: "Unauthorized!!!" };
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error("Error in generateToken:", error.message || error.toString());
|
console.error("Error in generateToken:", error.message || error.toString());
|
||||||
return {
|
return { status: 500, message: `An error occurred while generating the token` };
|
||||||
status: 500,
|
|
||||||
message: `An error occurred while generating the token`,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,80 +1,47 @@
|
||||||
import { Elysia, t } from "elysia";
|
import Elysia, { t } from "elysia";
|
||||||
import { generateToken, getUserData, updateUser } from "./auth.controller";
|
import { generateToken, getUserData, updateUser } from "./auth.controller";
|
||||||
import { verifyAuth } from "../../middlewares/auth.middlewares";
|
import { verifyAuth } from "../../middlewares/auth.middlewares";
|
||||||
|
|
||||||
export const authRoute = new Elysia({ prefix: "/auth" });
|
export const authRoute = new Elysia({
|
||||||
|
prefix: "/auth",
|
||||||
authRoute.get(
|
|
||||||
"/user/:userId",
|
|
||||||
async ({ params: { userId } }) => await getUserData(userId),
|
|
||||||
{
|
|
||||||
detail: {
|
|
||||||
tags: ["Auth"],
|
tags: ["Auth"],
|
||||||
summary: "Get user data",
|
detail: {
|
||||||
},
|
description: "Routes for managing users",
|
||||||
params: t.Object({
|
|
||||||
userId: t.String(),
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
);
|
})
|
||||||
|
|
||||||
authRoute.post(
|
authRoute.get("/user/:userId", async ({ params: { userId } }) => await getUserData(userId), {
|
||||||
"/user/update/:userId",
|
|
||||||
async ({ params: { userId }, body }) => await updateUser(userId, body),
|
|
||||||
{
|
|
||||||
detail: {
|
|
||||||
tags: ["Auth"],
|
|
||||||
summary: "Update user",
|
|
||||||
},
|
|
||||||
params: t.Object({
|
params: t.Object({
|
||||||
userId: t.String(),
|
userId: t.String()
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
authRoute.post("/user/update/:userId", async ({ params: { userId }, body }) => await updateUser(userId, body), {
|
||||||
|
params: t.Object({
|
||||||
|
userId: t.String()
|
||||||
}),
|
}),
|
||||||
body: t.Object({
|
body: t.Object({
|
||||||
paid_status: t.String(),
|
paid_status: t.String(),
|
||||||
package_expire_date: t.String(),
|
package_expire_date: t.String(),
|
||||||
}),
|
})
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
authRoute.get(
|
authRoute.get("/generate-token/:userId", async (context) => await generateToken(context));
|
||||||
"/generate-token/:userId",
|
|
||||||
async (context) => await generateToken(context),
|
|
||||||
{
|
|
||||||
detail: {
|
|
||||||
tags: ["Auth"],
|
|
||||||
summary: "Generate token",
|
|
||||||
},
|
|
||||||
params: t.Object({
|
|
||||||
userId: t.String(),
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
authRoute.get(
|
authRoute.get("/user/me", async ({ cookie }) => {
|
||||||
"/user/me",
|
|
||||||
async ({ cookie }) => {
|
|
||||||
const authData = await verifyAuth(cookie);
|
const authData = await verifyAuth(cookie);
|
||||||
if (authData.status !== 200) {
|
if (authData.status !== 200) {
|
||||||
return authData;
|
return authData;
|
||||||
} else {
|
}
|
||||||
const userId = authData.userId;
|
else {
|
||||||
|
const userId: string | any = authData.userId;
|
||||||
const response = await getUserData(userId);
|
const response = await getUserData(userId);
|
||||||
if (response?.status === 200) {
|
if (response?.status === 200) {
|
||||||
return {
|
return { ...response.data, token: authData.token, status: 200, message: "User data fetched successfully" };
|
||||||
...response.data,
|
}
|
||||||
token: authData.token,
|
else {
|
||||||
status: 200,
|
|
||||||
message: "User data fetched successfully",
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
})
|
||||||
{
|
|
||||||
detail: {
|
|
||||||
tags: ["Auth"],
|
|
||||||
summary: "Get current user",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
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();
|
|
||||||
console.log(response);
|
|
||||||
return data;
|
|
||||||
} catch (error: any) {
|
|
||||||
console.log(error);
|
|
||||||
return { status: 500, message: error.message, token };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
@ -1,27 +1,16 @@
|
||||||
import { Elysia } from "elysia";
|
import Elysia from "elysia";
|
||||||
import { projectRoutes } from "./project/project.route";
|
import { projectRoutes } from "./project/project.route";
|
||||||
import { uploadRoutes } from "./upload/upload.route";
|
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 { designRoute } from "./design/design.route";
|
|
||||||
|
|
||||||
export const api = new Elysia({ prefix: "" })
|
export const api = new Elysia({
|
||||||
.get("/", () => {
|
prefix: "/api",
|
||||||
console.log("Root endpoint accessed");
|
});
|
||||||
|
api.get("/", () => {
|
||||||
return "Hello from PlanPostAI Canvas API";
|
return "Hello from PlanPostAI Canvas API";
|
||||||
})
|
});
|
||||||
.use(authRoute)
|
api.use(authRoute);
|
||||||
.use(projectRoutes)
|
api.use(projectRoutes);
|
||||||
.use(uploadRoutes)
|
api.use(uploadRoutes);
|
||||||
.use(downloadRoute)
|
api.use(downloadRoute);
|
||||||
.use(photoLibraryRoutes)
|
|
||||||
.use(designRoute)
|
|
||||||
.onError(({ code, error, set }) => {
|
|
||||||
console.error(`API Error: ${code}`, error);
|
|
||||||
if (code === "NOT_FOUND") {
|
|
||||||
set.status = 404;
|
|
||||||
return "API Endpoint Not Found";
|
|
||||||
}
|
|
||||||
return "API Error Occurred";
|
|
||||||
});
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
import { ENV } from "../../config/env";
|
|
||||||
|
|
||||||
export const getPhotos = async (keyword: string, pre_page: number, token: string) => {
|
|
||||||
try {
|
|
||||||
const url = `${ENV.PEXELS_URL}/search?query=${keyword}&per_page=${pre_page}`;
|
|
||||||
const response = await fetch(url, {
|
|
||||||
headers: {
|
|
||||||
Authorization: process.env.PEXELS_ACCESS_KEY as string,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
return { status: 500, message: "An error occurred while getting the photos", token }
|
|
||||||
}
|
|
||||||
const data = await response.json();
|
|
||||||
return { data, token }
|
|
||||||
} catch (error: any) {
|
|
||||||
console.log("Error in getting photos:", error.message || error.toString());
|
|
||||||
return { status: 500, message: "An error occurred while getting the photos", token };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
import Elysia, { t } from "elysia";
|
|
||||||
import { getPhotos } from "./photo.library.controller";
|
|
||||||
import { verifyAuth } from "../../middlewares/auth.middlewares";
|
|
||||||
|
|
||||||
export const photoLibraryRoutes = new Elysia({
|
|
||||||
prefix: "/photos",
|
|
||||||
tags: ["Photos"],
|
|
||||||
detail: {
|
|
||||||
description: "Routes for managing photo library",
|
|
||||||
}
|
|
||||||
}).derive(async ({ cookie }) => {
|
|
||||||
const authData = await verifyAuth(cookie);
|
|
||||||
return { authData }; // Inject into context
|
|
||||||
});
|
|
||||||
|
|
||||||
photoLibraryRoutes.get("/", async ({ query, authData
|
|
||||||
}) => {
|
|
||||||
if (authData.status !== 200)
|
|
||||||
return authData;
|
|
||||||
else {
|
|
||||||
const { keyword, per_page } = query;
|
|
||||||
const token = authData.token;
|
|
||||||
const data = await getPhotos(keyword, per_page, token);
|
|
||||||
return { data };
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
query: t.Object({
|
|
||||||
keyword: t.String(),
|
|
||||||
per_page: t.Number(),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
@ -8,26 +8,18 @@ import { removeBucket } from "../../helper/upload/removeBucket";
|
||||||
export const getAllProjects = async (userId: string, token: string) => {
|
export const getAllProjects = async (userId: string, token: string) => {
|
||||||
try {
|
try {
|
||||||
// Fetch all projects for the given user
|
// Fetch all projects for the given user
|
||||||
const allProjects = await db
|
const allProjects = await db.select({
|
||||||
.select({
|
|
||||||
id: projects.id,
|
id: projects.id,
|
||||||
name: projects.name,
|
name: projects.name,
|
||||||
description: projects.description,
|
description: projects.description,
|
||||||
preview_url: projects.preview_url,
|
preview_url: projects.preview_url,
|
||||||
object: projects.object,
|
object: projects.object,
|
||||||
})
|
}).from(projects).where(eq(projects.userId, userId));
|
||||||
.from(projects)
|
|
||||||
.where(eq(projects.userId, userId));
|
|
||||||
|
|
||||||
// Identify projects where 'object' is empty or 'object.objects' is empty
|
// Identify projects where 'object' is empty or 'object.objects' is empty
|
||||||
const projectsToDelete = allProjects.filter(
|
const projectsToDelete = allProjects.filter(proj =>
|
||||||
(proj) =>
|
(proj.object && typeof proj.object === "object" && Object.keys(proj.object).length === 0) ||
|
||||||
(proj.object &&
|
(proj.object?.objects && Array.isArray(proj.object.objects) && proj.object.objects.length === 0)
|
||||||
typeof proj.object === "object" &&
|
|
||||||
Object.keys(proj.object).length === 0) ||
|
|
||||||
(proj.object?.objects &&
|
|
||||||
Array.isArray(proj.object.objects) &&
|
|
||||||
proj.object.objects.length === 0)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Delete projects with empty 'object' or empty 'object.objects'
|
// Delete projects with empty 'object' or empty 'object.objects'
|
||||||
|
|
@ -45,15 +37,10 @@ export const getAllProjects = async (userId: string, token: string) => {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Get remaining projects
|
// Get remaining projects
|
||||||
const remainingProjects = allProjects.filter(
|
const remainingProjects = allProjects.filter(proj =>
|
||||||
(proj) =>
|
|
||||||
!(
|
!(
|
||||||
(proj.object &&
|
(proj.object && typeof proj.object === "object" && Object.keys(proj.object).length === 0) ||
|
||||||
typeof proj.object === "object" &&
|
(proj.object?.objects && Array.isArray(proj.object.objects) && proj.object.objects.length === 0)
|
||||||
Object.keys(proj.object).length === 0) ||
|
|
||||||
(proj.object?.objects &&
|
|
||||||
Array.isArray(proj.object.objects) &&
|
|
||||||
proj.object.objects.length === 0)
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -61,51 +48,29 @@ export const getAllProjects = async (userId: string, token: string) => {
|
||||||
return { status: 404, message: "No projects found", token };
|
return { status: 404, message: "No projects found", token };
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return { status: 200, message: "Projects fetched successfully", data: remainingProjects, token };
|
||||||
status: 200,
|
|
||||||
message: "Projects fetched successfully",
|
|
||||||
data: remainingProjects,
|
|
||||||
token,
|
|
||||||
};
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.log(error.message);
|
console.log(error.message);
|
||||||
return {
|
return { status: 500, message: "An error occurred while fetching projects", token };
|
||||||
status: 500,
|
|
||||||
message: "An error occurred while fetching projects",
|
|
||||||
token,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getEachProjects = async (id: string, token: string) => {
|
export const getEachProjects = async (id: string, token: string) => {
|
||||||
try {
|
try {
|
||||||
const project = await db
|
const project = await db.select({
|
||||||
.select({
|
|
||||||
id: projects.id,
|
id: projects.id,
|
||||||
name: projects.name,
|
name: projects.name,
|
||||||
description: projects.description,
|
description: projects.description,
|
||||||
preview_url: projects.preview_url,
|
preview_url: projects.preview_url,
|
||||||
object: projects.object,
|
object: projects.object,
|
||||||
})
|
}).from(projects).where(eq(projects.id, id)).limit(1);
|
||||||
.from(projects)
|
|
||||||
.where(eq(projects.id, id))
|
|
||||||
.limit(1);
|
|
||||||
if (project.length === 0) {
|
if (project.length === 0) {
|
||||||
return { status: 404, message: "Project not found", token };
|
return { status: 404, message: "Project not found", token };
|
||||||
}
|
}
|
||||||
return {
|
return { status: 200, message: "Project fetched successfully", data: project[0], token };
|
||||||
status: 200,
|
|
||||||
message: "Project fetched successfully",
|
|
||||||
data: project[0],
|
|
||||||
token,
|
|
||||||
};
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.log(error.message);
|
console.log(error.message);
|
||||||
return {
|
return { status: 500, message: "An error occurred while fetching projects", token };
|
||||||
status: 500,
|
|
||||||
message: "An error occurred while fetching projects",
|
|
||||||
token,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -113,34 +78,18 @@ export const createProject = async (userId: string, token: string) => {
|
||||||
try {
|
try {
|
||||||
const { id } = await createEmptyProject(userId);
|
const { id } = await createEmptyProject(userId);
|
||||||
const bucket = await createBucket(id);
|
const bucket = await createBucket(id);
|
||||||
return {
|
return { status: 200, message: "New project created successfully", data: { id, bucketName: bucket }, token };
|
||||||
status: 200,
|
|
||||||
message: "New project created successfully",
|
|
||||||
data: { id, bucketName: bucket },
|
|
||||||
token,
|
|
||||||
};
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.log(error.message);
|
console.log(error.message);
|
||||||
return {
|
return { status: 500, message: "An error occurred while creating projects", token }
|
||||||
status: 500,
|
|
||||||
message: "An error occurred while creating projects",
|
|
||||||
token,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateProject = async (
|
export const updateProject = async (id: string, body: any, token: string) => {
|
||||||
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
|
const existingProject = await db.select().from(projects).where(eq(projects.id, id)).limit(1);
|
||||||
.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 };
|
||||||
}
|
}
|
||||||
|
|
@ -148,40 +97,26 @@ export const updateProject = async (
|
||||||
const { object, name, description, preview_url } = body;
|
const { object, name, description, preview_url } = body;
|
||||||
// The preview_url will come from client-side as well, where before updating the project a project capture will be taken and uploaded to the bucket. than the url will be sent to the server.And rest of them are normal process
|
// The preview_url will come from client-side as well, where before updating the project a project capture will be taken and uploaded to the bucket. than the url will be sent to the server.And rest of them are normal process
|
||||||
|
|
||||||
const updatedProject = await db
|
const updatedProject = await db.update(projects).set({
|
||||||
.update(projects)
|
|
||||||
.set({
|
|
||||||
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,
|
||||||
name: projects.name,
|
name: projects.name,
|
||||||
description: projects.description,
|
description: projects.description,
|
||||||
preview_url: projects.preview_url,
|
preview_url: projects.preview_url
|
||||||
});
|
});
|
||||||
|
|
||||||
if (updatedProject.length === 0) {
|
if (updatedProject.length === 0) {
|
||||||
return { status: 500, message: "Failed to update the project", token };
|
return { status: 500, message: "Failed to update the project", token };
|
||||||
}
|
}
|
||||||
return {
|
return { status: 200, message: "Project updated successfully", data: updatedProject[0], token };
|
||||||
status: 200,
|
|
||||||
message: "Project updated successfully",
|
|
||||||
data: updatedProject[0],
|
|
||||||
token,
|
|
||||||
};
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.log("Error updating project:", error.message || error.toString());
|
console.log("Error updating project:", error.message || error.toString());
|
||||||
return {
|
return { status: 500, message: "An error occurred while updating the project", token };
|
||||||
status: 500,
|
|
||||||
message: "An error occurred while updating the project",
|
|
||||||
token,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -210,21 +145,16 @@ export const deleteProject = async (id: string, token: string) => {
|
||||||
return {
|
return {
|
||||||
status: bucketDeletionResult.status,
|
status: bucketDeletionResult.status,
|
||||||
message: `Error deleting bucket: ${bucketDeletionResult.message}`,
|
message: `Error deleting bucket: ${bucketDeletionResult.message}`,
|
||||||
token,
|
token
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {
|
return { status: 200, message: "Project and associated bucket deleted successfully", token };
|
||||||
status: 200,
|
|
||||||
message: "Project and associated bucket deleted successfully",
|
|
||||||
token,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.log("Error in deleteProject:", error.message || error.toString());
|
console.log("Error in deleteProject:", error.message || error.toString());
|
||||||
return {
|
return { status: 500, message: "An error occurred while deleting the project", token };
|
||||||
status: 500,
|
|
||||||
message: "An error occurred while deleting the project",
|
|
||||||
token,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,5 @@
|
||||||
import { Elysia, t } from "elysia";
|
import { Elysia, t } from "elysia";
|
||||||
import {
|
import { createProject, deleteProject, getAllProjects, getEachProjects, updateProject } from "./project.controller";
|
||||||
createProject,
|
|
||||||
deleteProject,
|
|
||||||
getAllProjects,
|
|
||||||
getEachProjects,
|
|
||||||
updateProject,
|
|
||||||
} from "./project.controller";
|
|
||||||
import { verifyAuth } from "../../middlewares/auth.middlewares";
|
import { verifyAuth } from "../../middlewares/auth.middlewares";
|
||||||
|
|
||||||
export const projectRoutes = new Elysia({
|
export const projectRoutes = new Elysia({
|
||||||
|
|
@ -13,31 +7,29 @@ export const projectRoutes = new Elysia({
|
||||||
tags: ["Projects"],
|
tags: ["Projects"],
|
||||||
detail: {
|
detail: {
|
||||||
description: "Routes for managing projects",
|
description: "Routes for managing projects",
|
||||||
},
|
}
|
||||||
}).derive(async ({ cookie }) => {
|
}).derive(async ({ cookie }) => {
|
||||||
const authData = await verifyAuth(cookie);
|
const authData = await verifyAuth(cookie);
|
||||||
return { authData }; // Inject into context
|
return { authData }; // Inject into context
|
||||||
});
|
});
|
||||||
|
|
||||||
projectRoutes.get(
|
projectRoutes.get("/each/:project_id", async ({ params: { project_id }, authData }) => {
|
||||||
"/each/:project_id",
|
if (authData.status !== 200)
|
||||||
async ({ params: { project_id }, authData }) => {
|
return authData;
|
||||||
if (authData.status !== 200) return authData;
|
|
||||||
else {
|
else {
|
||||||
const token = authData.token;
|
const token = authData.token;
|
||||||
const response = await getEachProjects(project_id, token);
|
const response = await getEachProjects(project_id, token);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
},
|
}, {
|
||||||
{
|
|
||||||
params: t.Object({
|
params: t.Object({
|
||||||
project_id: t.String(),
|
project_id: t.String()
|
||||||
}),
|
})
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
projectRoutes.get("/", async ({ authData }: any) => {
|
projectRoutes.get("/", async ({ authData }: any) => {
|
||||||
if (authData.status !== 200) return authData;
|
if (authData.status !== 200)
|
||||||
|
return authData;
|
||||||
else {
|
else {
|
||||||
const userId = authData.userId;
|
const userId = authData.userId;
|
||||||
const token = authData.token;
|
const token = authData.token;
|
||||||
|
|
@ -47,7 +39,8 @@ projectRoutes.get("/", async ({ authData }: any) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
projectRoutes.post("/create", async ({ authData }: any) => {
|
projectRoutes.post("/create", async ({ authData }: any) => {
|
||||||
if (authData.status !== 200) return authData;
|
if (authData.status !== 200)
|
||||||
|
return authData;
|
||||||
else {
|
else {
|
||||||
const userId = authData.userId;
|
const userId = authData.userId;
|
||||||
const token = authData.token;
|
const token = authData.token;
|
||||||
|
|
@ -56,49 +49,37 @@ projectRoutes.post("/create", async ({ authData }: any) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
projectRoutes.put(
|
projectRoutes.put("/update/:project_id", async ({ body, params: { project_id }, authData }) => {
|
||||||
"/update/:project_id",
|
if (authData.status !== 200)
|
||||||
async ({ body, params: { project_id }, authData }) => {
|
return authData;
|
||||||
if (authData.status !== 200) return authData;
|
|
||||||
else {
|
else {
|
||||||
const token = authData.token;
|
const token = authData.token;
|
||||||
const user_id = authData?.userId;
|
const response = await updateProject(project_id, body, token);
|
||||||
// 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;
|
||||||
}
|
}
|
||||||
},
|
}, {
|
||||||
{
|
|
||||||
params: t.Object({
|
params: t.Object({
|
||||||
project_id: t.String(),
|
project_id: t.String()
|
||||||
}),
|
}),
|
||||||
body: t.Object({
|
body: t.Object({
|
||||||
object: t.Record(t.String(), t.Any()), // Allows any JSON object
|
object: t.Record(t.String(), t.Any()), // Allows any JSON object
|
||||||
name: t.String(),
|
name: t.String(),
|
||||||
description: t.String(),
|
description: t.String(),
|
||||||
preview_url: t.String(),
|
preview_url: t.String(),
|
||||||
}),
|
})
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
projectRoutes.delete(
|
projectRoutes.delete("/delete/:project_id", async ({ params: { project_id }, authData }) => {
|
||||||
"/delete/:project_id",
|
if (authData.status !== 200)
|
||||||
async ({ params: { project_id }, authData }) => {
|
return authData;
|
||||||
if (authData.status !== 200) return authData;
|
|
||||||
else {
|
else {
|
||||||
const token = authData.token;
|
const token = authData.token;
|
||||||
const response = await deleteProject(project_id, token);
|
const response = await deleteProject(project_id, token);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
},
|
}, {
|
||||||
{
|
|
||||||
params: t.Object({
|
params: t.Object({
|
||||||
project_id: t.String(),
|
project_id: t.String()
|
||||||
}),
|
})
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
|
||||||
77
src/app.ts
77
src/app.ts
|
|
@ -1,52 +1,59 @@
|
||||||
import { Elysia, t } from "elysia";
|
import { Elysia } from "elysia";
|
||||||
import swagger from "@elysiajs/swagger";
|
import swagger from '@elysiajs/swagger';
|
||||||
import cors from "@elysiajs/cors";
|
|
||||||
import { ENV } from "./config/env";
|
import { ENV } from "./config/env";
|
||||||
|
import cors from "@elysiajs/cors";
|
||||||
import { api } from "./api";
|
import { api } from "./api";
|
||||||
|
|
||||||
const app = new Elysia()
|
const allowedOrigins = [
|
||||||
.use(
|
|
||||||
cors({
|
|
||||||
origin: [
|
|
||||||
"http://localhost:5175",
|
"http://localhost:5175",
|
||||||
"http://localhost:5174",
|
"http://localhost:5173",
|
||||||
"https://dashboard.planpostai.com",
|
"https://dashboard.planpostai.com",
|
||||||
"https://dev.dashboard.planpostai.com",
|
|
||||||
"https://canvas.planpostai.com",
|
"https://canvas.planpostai.com",
|
||||||
"https://canvasdev.planpostai.com",
|
];
|
||||||
],
|
|
||||||
|
const app = new Elysia({
|
||||||
|
prefix: "",
|
||||||
|
tags: ["Default"],
|
||||||
|
})
|
||||||
|
.use(cors({
|
||||||
|
origin: allowedOrigins,
|
||||||
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"],
|
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"],
|
||||||
allowedHeaders: [
|
allowedHeaders: ["Content-Type", "Authorization", "X-Requested-With", "Accept", "Origin", "Access-Control-Allow-Origin"],
|
||||||
"Content-Type",
|
|
||||||
"Authorization",
|
|
||||||
"X-Requested-With",
|
|
||||||
"Accept",
|
|
||||||
"Origin",
|
|
||||||
"Access-Control-Allow-Origin",
|
|
||||||
],
|
|
||||||
credentials: true,
|
credentials: true,
|
||||||
})
|
}))
|
||||||
)
|
.use(swagger({
|
||||||
.get("/test", () => "Hello World", {})
|
path: "/api/docs",
|
||||||
.use(api)
|
|
||||||
.use(
|
|
||||||
swagger({
|
|
||||||
path: "/swagger",
|
|
||||||
documentation: {
|
documentation: {
|
||||||
openapi: "3.1.0",
|
|
||||||
info: {
|
info: {
|
||||||
title: "Canvas API",
|
title: "Canvas API",
|
||||||
version: "1.0.0",
|
version: "1.0.0",
|
||||||
description: "Canvas API Documentation",
|
description: "Canvas API Documentation",
|
||||||
},
|
},
|
||||||
|
tags: [
|
||||||
|
{
|
||||||
|
name: "Projects",
|
||||||
|
description: "All APIs related to Projects",
|
||||||
},
|
},
|
||||||
})
|
{
|
||||||
)
|
name: "Uploads",
|
||||||
.listen(ENV.SERVER_PORT);
|
description: "All APIs related to Uploads"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
.onError(({ code, error }) => {
|
||||||
|
if (code === 'NOT_FOUND')
|
||||||
|
return 'Not Found :(';
|
||||||
|
console.log("hello from app.ts under error");
|
||||||
|
console.error(error)
|
||||||
|
});
|
||||||
|
|
||||||
|
// all routes here
|
||||||
|
app.use(api);
|
||||||
|
|
||||||
|
app.listen(ENV.SERVER_PORT, () => {
|
||||||
|
console.log(`🦊 Elysia is running at ${ENV.SERVER_URL}:${ENV.SERVER_PORT}`)
|
||||||
|
})
|
||||||
|
|
||||||
app.routes.forEach((route) => {
|
|
||||||
console.log(`Route: ${route.method} ${route.path}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(`🦊 Elysia is running at ${ENV.SERVER_URL}`);
|
|
||||||
console.log(`Swagger docs available at ${ENV.SERVER_URL}/swagger`);
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,14 @@
|
||||||
import "dotenv/config";
|
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,
|
||||||
MINIO_ENDPOINT: process.env.MINIO_URL,
|
MINIO_ENDPOINT: process.env.MINIO_ENDPOINT,
|
||||||
MINIO_PORT: process.env.MINIO_PORT,
|
MINIO_PORT: process.env.MINIO_PORT,
|
||||||
CLERK_SECRET_KEY: process.env.CLERK_SECRET_KEY,
|
CLERK_SECRET_KEY: process.env.CLERK_SECRET_KEY,
|
||||||
JWT_ACCESS_TOKEN_SECRET: process.env.JWT_ACCESS_TOKEN_SECRET,
|
JWT_ACCESS_TOKEN_SECRET: process.env.JWT_ACCESS_TOKEN_SECRET,
|
||||||
JWT_REFRESH_TOKEN_SECRET: process.env.JWT_REFRESH_TOKEN_SECRET,
|
JWT_REFRESH_TOKEN_SECRET: process.env.JWT_REFRESH_TOKEN_SECRET,
|
||||||
PEXELS_URL: process.env.PEXELS_URL,
|
}
|
||||||
PEXELS_ACCESS_KEY: process.env.PEXELS_ACCESS_KEY,
|
|
||||||
};
|
|
||||||
|
|
@ -3,7 +3,8 @@ import { ENV } from "../config/env";
|
||||||
|
|
||||||
export const minioClient = new Client({
|
export const minioClient = new Client({
|
||||||
endPoint: ENV.MINIO_ENDPOINT!.replace("http://", "").replace("https://", ""),
|
endPoint: ENV.MINIO_ENDPOINT!.replace("http://", "").replace("https://", ""),
|
||||||
useSSL: ENV.MINIO_ENDPOINT!.startsWith("https"),
|
port: ENV.MINIO_PORT,
|
||||||
|
useSSL: false,
|
||||||
accessKey: ENV.MINIO_ACCESS_KEY,
|
accessKey: ENV.MINIO_ACCESS_KEY,
|
||||||
secretKey: ENV.MINIO_SECRET_KEY,
|
secretKey: ENV.MINIO_SECRET_KEY,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,4 @@
|
||||||
import {
|
import { boolean, integer, json, pgTable, text, timestamp, uuid, jsonb } from "drizzle-orm/pg-core";
|
||||||
boolean,
|
|
||||||
integer,
|
|
||||||
json,
|
|
||||||
pgTable,
|
|
||||||
text,
|
|
||||||
timestamp,
|
|
||||||
uuid,
|
|
||||||
jsonb,
|
|
||||||
} from "drizzle-orm/pg-core";
|
|
||||||
|
|
||||||
export const users = pgTable("users", {
|
export const users = pgTable("users", {
|
||||||
id: text("user_id").primaryKey().notNull(),
|
id: text("user_id").primaryKey().notNull(),
|
||||||
|
|
@ -42,18 +33,3 @@ export const uploads = pgTable("uploads", {
|
||||||
created_at: timestamp("created_at").defaultNow(),
|
created_at: timestamp("created_at").defaultNow(),
|
||||||
updated_at: timestamp("updated_at").defaultNow(),
|
updated_at: timestamp("updated_at").defaultNow(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const shapes = pgTable("shapes", {
|
|
||||||
id: uuid("shape_id").defaultRandom().primaryKey(),
|
|
||||||
shapes: text("shapes").notNull(),
|
|
||||||
created_at: timestamp("created_at").defaultNow(),
|
|
||||||
updated_at: timestamp("updated_at").defaultNow(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const category = pgTable("project_category", {
|
|
||||||
id: uuid("category_id").defaultRandom().primaryKey(),
|
|
||||||
user_id: uuid().references(() => users.id),
|
|
||||||
category: text("category").notNull(),
|
|
||||||
created_at: timestamp("created_at").defaultNow(),
|
|
||||||
updated_at: timestamp("updated_at").defaultNow(),
|
|
||||||
});
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue