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

JUP-71 Backend Changes #252

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
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';
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 $$;
4 changes: 4 additions & 0 deletions src/server/db/migrations/0009_colossal_omega_flight.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE "officers" DROP CONSTRAINT "officers_club_id_id";--> statement-breakpoint
ALTER TABLE "officers" ADD PRIMARY KEY ("id");--> statement-breakpoint
ALTER TABLE "officers" ALTER COLUMN "id" SET DATA TYPE uuid;--> statement-breakpoint
ALTER TABLE "officers" ALTER COLUMN "id" SET DEFAULT gen_random_uuid();
Loading