mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 18:33:01 +00:00
createOrganisationWithOwner
This commit is contained in:
@@ -30,6 +30,36 @@ export async function createOrganisationMember(
|
|||||||
return member;
|
return member;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function createOrganisationWithOwner(
|
||||||
|
name: string,
|
||||||
|
slug: string,
|
||||||
|
userId: number,
|
||||||
|
description?: string,
|
||||||
|
) {
|
||||||
|
return await db.transaction(async (tx) => {
|
||||||
|
const [org] = await tx
|
||||||
|
.insert(Organisation)
|
||||||
|
.values({
|
||||||
|
name,
|
||||||
|
slug,
|
||||||
|
description,
|
||||||
|
})
|
||||||
|
.returning();
|
||||||
|
|
||||||
|
if (!org) {
|
||||||
|
throw new Error("failed to create organisation");
|
||||||
|
}
|
||||||
|
|
||||||
|
await tx.insert(OrganisationMember).values({
|
||||||
|
organisationId: org.id,
|
||||||
|
userId,
|
||||||
|
role: "owner",
|
||||||
|
});
|
||||||
|
|
||||||
|
return org;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export async function getOrganisationById(id: number) {
|
export async function getOrganisationById(id: number) {
|
||||||
const [organisation] = await db.select().from(Organisation).where(eq(Organisation.id, id));
|
const [organisation] = await db.select().from(Organisation).where(eq(Organisation.id, id));
|
||||||
return organisation;
|
return organisation;
|
||||||
|
|||||||
Reference in New Issue
Block a user