So its like broken but we are rewriting status.ts & TechTable & HistoryTable
This commit is contained in:
52
src/lib/hooks/status.ts
Normal file
52
src/lib/hooks/status.ts
Normal file
@ -0,0 +1,52 @@
|
||||
'use client';
|
||||
|
||||
import {
|
||||
createClient,
|
||||
type Profile,
|
||||
type Result,
|
||||
type Status,
|
||||
} from '@/utils/supabase';
|
||||
|
||||
type UserWithStatus = {
|
||||
user: Profile;
|
||||
status: string;
|
||||
created_at: string;
|
||||
updated_by: Profile;
|
||||
};
|
||||
|
||||
type PaginatedHistory = UserWithStatus[] & {
|
||||
meta: {
|
||||
current_page: number;
|
||||
per_page: number;
|
||||
total_pages: number;
|
||||
total_count: number;
|
||||
};
|
||||
};
|
||||
|
||||
export const getUsersWithStatuses = async (): Promise<Result<UserWithStatus[]>> => {
|
||||
try {
|
||||
const supabase = createClient();
|
||||
|
||||
// Get only users with recent statuses (Past 7 days)
|
||||
const oneWeekAgo = new Date();
|
||||
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);
|
||||
|
||||
const { data: recentStatuses, error } = await supabase
|
||||
.from('statuses')
|
||||
.select(`
|
||||
user:profiles!user_id(*),
|
||||
status,
|
||||
created_at,
|
||||
updated_by:profiles!updated_by_id(*)
|
||||
`)
|
||||
.gte('created_at', oneWeekAgo.toISOString())
|
||||
.order('created_at', { ascending: false }) as {data: UserWithStatus[], error: unknown};
|
||||
|
||||
if (error) throw error;
|
||||
if (!recentStatuses.length) return { success: true, data: []};
|
||||
|
||||
return { success: true, data: recentStatuses };
|
||||
} catch (error) {
|
||||
return { success: false, error: `Error: ${error as string}` };
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user