refactor(db): migrate app pages and APIs from Prisma facade to Drizzle (5)
Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
9aa4f331bf
commit
30b54e99e7
40 files changed
+1183
-784
No files matched your search
@@ -1,4 +1,6 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db, User } from "@/lib/db";
|
||||
|
||||
/**
|
||||
* Build the SSO ticket exactly like AtomCMS's User::ssoTicket():
|
||||
@@ -12,30 +14,19 @@ export function generateSsoTicket(hotelName: string): string {
|
||||
return `${normalized}-${randomUUID()}`;
|
||||
}
|
||||
|
||||
/** Minimal shape of the Prisma client this needs (keeps it unit-testable). */
|
||||
export interface SsoUserUpdater {
|
||||
user: {
|
||||
update(args: {
|
||||
where: { id: number };
|
||||
data: { authTicket: string; ipCurrent: string };
|
||||
}): Promise<unknown>;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a ticket and persist it like AtomCMS: writes auth_ticket AND
|
||||
* ip_current on the user, then returns the ticket for the client launcher.
|
||||
*/
|
||||
export async function issueSsoTicket(
|
||||
db: SsoUserUpdater,
|
||||
userId: number,
|
||||
hotelName: string,
|
||||
ip: string,
|
||||
): Promise<string> {
|
||||
const ticket = generateSsoTicket(hotelName);
|
||||
await db.user.update({
|
||||
where: { id: userId },
|
||||
data: { authTicket: ticket, ipCurrent: ip },
|
||||
});
|
||||
await db
|
||||
.update(User)
|
||||
.set({ authTicket: ticket, ipCurrent: ip })
|
||||
.where(eq(User.id, userId));
|
||||
return ticket;
|
||||
}
|
||||
Reference in new issue
Block a user