So its like broken but we are rewriting status.ts & TechTable & HistoryTable
This commit is contained in:
53
src/lib/actions/status.ts
Normal file
53
src/lib/actions/status.ts
Normal file
@ -0,0 +1,53 @@
|
||||
'use server'
|
||||
|
||||
import 'server-only';
|
||||
import {
|
||||
createServerClient,
|
||||
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 () => {
|
||||
try {
|
||||
const supabase = await createServerClient();
|
||||
|
||||
// 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 });
|
||||
|
||||
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