Add assigment of crew to events and shifts
This commit is contained in:
parent
0aff9cc94a
commit
cef6b13dd1
7 changed files with 153 additions and 3 deletions
23
server/api/accounts/index.get.ts
Normal file
23
server/api/accounts/index.get.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import { readAccounts } from "~/server/database"
|
||||
import { requireAccountSession } from "~/server/utils/session";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const session = await requireAccountSession(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") {
|
||||
return accounts;
|
||||
}
|
||||
if (account.type === "crew") {
|
||||
return accounts.filter(a => a.type === "crew" || a.type === "admin");
|
||||
}
|
||||
throw createError({
|
||||
status: 403,
|
||||
statusText: "Forbidden",
|
||||
message: "You do not have permission to list accounts",
|
||||
});
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue