Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix how we store Musician Groups #90

Merged
merged 7 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we need to update this data on creation/update of its user (in case the wrong data is inputted), or is this more of a one time use data for registration?

Copy link
Member

@sanjana-singhania sanjana-singhania Jan 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's the former, where we want to display updated data in the admin dashboard so that the admin can view the updated information for group members, we may need to make a table to associate MusicianGroupMember with User.

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
Loading