add proper schemas

This commit is contained in:
chark1es 2025-02-28 17:38:46 -08:00
parent d4fe0bf2b0
commit 8e439ebcf0
3 changed files with 251 additions and 0 deletions

46
pocketbase/README.md Normal file
View file

@ -0,0 +1,46 @@
# PocketBase Schema
This directory contains the schema definition for the PocketBase database used in the IEEE UCSD website.
## Overview
The `schema.ts` file defines TypeScript interfaces that represent the collections in the PocketBase database. These interfaces can be imported and used throughout the codebase to ensure type safety when working with PocketBase data.
## Collections
The following collections are defined in the schema:
- **Users**: User accounts in the system
- **Events**: Events created in the system
- **Event Requests**: Requests to create new events
- **Logs**: System logs for user actions
- **Officers**: Officer roles in the organization
- **Reimbursements**: Reimbursement requests
- **Receipts**: Receipt records for reimbursements
- **Sponsors**: Sponsors of the organization
## Usage
To use these types in your code, import them from the schema file:
```typescript
import { User, Event, Collections } from "../pocketbase/schema";
// Example: Get a user from PocketBase
const getUser = async (userId: string): Promise<User> => {
const pb = getPocketBase();
return await pb.collection(Collections.USERS).getOne<User>(userId);
};
```
## Updating the Schema
When the PocketBase database schema changes, update the corresponding interfaces in `schema.ts` to reflect those changes. This ensures that the TypeScript types match the actual database structure.
## Collection Names
The `Collections` object provides constants for all collection names, which should be used when making API calls to PocketBase instead of hardcoding collection names as strings.
## Collection IDs
Each collection has its PocketBase collection ID documented in the schema file. These IDs are useful for reference and debugging purposes.

8
pocketbase/index.ts Normal file
View file

@ -0,0 +1,8 @@
/**
* PocketBase Schema Index
*
* This file re-exports all types and constants from the schema file
* for easier imports throughout the codebase.
*/
export * from "./schema";

197
pocketbase/schema.ts Normal file
View file

@ -0,0 +1,197 @@
/**
* PocketBase Collections Schema
*
* This file documents the schema for all collections in the PocketBase database.
* It is based on the interfaces found throughout the codebase.
*/
/**
* Base interface for all PocketBase records
*/
export interface BaseRecord {
id: string;
created: string;
updated: string;
}
/**
* Users Collection
* Represents user accounts in the system
* Collection ID: _pb_users_auth_
*/
export interface User extends BaseRecord {
email: string;
emailVisibility: boolean;
verified: boolean;
name: string;
avatar?: string;
pid?: string;
member_id?: string;
graduation_year?: number;
major?: string;
zelle_information?: string;
}
/**
* Events Collection
* Represents events created in the system
* Collection ID: pbc_1687431684
*/
export interface Event extends BaseRecord {
event_name: string;
event_description: string;
event_code: string;
location: string;
files: string[];
points_to_reward: number;
start_date: string;
end_date: string;
published: boolean;
has_food: boolean;
attendees?: AttendeeEntry[];
}
/**
* Attendee Entry
* Represents an attendee record for an event
* This is stored as part of the Event record
*/
export interface AttendeeEntry {
user_id: string;
time_checked_in: string;
food: string;
}
/**
* Event Requests Collection
* Represents requests to create new events
* Collection ID: pbc_1475615553
*/
export interface EventRequest extends BaseRecord {
name: string;
location: string;
start_date_time: string;
end_date_time: string;
event_description: string;
flyers_needed: boolean;
flyer_type?: string[];
other_flyer_type?: string;
flyer_advertising_start_date?: string;
flyer_additional_requests?: string;
photography_needed: boolean;
required_logos?: string[];
other_logos?: string[];
advertising_format?: string;
will_or_have_room_booking?: boolean;
expected_attendance?: number;
room_booking?: string;
as_funding_required: boolean;
food_drinks_being_served: boolean;
itemized_invoice?: string; // JSON string
invoice?: string;
needs_graphics?: boolean;
needs_as_funding?: boolean;
status: string;
requested_user?: string;
}
/**
* Logs Collection
* Represents system logs for user actions
* Collection ID: pbc_3615662572
*/
export interface Log extends BaseRecord {
user: string; // Relation to User
type: string; // Standard types: "error", "update", "delete", "create", "login", "logout"
part: string; // The specific part/section being logged
message: string;
}
/**
* Officers Collection
* Represents officer roles in the organization
* Collection ID: pbc_1036312343
*/
export interface Officer extends BaseRecord {
user: string; // Relation to User
role: string;
type: string; // e.g., "administrator"
}
/**
* Reimbursements Collection
* Represents reimbursement requests
* Collection ID: pbc_2573806534
*/
export interface Reimbursement extends BaseRecord {
title: string;
total_amount: number;
date_of_purchase: string;
payment_method: string;
status:
| "submitted"
| "under_review"
| "approved"
| "rejected"
| "in_progress"
| "paid";
submitted_by: string; // Relation to User
additional_info: string;
receipts: string[]; // Array of Receipt IDs (Relations)
department: "internal" | "external" | "projects" | "events" | "other";
audit_notes?: string | null; // JSON string for user-submitted notes
audit_logs?: string | null; // JSON string for system-generated logs
}
/**
* Receipts Collection
* Represents receipt records for reimbursements
* Collection ID: pbc_1571142587
*/
export interface Receipt extends BaseRecord {
field: string;
created_by: string; // Relation to User
itemized_expenses: string; // JSON string of ItemizedExpense[]
tax: number;
date: string;
location_name: string;
location_address: string;
notes: string;
audited_by: string; // Relation to User
}
/**
* Sponsors Collection
* Represents sponsors of the organization
* Collection ID: pbc_3665759510
*/
export interface Sponsor extends BaseRecord {
user: string; // Relation to User
company: string;
}
/**
* Itemized Expense
* Represents an individual expense item in a receipt
* This is stored as part of the Receipt record as a JSON string
*/
export interface ItemizedExpense {
description: string;
category: string;
amount: number;
}
/**
* Collection Names
* Constants for the collection names used in the PocketBase API
*/
export const Collections = {
USERS: "users",
EVENTS: "events",
EVENT_REQUESTS: "event_request",
LOGS: "logs",
OFFICERS: "officers",
REIMBURSEMENTS: "reimbursement",
RECEIPTS: "receipts",
SPONSORS: "sponsors",
};