Refactor user storage and update
Rename accounts to users to be consistent with the new naming scheme where account only referes to the logged in user of the session and implement live updates of users via a user store which listens for updates from the event stream.
This commit is contained in:
parent
6336ccdb96
commit
3be7f8be05
24 changed files with 331 additions and 182 deletions
|
@ -1,18 +1,13 @@
|
|||
import { z } from "zod/v4-mini";
|
||||
import { readAccounts, readSchedule, writeSchedule } from "~/server/database";
|
||||
import { readUsers, readSchedule, writeSchedule } from "~/server/database";
|
||||
import { broadcastEvent } from "~/server/streams";
|
||||
import { apiScheduleSchema } from "~/shared/types/api";
|
||||
import { applyUpdatesToArray } from "~/shared/utils/update";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const session = await requireServerSession(event);
|
||||
const accounts = await readAccounts();
|
||||
const account = accounts.find(a => a.id === session.accountId);
|
||||
if (!account) {
|
||||
throw new Error("Account does not exist");
|
||||
}
|
||||
|
||||
if (account.type !== "admin" && account.type !== "crew") {
|
||||
if (session.account.type !== "admin" && session.account.type !== "crew") {
|
||||
throw createError({
|
||||
status: 403,
|
||||
statusMessage: "Forbidden",
|
||||
|
@ -46,7 +41,7 @@ export default defineEventHandler(async (event) => {
|
|||
}
|
||||
|
||||
// Validate edit restrictions for crew
|
||||
if (account.type === "crew") {
|
||||
if (session.account.type === "crew") {
|
||||
if (update.locations?.length) {
|
||||
throw createError({
|
||||
status: 403,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue