Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docker/init-scripts/01-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ CREATE TYPE public."roleType" AS ENUM (
'USER',
'STAFF',
'ADMIN',
'CORPORATE'
'CORPORATE',
'SUPER_ADMIN'
);

CREATE TYPE public."staffAttendanceType" AS ENUM (
Expand Down
7 changes: 0 additions & 7 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,6 @@ export type EventType = Enums<"eventType">;
export type StaffAttendanceType = Enums<"staffAttendanceType">;
export type ShiftRoleType = Enums<"shiftRoleType">;

export const RoleTypes: Record<RoleType, RoleType> = {
USER: "USER",
STAFF: "STAFF",
ADMIN: "ADMIN",
CORPORATE: "CORPORATE",
};

export const CommitteeTypes: Record<string, CommitteeType> = {
CONTENT: "CONTENT",
CORPORATE: "CORPORATE",
Expand Down
191 changes: 97 additions & 94 deletions src/database.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ export type Database = {
name: string;
points: number;
startTime: string;
tags: string[];
};
Insert: {
attendanceCount?: number;
Expand All @@ -359,6 +360,7 @@ export type Database = {
name: string;
points: number;
startTime: string;
tags?: string[];
};
Update: {
attendanceCount?: number;
Expand All @@ -373,6 +375,7 @@ export type Database = {
name?: string;
points?: number;
startTime?: string;
tags?: string[];
};
Relationships: [];
};
Expand Down Expand Up @@ -449,6 +452,29 @@ export type Database = {
},
];
};
redemptions: {
Row: {
item: Database["public"]["Enums"]["tierType"];
userId: string;
};
Insert: {
item: Database["public"]["Enums"]["tierType"];
userId: string;
};
Update: {
item?: Database["public"]["Enums"]["tierType"];
userId?: string;
};
Relationships: [
{
foreignKeyName: "redemptions_user_id_fkey";
columns: ["userId"];
isOneToOne: false;
referencedRelation: "authInfo";
referencedColumns: ["userId"];
},
];
};
registrations: {
Row: {
allergies: string[];
Expand Down Expand Up @@ -523,6 +549,66 @@ export type Database = {
},
];
};
shiftAssignments: {
Row: {
acknowledged: boolean;
shiftId: string;
staffEmail: string;
};
Insert: {
acknowledged?: boolean;
shiftId: string;
staffEmail: string;
};
Update: {
acknowledged?: boolean;
shiftId?: string;
staffEmail?: string;
};
Relationships: [
{
foreignKeyName: "shiftAssignments_shiftId_fkey";
columns: ["shiftId"];
isOneToOne: false;
referencedRelation: "shifts";
referencedColumns: ["shiftId"];
},
{
foreignKeyName: "shiftAssignments_staffEmail_fkey";
columns: ["staffEmail"];
isOneToOne: false;
referencedRelation: "staff";
referencedColumns: ["email"];
},
];
};
shifts: {
Row: {
endTime: string;
location: string;
name: string;
role: Database["public"]["Enums"]["shiftRoleType"];
shiftId: string;
startTime: string;
};
Insert: {
endTime: string;
location: string;
name: string;
role: Database["public"]["Enums"]["shiftRoleType"];
shiftId?: string;
startTime: string;
};
Update: {
endTime?: string;
location?: string;
name?: string;
role?: Database["public"]["Enums"]["shiftRoleType"];
shiftId?: string;
startTime?: string;
};
Relationships: [];
};
speakers: {
Row: {
bio: string;
Expand Down Expand Up @@ -574,66 +660,6 @@ export type Database = {
};
Relationships: [];
};
shifts: {
Row: {
shiftId: string;
name: string;
role: Database["public"]["Enums"]["shiftRoleType"];
startTime: string;
endTime: string;
location: string;
};
Insert: {
shiftId?: string;
name: string;
role: Database["public"]["Enums"]["shiftRoleType"];
startTime: string;
endTime: string;
location: string;
};
Update: {
shiftId?: string;
name?: string;
role?: Database["public"]["Enums"]["shiftRoleType"];
startTime?: string;
endTime?: string;
location?: string;
};
Relationships: [];
};
shiftAssignments: {
Row: {
shiftId: string;
staffEmail: string;
acknowledged: boolean;
};
Insert: {
shiftId: string;
staffEmail: string;
acknowledged?: boolean;
};
Update: {
shiftId?: string;
staffEmail?: string;
acknowledged?: boolean;
};
Relationships: [
{
foreignKeyName: "shiftAssignments_shiftId_fkey";
columns: ["shiftId"];
isOneToOne: false;
referencedRelation: "shifts";
referencedColumns: ["shiftId"];
},
{
foreignKeyName: "shiftAssignments_staffEmail_fkey";
columns: ["staffEmail"];
isOneToOne: false;
referencedRelation: "staff";
referencedColumns: ["email"];
},
];
};
subscriptions: {
Row: {
userId: string;
Expand All @@ -657,29 +683,6 @@ export type Database = {
},
];
};
redemptions: {
Row: {
userId: string;
item: Database["public"]["Enums"]["tierType"];
};
Insert: {
userId: string;
item: Database["public"]["Enums"]["tierType"];
};
Update: {
userId?: string;
item?: Database["public"]["Enums"]["tierType"];
};
Relationships: [
{
foreignKeyName: "redemptions_user_id_fkey";
columns: ["userId"];
isOneToOne: false;
referencedRelation: "authInfo";
referencedColumns: ["userId"];
},
];
};
};
Views: {
[_ in never]: never;
Expand All @@ -698,14 +701,6 @@ export type Database = {
};
};
Enums: {
shiftRoleType:
| "CLEAN_UP"
| "DINNER"
| "CHECK_IN"
| "SPEAKER_BUDDY"
| "SPONSOR_BUDDY"
| "DEV_ON_CALL"
| "CHAIR_ON_CALL";
committeeNames:
| "CONTENT"
| "CORPORATE"
Expand All @@ -728,7 +723,15 @@ export type Database = {
| "PINK"
| "PURPLE"
| "ORANGE";
roleType: "USER" | "STAFF" | "ADMIN" | "CORPORATE";
roleType: "USER" | "STAFF" | "ADMIN" | "CORPORATE" | "SUPER_ADMIN";
shiftRoleType:
| "CLEAN_UP"
| "DINNER"
| "CHECK_IN"
| "SPEAKER_BUDDY"
| "SPONSOR_BUDDY"
| "DEV_ON_CALL"
| "CHAIR_ON_CALL";
staffAttendanceType: "PRESENT" | "EXCUSED" | "ABSENT";
tierType: "TIER1" | "TIER2" | "TIER3" | "TIER4";
};
Expand Down Expand Up @@ -881,6 +884,8 @@ export const Constants = {
"MEALS",
"CHECKIN",
],
iconColorType: ["BLUE", "RED", "GREEN", "PINK", "PURPLE", "ORANGE"],
roleType: ["USER", "STAFF", "ADMIN", "CORPORATE", "SUPER_ADMIN"],
shiftRoleType: [
"CLEAN_UP",
"DINNER",
Expand All @@ -890,8 +895,6 @@ export const Constants = {
"DEV_ON_CALL",
"CHAIR_ON_CALL",
],
iconColorType: ["BLUE", "RED", "GREEN", "PINK", "PURPLE", "ORANGE"],
roleType: ["USER", "STAFF", "ADMIN", "CORPORATE"],
staffAttendanceType: ["PRESENT", "EXCUSED", "ABSENT"],
tierType: ["TIER1", "TIER2", "TIER3", "TIER4"],
},
Expand Down
8 changes: 7 additions & 1 deletion src/services/auth/auth-models.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { z } from "zod";

export const Role = z.enum(["USER", "STAFF", "ADMIN", "CORPORATE"]);
export const Role = z.enum([
"USER",
"STAFF",
"ADMIN",
"CORPORATE",
"SUPER_ADMIN",
]);
export type Role = z.infer<typeof Role>;

export enum Platform {
Expand Down
19 changes: 10 additions & 9 deletions src/services/auth/auth-router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import {
postAsAdmin,
postAsStaff,
putAsAdmin,
putAsStaff,
TESTER,
delAsSuperAdmin,
putAsSuperAdmin,
} from "../../../testing/testingTools";
import { AuthInfo, AuthRole } from "./auth-schema";
import { Platform, Role } from "./auth-models";
Expand Down Expand Up @@ -81,7 +82,7 @@ beforeEach(async () => {

describe("DELETE /auth/", () => {
it("should remove the requested role", async () => {
const res = await delAsAdmin("/auth/")
const res = await delAsSuperAdmin("/auth/")
.send({
userId: OTHER_USER.userId,
role: Role.Enum.STAFF,
Expand All @@ -101,7 +102,7 @@ describe("DELETE /auth/", () => {
});

it("should give the not found error when the user doesn't exist", async () => {
const res = await delAsAdmin("/auth/")
const res = await delAsSuperAdmin("/auth/")
.send({
userId: "nonexistent",
role: Role.Enum.STAFF,
Expand All @@ -111,8 +112,8 @@ describe("DELETE /auth/", () => {
expect(res.body).toHaveProperty("error", "UserNotFound");
});

it("should require admin permissions", async () => {
const res = await delAsStaff("/auth/")
it("should require super admin permissions", async () => {
const res = await delAsAdmin("/auth/")
.send({
userId: OTHER_USER.userId,
role: Role.Enum.STAFF,
Expand All @@ -125,7 +126,7 @@ describe("DELETE /auth/", () => {

describe("PUT /auth/", () => {
it("should add the requested role", async () => {
const res = await putAsAdmin("/auth/")
const res = await putAsSuperAdmin("/auth/")
.send({
userId: OTHER_USER.userId,
role: Role.Enum.ADMIN,
Expand All @@ -146,7 +147,7 @@ describe("PUT /auth/", () => {
});

it("should give the not found error if the user doesn't exist", async () => {
const res = await putAsAdmin("/auth/")
const res = await putAsSuperAdmin("/auth/")
.send({
userId: "nonexistent",
role: Role.Enum.ADMIN,
Expand All @@ -156,8 +157,8 @@ describe("PUT /auth/", () => {
expect(res.body).toHaveProperty("error", "UserNotFound");
});

it("should require admin permissions", async () => {
const res = await putAsStaff("/auth/")
it("should require super admin permissions", async () => {
const res = await putAsAdmin("/auth/")
.send({
userId: OTHER_USER.userId,
role: Role.Enum.STAFF,
Expand Down
Loading