feat(backend): complete AI and business migration
This commit is contained in:
@@ -1,42 +1,21 @@
|
||||
import { createClient } from "@/lib/supabase/server";
|
||||
import { requireFreelancerBackend } from "@/server/web/freelancer";
|
||||
import { InvoicesClient, type InvoiceRow } from "./invoices-client";
|
||||
|
||||
export default async function InvoicesPage() {
|
||||
const supabase = await createClient();
|
||||
const { data: { user } } = await supabase.auth.getUser();
|
||||
|
||||
if (!user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { data: invoicesData } = await supabase
|
||||
.from("invoices")
|
||||
.select(`
|
||||
id,
|
||||
invoice_number,
|
||||
amount,
|
||||
currency,
|
||||
status,
|
||||
issue_date,
|
||||
due_date,
|
||||
created_at,
|
||||
clients ( name ),
|
||||
projects ( name )
|
||||
`)
|
||||
.eq("user_id", user.id)
|
||||
.order("created_at", { ascending: false });
|
||||
|
||||
const invoices: InvoiceRow[] = (invoicesData || []).map((i: any) => ({
|
||||
id: i.id,
|
||||
invoice_number: i.invoice_number,
|
||||
amount: Number(i.amount),
|
||||
currency: i.currency,
|
||||
status: i.status,
|
||||
issue_date: i.issue_date,
|
||||
due_date: i.due_date,
|
||||
created_at: i.created_at,
|
||||
clientName: i.clients?.name || null,
|
||||
projectName: i.projects?.name || null,
|
||||
const { actor, service } = await requireFreelancerBackend();
|
||||
const clientNames = new Map(service.listClients(actor).map((client) => [client.id, client.name]));
|
||||
const projectNames = new Map(service.listProjects(actor).map((project) => [project.id, project.name]));
|
||||
const invoices: InvoiceRow[] = service.listInvoices(actor).map((invoice) => ({
|
||||
id: invoice.id,
|
||||
invoice_number: invoice.invoiceNumber,
|
||||
amount: invoice.amountMinor / 100,
|
||||
currency: invoice.currency,
|
||||
status: invoice.status,
|
||||
issue_date: invoice.issueDate,
|
||||
due_date: invoice.dueDate,
|
||||
created_at: invoice.createdAt.toISOString(),
|
||||
clientName: invoice.clientId ? clientNames.get(invoice.clientId) ?? null : null,
|
||||
projectName: invoice.projectId ? projectNames.get(invoice.projectId) ?? null : null,
|
||||
}));
|
||||
|
||||
return <InvoicesClient invoices={invoices} />;
|
||||
|
||||
@@ -1,40 +1,20 @@
|
||||
import { createClient } from "@/lib/supabase/server";
|
||||
import { requireFreelancerBackend } from "@/server/web/freelancer";
|
||||
import { ProposalsClient, type ProposalRow } from "./proposals-client";
|
||||
|
||||
export default async function ProposalsPage() {
|
||||
const supabase = await createClient();
|
||||
const { data: { user } } = await supabase.auth.getUser();
|
||||
|
||||
if (!user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { data: proposalsData } = await supabase
|
||||
.from("proposals")
|
||||
.select(`
|
||||
id,
|
||||
title,
|
||||
amount,
|
||||
currency,
|
||||
status,
|
||||
valid_until,
|
||||
created_at,
|
||||
clients ( name ),
|
||||
projects ( name )
|
||||
`)
|
||||
.eq("user_id", user.id)
|
||||
.order("created_at", { ascending: false });
|
||||
|
||||
const proposals: ProposalRow[] = (proposalsData || []).map((p: any) => ({
|
||||
id: p.id,
|
||||
title: p.title,
|
||||
amount: Number(p.amount),
|
||||
currency: p.currency,
|
||||
status: p.status,
|
||||
valid_until: p.valid_until,
|
||||
created_at: p.created_at,
|
||||
clientName: p.clients?.name || null,
|
||||
projectName: p.projects?.name || null,
|
||||
const { actor, service } = await requireFreelancerBackend();
|
||||
const clientNames = new Map(service.listClients(actor).map((client) => [client.id, client.name]));
|
||||
const projectNames = new Map(service.listProjects(actor).map((project) => [project.id, project.name]));
|
||||
const proposals: ProposalRow[] = service.listProposals(actor).map((proposal) => ({
|
||||
id: proposal.id,
|
||||
title: proposal.title,
|
||||
amount: proposal.amountMinor / 100,
|
||||
currency: proposal.currency,
|
||||
status: proposal.status,
|
||||
valid_until: proposal.validUntil?.toISOString() ?? null,
|
||||
created_at: proposal.createdAt.toISOString(),
|
||||
clientName: proposal.clientId ? clientNames.get(proposal.clientId) ?? null : null,
|
||||
projectName: proposal.projectId ? projectNames.get(proposal.projectId) ?? null : null,
|
||||
}));
|
||||
|
||||
return <ProposalsClient proposals={proposals} />;
|
||||
|
||||
@@ -1,40 +1,18 @@
|
||||
import { createClient } from "@/lib/supabase/server";
|
||||
import { requireFreelancerBackend } from "@/server/web/freelancer";
|
||||
import { SubscriptionsClient, type SubscriptionRow } from "./subscriptions-client";
|
||||
|
||||
export default async function SubscriptionsPage() {
|
||||
const supabase = await createClient();
|
||||
const { data: { user } } = await supabase.auth.getUser();
|
||||
|
||||
if (!user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { data: subscriptionsData } = await supabase
|
||||
.from("subscriptions")
|
||||
.select(`
|
||||
id,
|
||||
name,
|
||||
amount,
|
||||
currency,
|
||||
billing_cycle,
|
||||
status,
|
||||
category,
|
||||
next_billing_date,
|
||||
created_at
|
||||
`)
|
||||
.eq("user_id", user.id)
|
||||
.order("created_at", { ascending: false });
|
||||
|
||||
const subscriptions: SubscriptionRow[] = (subscriptionsData || []).map((s: any) => ({
|
||||
id: s.id,
|
||||
name: s.name,
|
||||
amount: Number(s.amount),
|
||||
currency: s.currency,
|
||||
billing_cycle: s.billing_cycle,
|
||||
status: s.status,
|
||||
category: s.category,
|
||||
next_billing_date: s.next_billing_date,
|
||||
created_at: s.created_at,
|
||||
const { actor, service } = await requireFreelancerBackend();
|
||||
const subscriptions: SubscriptionRow[] = service.listSubscriptions(actor).map((subscription) => ({
|
||||
id: subscription.id,
|
||||
name: subscription.name,
|
||||
amount: subscription.amountMinor / 100,
|
||||
currency: subscription.currency,
|
||||
billing_cycle: subscription.billingCycle,
|
||||
status: subscription.status,
|
||||
category: subscription.category,
|
||||
next_billing_date: subscription.nextBillingDate,
|
||||
created_at: subscription.createdAt.toISOString(),
|
||||
}));
|
||||
|
||||
return <SubscriptionsClient subscriptions={subscriptions} />;
|
||||
|
||||
Reference in New Issue
Block a user