Skip to content

Commit

Permalink
Removed userMetadataToClubs title dependencies; added db migration
Browse files Browse the repository at this point in the history
  • Loading branch information
BK2004 committed Oct 23, 2024
1 parent c4a9da0 commit 5529a6e
Show file tree
Hide file tree
Showing 7 changed files with 872 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/app/manage/[clubId]/edit/officers/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default async function Page({
name: officer.userMetadata.firstName + ' ' + officer.userMetadata.lastName,
locked: officer.memberType == 'President' || role == 'Officer',
position: officer.memberType as 'President' | 'Officer',
title: officer.title as string,
title: "", // TODO: link from officers table
}));

return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/club/listing/ClubInfoSegment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const ClubInfoSegment: FC<{
officer.userMetadata.lastName}
</p>
<p className="mt-2 text-sm text-slate-400">
{officer.title ?? 'Officer'}
Officer {/* TODO: link to officers table */}
</p>
</div>
</div>
Expand Down
33 changes: 17 additions & 16 deletions src/server/api/routers/clubEdit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { db } from '@src/server/db';

Check failure on line 1 in src/server/api/routers/clubEdit.ts

View workflow job for this annotation

GitHub Actions / check-formatting

src/server/api/routers/clubEdit.ts not formatted correctly
import { createTRPCRouter, protectedProcedure } from '../trpc';
import { and, eq, inArray, sql } from 'drizzle-orm';
import { and, eq, inArray } from 'drizzle-orm';
import { editClubSchema } from '@src/utils/formSchemas';
import { TRPCError } from '@trpc/server';
import { z } from 'zod';
Expand Down Expand Up @@ -136,20 +136,21 @@ export const clubEditRouter = createTRPCRouter({
),
);
}
const promises: Promise<unknown>[] = [];
for (const modded of input.modified) {
const prom = ctx.db
.update(userMetadataToClubs)
.set({ title: modded.title })
.where(
and(
eq(userMetadataToClubs.userId, modded.userId),
eq(userMetadataToClubs.clubId, input.clubId),
),
);
promises.push(prom);
}
await Promise.allSettled(promises);
// TODO: link to officers table
// const promises: Promise<unknown>[] = [];
// for (const modded of input.modified) {
// const prom = ctx.db
// .update(userMetadataToClubs)
// .set({ title: modded.title })
// .where(
// and(
// eq(userMetadataToClubs.userId, modded.userId),
// eq(userMetadataToClubs.clubId, input.clubId),
// ),
// );
// promises.push(prom);
// }
// await Promise.allSettled(promises);
if (input.created.length === 0) return;

await ctx.db
Expand All @@ -164,7 +165,7 @@ export const clubEditRouter = createTRPCRouter({
)
.onConflictDoUpdate({
target: [userMetadataToClubs.userId, userMetadataToClubs.clubId],
set: { memberType: 'Officer' as const, title: sql`excluded.title` },
set: { memberType: 'Officer' as const},
where: eq(userMetadataToClubs.memberType, 'Member'),
});
}),
Expand Down
16 changes: 16 additions & 0 deletions src/server/db/migrations/0008_military_mole_man.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CREATE TABLE IF NOT EXISTS "officers" (
"id" text NOT NULL,
"club_id" text NOT NULL,
"name" text NOT NULL,
"position" text NOT NULL,
"image" text DEFAULT '/nebula-logo.png' NOT NULL,
"is_president" boolean DEFAULT false NOT NULL,
CONSTRAINT officers_club_id_id PRIMARY KEY("club_id","id")
);
--> statement-breakpoint
ALTER TABLE "user_metadata_to_clubs" DROP COLUMN IF EXISTS "title";--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "officers" ADD CONSTRAINT "officers_club_id_club_id_fk" FOREIGN KEY ("club_id") REFERENCES "club"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
Loading

0 comments on commit 5529a6e

Please sign in to comment.