Version 1.0 squash

This commit is contained in:
Kenan Alić
2025-10-21 18:45:02 +02:00
parent 8c1f041fa0
commit a481044c43
30 changed files with 2534 additions and 15 deletions

View File

@@ -0,0 +1,44 @@
/**
* Notices Service
*
* Handles all data operations for notices including fetching
* and real-time subscriptions for bulletin board display.
*
* Returns data directly from PocketBase with no transformations.
* Uses created field from RecordModel for posted date.
*/
import { pb, Collections } from "@/lib/pocketbase";
import type { Notice } from "@/types/notice";
import { safely } from "@/lib/result";
/**
* Fetches all notices from PocketBase
* Returns notices sorted by created date (newest first)
* Includes both active and expired notices for display
*
* @returns Array of all notice records sorted by creation date
*/
export async function getNotices(): Promise<Notice[]> {
return await pb.collection(Collections.Notices).getFullList<Notice>({
sort: "-created",
});
}
/**
* Subscribes to real-time notice updates
* Callback is invoked whenever any notice is created, updated, or deleted
*
* @param callback Function to call when notices change
* @returns Unsubscribe function to clean up the subscription
*/
export function subscribeToNotices(callback: (notices: Notice[]) => void): () => void {
pb.collection(Collections.Notices).subscribe<Notice>("*", async () => {
const notices = await getNotices();
callback(notices);
});
return () => {
safely(() => pb.collection(Collections.Notices).unsubscribe("*"));
};
}