feat(portal): replace mock data with real session-driven API calls #152
@@ -38,11 +38,13 @@ setupRouter.post("/", zValidator("json", setupSchema), async (c) => {
|
|||||||
.from(businessSettings)
|
.from(businessSettings)
|
||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
// Check if any super user already exists (race condition guard)
|
// Lock super user rows to prevent concurrent claims
|
||||||
|
// FOR UPDATE serializes concurrent claims: second transaction blocks until first commits
|
||||||
const [existingSuperUser] = await tx
|
const [existingSuperUser] = await tx
|
||||||
.select({ id: staff.id })
|
.select({ id: staff.id })
|
||||||
.from(staff)
|
.from(staff)
|
||||||
.where(eq(staff.isSuperUser, true))
|
.where(eq(staff.isSuperUser, true))
|
||||||
|
.for("update")
|
||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
if (existingSuperUser) {
|
if (existingSuperUser) {
|
||||||
|
|||||||
Reference in New Issue
Block a user