- Add authedProcedure, superuserProcedure, loginRequestProcedure, orgMemberProcedure in base.ts - Create procedures/me/_base.ts with meRoute = authedProcedure.me - Update all me procedures to use meRoute.X.handler() - Update auth/logout and auth/resend-verification to use authedProcedure - Update all admin procedures to use superuserProcedure - Update all orgs procedures to use authedProcedure This reduces boilerplate and makes middleware usage consistent. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
/**
|
|
* admin.orgs.update - Update organization
|
|
*/
|
|
|
|
import { ORPCError } from "@orpc/server";
|
|
import { superuserProcedure } from "../../base.js";
|
|
|
|
export const adminOrgsUpdate = superuserProcedure.admin.orgs.update.handler(
|
|
async ({ input, context }) => {
|
|
const { slug, displayName, logoUrl } = input;
|
|
|
|
// Check if there are actual updates to make
|
|
if (displayName === undefined && logoUrl === undefined) {
|
|
// Verify org exists even for no-op
|
|
const org = await context.db
|
|
.selectFrom("orgs")
|
|
.where("slug", "=", slug)
|
|
.select(["id"])
|
|
.executeTakeFirst();
|
|
if (!org) {
|
|
throw new ORPCError("NOT_FOUND", { message: "Organization not found" });
|
|
}
|
|
return { success: true };
|
|
}
|
|
|
|
const updates: Partial<{
|
|
display_name: string;
|
|
logo_url: string | null;
|
|
updated_at: Date;
|
|
}> = { updated_at: new Date() };
|
|
|
|
if (displayName !== undefined) {
|
|
updates.display_name = displayName;
|
|
}
|
|
if (logoUrl !== undefined) {
|
|
updates.logo_url = logoUrl || null;
|
|
}
|
|
|
|
const result = await context.db
|
|
.updateTable("orgs")
|
|
.set(updates)
|
|
.where("slug", "=", slug)
|
|
.executeTakeFirst();
|
|
|
|
if (!result.numUpdatedRows || result.numUpdatedRows === 0n) {
|
|
throw new ORPCError("NOT_FOUND", { message: "Organization not found" });
|
|
}
|
|
|
|
return { success: true };
|
|
},
|
|
);
|