Skip to content

Commit

Permalink
Fix how we store Musician Groups (#90)
Browse files Browse the repository at this point in the history
* first pass

* maybe fix tests

* fix tests maybe

* fix schema

* format

* remvoe role from group member

* remove unces todo
  • Loading branch information
owens1127 authored Jan 26, 2025
1 parent 34bd366 commit da0bc3a
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 69 deletions.
14 changes: 0 additions & 14 deletions packages/components/src/admin/AdminDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default function AdminDashboard() {

const userData = data.users;
const groupData = data.groups;
const groupInvitesData = data.groupInvites;

return (
<div className="bg-good-dog-violet pb-10">
Expand Down Expand Up @@ -65,19 +64,6 @@ export default function AdminDashboard() {
</CardContent>
</Card>
</TabsContent>
<TabsContent className="text-3xl" value="invites">
<Card>
<CardHeader>
<CardTitle>Invites</CardTitle>
<CardDescription className="text-xl">
Manage pending invitations.
</CardDescription>
</CardHeader>
<CardContent>
<DataTable table="groupInvites" data={groupInvitesData} />
</CardContent>
</Card>
</TabsContent>
</div>
</Tabs>
</div>
Expand Down
11 changes: 0 additions & 11 deletions packages/components/src/admin/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,6 @@ const columns: { [T in keyof AdminDataTypes]: DataColumn<T>[] } = {
{ accessorKey: "createdAt", header: "Date of Creation" },
{ accessorKey: "updatedAt", header: "Date Last Updated" },
],
groupInvites: [
{ accessorKey: "email", header: "Email" },
{ accessorKey: "firstName", header: "First Name" },
{ accessorKey: "lastName", header: "Last Name" },
{ accessorKey: "stageName", header: "Stage Name" },
{ accessorKey: "role", header: "Role" },
{ accessorKey: "isSongWriter", header: "Songwriter?" },
{ accessorKey: "isAscapAffiliated", header: "ASCAP Affiliated?" },
{ accessorKey: "isBmiAffiliated", header: "BMI Affiliated?" },
{ accessorKey: "createdAt", header: "Date of Creation" },
],
};

interface DataTableProps<T extends keyof AdminDataTypes> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
Warnings:
- You are about to drop the `Group` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `GroupInvite` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `_GroupToUser` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropForeignKey
ALTER TABLE "GroupInvite" DROP CONSTRAINT "GroupInvite_groupId_fkey";

-- DropForeignKey
ALTER TABLE "GroupInvite" DROP CONSTRAINT "GroupInvite_initiatorId_fkey";

-- DropForeignKey
ALTER TABLE "_GroupToUser" DROP CONSTRAINT "_GroupToUser_A_fkey";

-- DropForeignKey
ALTER TABLE "_GroupToUser" DROP CONSTRAINT "_GroupToUser_B_fkey";

-- DropTable
DROP TABLE "Group";

-- DropTable
DROP TABLE "GroupInvite";

-- DropTable
DROP TABLE "_GroupToUser";

-- CreateTable
CREATE TABLE "MusicianGroup" (
"groupId" TEXT NOT NULL,
"organizerId" TEXT NOT NULL,
"name" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

CONSTRAINT "MusicianGroup_pkey" PRIMARY KEY ("groupId")
);

-- CreateTable
CREATE TABLE "MusicianGroupMember" (
"groupId" TEXT NOT NULL,
"firstName" TEXT NOT NULL,
"lastName" TEXT NOT NULL,
"stageName" TEXT,
"email" TEXT NOT NULL,
"isSongWriter" BOOLEAN NOT NULL DEFAULT false,
"isAscapAffiliated" BOOLEAN NOT NULL DEFAULT false,
"isBmiAffiliated" BOOLEAN NOT NULL DEFAULT false,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL
);

-- CreateIndex
CREATE UNIQUE INDEX "MusicianGroupMember_groupId_email_key" ON "MusicianGroupMember"("groupId", "email");

-- AddForeignKey
ALTER TABLE "MusicianGroup" ADD CONSTRAINT "MusicianGroup_organizerId_fkey" FOREIGN KEY ("organizerId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MusicianGroupMember" ADD CONSTRAINT "MusicianGroupMember_groupId_fkey" FOREIGN KEY ("groupId") REFERENCES "MusicianGroup"("groupId") ON DELETE CASCADE ON UPDATE CASCADE;
57 changes: 27 additions & 30 deletions packages/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ model User {
isSongWriter Boolean @default(false)
isAscapAffiliated Boolean @default(false)
isBmiAffiliated Boolean @default(false)
groups Group[]
musicianGroups MusicianGroup[]
passwordResetReq PasswordResetReq?
sessions Session[]
sentInvites GroupInvite[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
Expand All @@ -49,34 +48,6 @@ model Session {
user User @relation(fields: [userId], references: [userId], onDelete: Cascade)
}

model Group {
groupId String @id @default(uuid())
name String
users User[]
invites GroupInvite[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

model GroupInvite {
inviteId String @default(cuid()) @map("id")
groupId String
initiatorId String
email String
firstName String
lastName String
stageName String?
role Role
isSongWriter Boolean @default(false)
isAscapAffiliated Boolean @default(false)
isBmiAffiliated Boolean @default(false)
group Group @relation(fields: [groupId], references: [groupId], onDelete: Cascade)
intitiator User @relation(fields: [initiatorId], references: [userId], onDelete: Cascade)
createdAt DateTime @default(now())
@@unique([groupId, email])
}

model EmailVerificationCode {
email String @id
code String
Expand All @@ -92,3 +63,29 @@ model PasswordResetReq {
createdAt DateTime @default(now())
expiresAt DateTime
}

model MusicianGroup {
groupId String @id @default(uuid())
organizerId String // The user that created the group
organizer User @relation(fields: [organizerId], references: [userId], onDelete: Cascade)
name String
groupMembers MusicianGroupMember[] // Does not contain the user that created the group
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

model MusicianGroupMember {
groupId String
group MusicianGroup @relation(fields: [groupId], references: [groupId], onDelete: Cascade)
firstName String
lastName String
stageName String?
email String
isSongWriter Boolean @default(false)
isAscapAffiliated Boolean @default(false)
isBmiAffiliated Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([groupId, email])
}
12 changes: 8 additions & 4 deletions packages/trpc/src/procedures/admin-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import { adminAuthenticatedProcedureBuilder } from "../internal/init";

export const getAdminViewProcedure = adminAuthenticatedProcedureBuilder.query(
async ({ ctx }) => {
const [users, groups, groupInvites] = await Promise.all([
const [users, groups] = await Promise.all([
ctx.prisma.user.findMany({ omit: { hashedPassword: true } }),
ctx.prisma.group.findMany(),
ctx.prisma.groupInvite.findMany(),
ctx.prisma.musicianGroup.findMany({
include: {
organizer: true,
groupMembers: true,
},
}),
]);
return { users, groups, groupInvites };
return { users, groups };
},
);
7 changes: 2 additions & 5 deletions packages/trpc/src/procedures/onboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export const onboardingProcedure = authenticatedProcedureBuilder
},
});
} else {
// TODO: Actually send the group invites
await ctx.prisma.user.update({
data: {
role: "MUSICIAN",
Expand All @@ -70,22 +69,20 @@ export const onboardingProcedure = authenticatedProcedureBuilder
isSongWriter: input.isSongWriter,
isAscapAffiliated: input.isAscapAffiliated,
isBmiAffiliated: input.isBmiAffiliated,
groups: {
musicianGroups: {
create: {
name: input.groupName,
invites: {
groupMembers: {
createMany: {
data:
input.groupMembers?.map((member) => ({
initiatorId: ctx.session.userId,
email: member.email,
firstName: member.firstName,
lastName: member.lastName,
stageName: member.stageName,
isSongWriter: member.isSongWriter,
isAscapAffiliated: member.isAscapAffiliated,
isBmiAffiliated: member.isBmiAffiliated,
role: "MUSICIAN",
})) ?? [],
},
},
Expand Down
10 changes: 5 additions & 5 deletions tests/api/onboarding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe("get user", () => {
},
},
}),
prisma.group.deleteMany({
prisma.musicianGroup.deleteMany({
where: {
name: "Owen's Group",
},
Expand Down Expand Up @@ -136,18 +136,18 @@ describe("get user", () => {
expect(response.message).toEqual("Successfully onboarded");
expect(mockCache.revalidatePath).toHaveBeenCalledWith("/onboarding");

const group = await prisma.group.findFirst({
const group = await prisma.musicianGroup.findFirst({
where: {
name: "Owen's Group",
},
include: {
invites: true,
groupMembers: true,
},
});

expect(group).not.toBeNull();
expect(group?.invites).toHaveLength(1);
expect(group?.invites[0]?.email).toEqual("[email protected]");
expect(group?.groupMembers).toHaveLength(1);
expect(group?.groupMembers[0]?.email).toEqual("[email protected]");
});

test("Onboards media maker", async () => {
Expand Down

0 comments on commit da0bc3a

Please sign in to comment.