Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Nov 25, 2023
1 parent 546ce6d commit 7ece4fa
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 110 deletions.
21 changes: 0 additions & 21 deletions apps/dashboard/src/app/api/download/test/route.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Category } from "@/components/category";
import { TransactionMethod } from "@/components/transaction-method";
import { useCurrentLocale } from "@/locales/client";
import { formatAmount } from "@/utils/format";
import { Avatar, AvatarFallback, AvatarImage } from "@midday/ui/avatar";
import { Icons } from "@midday/ui/icons";
import { cn } from "@midday/ui/utils";
import { format } from "date-fns";
Expand Down Expand Up @@ -48,16 +47,7 @@ export function DataTableRow({ collapsed, onSelect, data, selected }) {
{data.date && format(new Date(data.date), "MMM d")}
</DataTableCell>

<DataTableCell className="w-[430px] space-x-2">
<Avatar className="rounded-full w-5 h-5">
<AvatarImage src={data?.enrichment?.logo_url} />
<AvatarFallback>
<span className="text-[10px]">{data?.name?.charAt(0)}</span>
</AvatarFallback>
</Avatar>

<span>{data.name}</span>
</DataTableCell>
<DataTableCell className="w-[430px] space-x-2">{data.name}</DataTableCell>

<DataTableCell className="w-[200px]">
<span className={cn("text-sm", data.amount > 0 && "text-[#00C969]")}>
Expand Down
37 changes: 14 additions & 23 deletions apps/dashboard/src/components/transaction-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
AccordionItem,
AccordionTrigger,
} from "@midday/ui/accordion";
import { Avatar, AvatarFallback, AvatarImage } from "@midday/ui/avatar";
import { Button } from "@midday/ui/button";
import { Icons } from "@midday/ui/icons";
import { Skeleton } from "@midday/ui/skeleton";
Expand Down Expand Up @@ -43,38 +42,30 @@ export function TransactionDetails({ transactionId, onClose, data }) {

<h2 className="mt-4 mb-3">
{isLoading ? (
<Skeleton className="w-[35%] h-[22px] rounded-md" />
<Skeleton className="w-[35%] h-[22px] rounded-md mb-2" />
) : (
data?.name
)}
</h2>
<div className="flex justify-between items-center">
<div className="flex flex-col w-full">
{isLoading ? (
<Skeleton className="w-[50%] h-[30px] rounded-md" />
<Skeleton className="w-[50%] h-[30px] rounded-md mb-2" />
) : (
<div className="flex flex-col space-y-3">
<span
className={cn(
"text-4xl",
data?.amount > 0 && "text-[#00C969]"
)}
>
{formatAmount({
amount: data?.amount,
currency: data?.currency,
locale,
})}
</span>
</div>
<span
className={cn(
"text-4xl",
data?.amount > 0 && "text-[#00C969]"
)}
>
{formatAmount({
amount: data?.amount,
currency: data?.currency,
locale,
})}
</span>
)}
</div>
<Avatar className="rounded-full w-[60px] h-[60px]">
<AvatarImage src={data?.enrichment?.logo_url} />
<AvatarFallback>
<span className="text-sm">{data?.name?.charAt(0)}</span>
</AvatarFallback>
</Avatar>
</div>
</div>

Expand Down
92 changes: 46 additions & 46 deletions apps/dashboard/src/jobs/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,52 +334,52 @@ client.defineJob({
run: async (payload, io) => {
const { teamId } = payload;

const { data: transactionsData } = await io.supabase.client
.from("transactions")
.select("id, name")
.eq("team_id", teamId)
.is("category", null)
.is("logo_url", null)
.is("enrichment_id", null)
.select();

async function enrichTransactions(transaction) {
const { data } = await io.supabase.client
.rpc("search_enriched_transactions", { term: transaction.name })
.single();

if (data) {
return {
...transaction,
enrichment_id: data?.id ?? null,
};
}
}

const result = await processPromisesBatch(
transactionsData,
5,
enrichTransactions
);

const filteredItems = result.filter(Boolean);

if (filteredItems.length > 0) {
const { data: updatedTransactions } = await io.supabase.client
.from("transactions")
.upsert(filteredItems)
.select();

if (updatedTransactions?.length > 0) {
revalidateTag(`transactions_${teamId}`);
revalidateTag(`spending_${teamId}`);
revalidateTag(`metrics_${teamId}`);

await io.logger.info(
`Transactions Enriched: ${updatedTransactions?.length}`
);
}
}
// const { data: transactionsData } = await io.supabase.client
// .from("transactions")
// .select("id, name")
// .eq("team_id", teamId)
// .is("category", null)
// .is("logo_url", null)
// .is("enrichment_id", null)
// .select();

// async function enrichTransactions(transaction) {
// const { data } = await io.supabase.client
// .rpc("search_enriched_transactions", { term: transaction.name })
// .single();

// if (data) {
// return {
// ...transaction,
// enrichment_id: data?.id ?? null,
// };
// }
// }

// const result = await processPromisesBatch(
// transactionsData,
// 5,
// enrichTransactions
// );

// const filteredItems = result.filter(Boolean);

// if (filteredItems.length > 0) {
// const { data: updatedTransactions } = await io.supabase.client
// .from("transactions")
// .upsert(filteredItems)
// .select();

// if (updatedTransactions?.length > 0) {
// revalidateTag(`transactions_${teamId}`);
// revalidateTag(`spending_${teamId}`);
// revalidateTag(`metrics_${teamId}`);

// await io.logger.info(
// `Transactions Enriched: ${updatedTransactions?.length}`
// );
// }
// }
},
});

Expand Down
12 changes: 3 additions & 9 deletions packages/supabase/src/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ export async function getSpendingQuery(
`
currency,
category,
enrichment:enrichment_id(category),
amount
`
)
Expand All @@ -154,9 +153,9 @@ export async function getSpendingQuery(
const combinedValues = {};

for (const item of data) {
const { category, amount, currency, enrichment } = item;
const { category, amount, currency } = item;

const key = (category || enrichment?.category) ?? "uncategorized";
const key = category ?? "uncategorized";

if (combinedValues[key]) {
combinedValues[key].amount += amount;
Expand Down Expand Up @@ -224,7 +223,6 @@ export async function getTransactionsQuery(
`
*,
assigned:assigned_id(*),
enrichment:enrichment_id(id,category,logo_url),
attachments(id,size,name)
`,
{ count: "exact" }
Expand Down Expand Up @@ -298,10 +296,7 @@ export async function getTransactionsQuery(
},
data: data?.map((transaction) => ({
...transaction,
category:
transaction?.category ||
transaction?.enrichment?.category ||
"uncategorized",
category: transaction?.category || "uncategorized",
})),
};
}
Expand All @@ -313,7 +308,6 @@ export async function getTransaction(supabase: Client, id: string) {
`
*,
assigned:assigned_id(*),
enrichment:enrichment_id(id,category,logo_url),
attachments(id,size,name)
`
)
Expand Down

0 comments on commit 7ece4fa

Please sign in to comment.