* Add account deletion and multi-section settings page - Rename /user-profile → /settings with 301 redirect from old URL - Add multi-section settings nav (Profile, Account, API placeholder, Data & Privacy) reusing existing SettingsDesktopNav/SettingsMobileGridNav components - Implement account deletion via anonymization: wipes all PII from users row, releases team ownerships, removes commissioner records, deletes sessions/accounts - Add data export request form that emails privacy@brackt.com via Resend - Add deletedAt timestamp column to users table (migration 0100) - Add anonymizeUserAccount() to user model - Add removeAllCommissionersByUserId() to commissioner model - Tests for both new model functions - Update UserMenu "Profile" link → "Settings" at /settings https://claude.ai/code/session_017Hvmof82Xr3UwKFc3pnC4X * Address code review feedback on settings/account deletion 1. Wrap anonymizeUserAccount in a DB transaction so partial failures (e.g. session delete succeeds but user update fails) can't leave accounts in an inconsistent state 2. Escape user email and notes with escapeHtml() before interpolating into the data request email body 3. Reset AlertDialog confirmed state when dialog is dismissed via backdrop click or Escape key (onOpenChange handler) 4. Extract accounts DB query to app/models/account.ts (findLinkedAccountsByUserId) to comply with the "always query through app/models/" convention 5. Replace dynamic imports() in action handlers with static top-level imports 6. Remove the unused hard-delete deleteUser() function 7. Add lastDataRequestAt timestamp to users (migration 0101) and enforce a 30-day server-side cooldown on data export requests 8. Replace fragile actionData type casts with a proper ActionData discriminated union; narrowing now works without `as` assertions 9. Strengthen tests: verify which schema tables are passed to delete() and that operations run inside the transaction https://claude.ai/code/session_017Hvmof82Xr3UwKFc3pnC4X * Fix no-non-null-assertion lint error in PrivacySection Replace non-null assertion with optional chaining on dataRequestCooldownUntil to satisfy oxlint no-non-null-assertion rule. https://claude.ai/code/session_017Hvmof82Xr3UwKFc3pnC4X --------- Co-authored-by: Claude <noreply@anthropic.com>
104 lines
2.9 KiB
TypeScript
104 lines
2.9 KiB
TypeScript
import { eq, and } from "drizzle-orm";
|
|
import { database } from "~/database/context";
|
|
import * as schema from "~/database/schema";
|
|
import { isUserAdmin } from "~/models/user";
|
|
|
|
export type Commissioner = typeof schema.commissioners.$inferSelect;
|
|
export type NewCommissioner = typeof schema.commissioners.$inferInsert;
|
|
|
|
export async function createCommissioner(
|
|
data: NewCommissioner
|
|
): Promise<Commissioner> {
|
|
const db = database();
|
|
const [commissioner] = await db
|
|
.insert(schema.commissioners)
|
|
.values(data)
|
|
.returning();
|
|
return commissioner;
|
|
}
|
|
|
|
export async function findCommissionersByLeagueId(
|
|
leagueId: string
|
|
): Promise<Commissioner[]> {
|
|
const db = database();
|
|
return await db.query.commissioners.findMany({
|
|
where: eq(schema.commissioners.leagueId, leagueId),
|
|
orderBy: (commissioners, { asc }) => [asc(commissioners.createdAt)],
|
|
});
|
|
}
|
|
|
|
export async function findCommissionersByUserId(
|
|
userId: string
|
|
): Promise<Commissioner[]> {
|
|
const db = database();
|
|
return await db.query.commissioners.findMany({
|
|
where: eq(schema.commissioners.userId, userId),
|
|
orderBy: (commissioners, { desc }) => [desc(commissioners.createdAt)],
|
|
});
|
|
}
|
|
|
|
export async function hasCommissionerRecord(
|
|
leagueId: string,
|
|
userId: string
|
|
): Promise<boolean> {
|
|
const db = database();
|
|
const commissioner = await db.query.commissioners.findFirst({
|
|
where: and(
|
|
eq(schema.commissioners.leagueId, leagueId),
|
|
eq(schema.commissioners.userId, userId)
|
|
),
|
|
});
|
|
return !!commissioner;
|
|
}
|
|
|
|
export async function isCommissioner(
|
|
leagueId: string,
|
|
userId: string
|
|
): Promise<boolean> {
|
|
const db = database();
|
|
const [isAdmin, commissioner] = await Promise.all([
|
|
isUserAdmin(userId),
|
|
db.query.commissioners.findFirst({
|
|
where: and(
|
|
eq(schema.commissioners.leagueId, leagueId),
|
|
eq(schema.commissioners.userId, userId)
|
|
),
|
|
}),
|
|
]);
|
|
return isAdmin || !!commissioner;
|
|
}
|
|
|
|
export async function countCommissionersByLeagueId(
|
|
leagueId: string
|
|
): Promise<number> {
|
|
const db = database();
|
|
const commissioners = await db.query.commissioners.findMany({
|
|
where: eq(schema.commissioners.leagueId, leagueId),
|
|
});
|
|
return commissioners.length;
|
|
}
|
|
|
|
export async function deleteCommissioner(id: string): Promise<void> {
|
|
const db = database();
|
|
await db.delete(schema.commissioners).where(eq(schema.commissioners.id, id));
|
|
}
|
|
|
|
export async function removeCommissionerByLeagueAndUser(
|
|
leagueId: string,
|
|
userId: string
|
|
): Promise<void> {
|
|
const db = database();
|
|
await db
|
|
.delete(schema.commissioners)
|
|
.where(
|
|
and(
|
|
eq(schema.commissioners.leagueId, leagueId),
|
|
eq(schema.commissioners.userId, userId)
|
|
)
|
|
);
|
|
}
|
|
|
|
export async function removeAllCommissionersByUserId(userId: string): Promise<void> {
|
|
const db = database();
|
|
await db.delete(schema.commissioners).where(eq(schema.commissioners.userId, userId));
|
|
}
|