mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 18:33:01 +00:00
all fixes for Project.creatorId and Organisation tables
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
export * from "./users";
|
||||
export * from "./projects";
|
||||
export * from "./issues";
|
||||
export * from "./organisations";
|
||||
export * from "./projects";
|
||||
export * from "./users";
|
||||
|
||||
45
packages/backend/src/db/queries/organisations.ts
Normal file
45
packages/backend/src/db/queries/organisations.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { Organisation, OrganisationMember } from "@issue/shared";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../client";
|
||||
|
||||
export async function createOrganisation(name: string, slug: string, description?: string) {
|
||||
const [organisation] = await db
|
||||
.insert(Organisation)
|
||||
.values({
|
||||
name,
|
||||
slug,
|
||||
description,
|
||||
})
|
||||
.returning();
|
||||
return organisation;
|
||||
}
|
||||
|
||||
export async function createOrganisationMember(
|
||||
organisationId: number,
|
||||
userId: number,
|
||||
role: string = "member",
|
||||
) {
|
||||
const [member] = await db
|
||||
.insert(OrganisationMember)
|
||||
.values({
|
||||
organisationId,
|
||||
userId,
|
||||
role,
|
||||
})
|
||||
.returning();
|
||||
return member;
|
||||
}
|
||||
|
||||
export async function getOrganisationById(id: number) {
|
||||
const [organisation] = await db.select().from(Organisation).where(eq(Organisation.id, id));
|
||||
return organisation;
|
||||
}
|
||||
|
||||
export async function getOrganisationsByUserId(userId: number) {
|
||||
const organisations = await db
|
||||
.select()
|
||||
.from(OrganisationMember)
|
||||
.where(eq(OrganisationMember.userId, userId))
|
||||
.innerJoin(Organisation, eq(OrganisationMember.organisationId, Organisation.id));
|
||||
return organisations;
|
||||
}
|
||||
@@ -2,13 +2,14 @@ import { Issue, Project, User } from "@issue/shared";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../client";
|
||||
|
||||
export async function createProject(blob: string, name: string, ownerId: number) {
|
||||
export async function createProject(blob: string, name: string, creatorId: number, organisationId: number) {
|
||||
const [project] = await db
|
||||
.insert(Project)
|
||||
.values({
|
||||
blob,
|
||||
name,
|
||||
ownerId,
|
||||
creatorId,
|
||||
organisationId,
|
||||
})
|
||||
.returning();
|
||||
return project;
|
||||
@@ -16,7 +17,7 @@ export async function createProject(blob: string, name: string, ownerId: number)
|
||||
|
||||
export async function updateProject(
|
||||
projectId: number,
|
||||
updates: { blob?: string; name?: string; ownerId?: number },
|
||||
updates: { blob?: string; name?: string; creatorId?: number; organisationId?: number },
|
||||
) {
|
||||
const [project] = await db.update(Project).set(updates).where(eq(Project.id, projectId)).returning();
|
||||
return project;
|
||||
@@ -39,13 +40,13 @@ export async function getProjectByBlob(projectBlob: string) {
|
||||
return project;
|
||||
}
|
||||
|
||||
export async function getProjectsByOwnerID(ownerId: number) {
|
||||
const projectsWithOwners = await db
|
||||
export async function getProjectsByCreatorID(creatorId: number) {
|
||||
const projectsWithCreators = await db
|
||||
.select()
|
||||
.from(Project)
|
||||
.where(eq(Project.ownerId, ownerId))
|
||||
.leftJoin(User, eq(Project.ownerId, User.id));
|
||||
return projectsWithOwners;
|
||||
.where(eq(Project.creatorId, creatorId))
|
||||
.leftJoin(User, eq(Project.creatorId, User.id));
|
||||
return projectsWithCreators;
|
||||
}
|
||||
|
||||
export async function getAllProjects() {
|
||||
@@ -53,16 +54,19 @@ export async function getAllProjects() {
|
||||
return projects;
|
||||
}
|
||||
|
||||
export async function getProjectsWithOwners() {
|
||||
const projectsWithOwners = await db.select().from(Project).leftJoin(User, eq(Project.ownerId, User.id));
|
||||
return projectsWithOwners;
|
||||
}
|
||||
|
||||
export async function getProjectWithOwnerByID(projectId: number) {
|
||||
const [projectWithOwner] = await db
|
||||
export async function getProjectsWithCreators() {
|
||||
const projectsWithCreators = await db
|
||||
.select()
|
||||
.from(Project)
|
||||
.leftJoin(User, eq(Project.ownerId, User.id))
|
||||
.where(eq(Project.id, projectId));
|
||||
return projectWithOwner;
|
||||
.leftJoin(User, eq(Project.creatorId, User.id));
|
||||
return projectsWithCreators;
|
||||
}
|
||||
|
||||
export async function getProjectWithCreatorByID(projectId: number) {
|
||||
const [projectWithCreator] = await db
|
||||
.select()
|
||||
.from(Project)
|
||||
.leftJoin(User, eq(Project.creatorId, User.id))
|
||||
.where(eq(Project.id, projectId));
|
||||
return projectWithCreator;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user