Skip to content

Commit

Permalink
Merge pull request #120 from midday-ai/feature/inbox-fix
Browse files Browse the repository at this point in the history
Fix inbox
  • Loading branch information
pontusab authored May 17, 2024
2 parents a5a7fcb + f6bc6e8 commit 6487e94
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 14 additions & 2 deletions apps/dashboard/src/actions/search-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { getUser } from "@midday/supabase/cached-queries";
import { createClient } from "@midday/supabase/server";
import { addDays, isWithinInterval } from "date-fns";
import { action } from "./safe-action";
import { searchSchema } from "./schema";

Expand All @@ -17,7 +18,7 @@ export const searchAction = action(searchSchema, async (params) => {
const query = supabase
.from("inbox")
.select(
"id, file_name, amount, currency, file_path, content_type, due_date, display_name"
"id, created_at, file_name, amount, currency, file_path, content_type, due_date, display_name"
)
.eq("team_id", teamId)
.neq("status", "deleted")
Expand All @@ -31,7 +32,18 @@ export const searchAction = action(searchSchema, async (params) => {

const { data } = await query.range(0, limit);

return data;
return data?.map((item) => {
const pending = isWithinInterval(new Date(), {
start: new Date(item.created_at),
end: addDays(new Date(item.created_at), 45),
});

return {
...item,
pending,
review: !pending && !item.id,
};
});
}

case "categories": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Database, Tables } from "../../src/types";

type TransactionCategoriesRecord = Tables<"transaction_categories">;
interface WebhookPayload {
type: "INSERT" | "UPDATE";
type: "INSERT";
table: string;
record: TransactionCategoriesRecord;
schema: "public";
Expand All @@ -21,7 +21,7 @@ const model = new Supabase.ai.Session("gte-small");

Deno.serve(async (req) => {
const payload: WebhookPayload = await req.json();
const { id, name } = payload.record;
const { id, name, system } = payload.record;

if (name === payload?.old_record?.name) {
return new Response("No change");
Expand Down

0 comments on commit 6487e94

Please sign in to comment.