feat: added projectLabel schema and service function

This commit is contained in:
Henit Chobisa
2023-12-20 11:47:50 +05:30
parent 6b9a1672c2
commit eff68b8cd6
2 changed files with 50 additions and 1 deletions

View File

@@ -105,6 +105,32 @@ export const projectMembers = pgTable("project_members", {
isActive: boolean("is_active"),
});
export const projectLabels = pgTable("labels", {
id: uuid("id").primaryKey(),
name: text("name"),
description: text("description"),
projectId: uuid("project_id"),
workspaceId: uuid("workspace_id"),
parentId: uuid("parent_id"),
color: text("color"),
sortOrder: integer("sort_order"),
});
export const projectlabelsRelations = relations(projectLabels, ({ one }) => ({
project: one(projects, {
fields: [projectLabels.projectId],
references: [projects.id],
}),
workspace: one(workspaces, {
fields: [projectLabels.workspaceId],
references: [workspaces.id],
}),
parent: one(projectLabels, {
fields: [projectLabels.parentId],
references: [projectLabels.id],
}),
}));
export const projectMembersRelations = relations(projectMembers, ({ one }) => ({
project: one(projects, {
fields: [projectMembers.projectId],

View File

@@ -1,6 +1,11 @@
import { eq, sql } from "drizzle-orm";
import { DatabaseSingleton } from "../db/singleton";
import { projectMembers, projects, states } from "../db/slack.schema";
import {
projectLabels,
projectMembers,
projects,
states,
} from "../db/slack.schema";
export class ProjectService {
async getProjectsForWorkspace(workspaceId: string) {
@@ -49,4 +54,22 @@ export class ProjectService {
throw new Error("Database not found");
}
}
async getProjectLabels(projectId: string) {
const db = DatabaseSingleton.getInstance().db;
if (!db) {
throw new Error("Database not found");
}
try {
const labels = await db.query.projectLabels.findMany({
where: eq(projectLabels.projectId, projectId),
});
return labels;
} catch (error) {
throw new Error("Database not found");
}
}
}