Skip to content

Commit

Permalink
quickfix: add unmatched in function (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-lipski authored Jul 8, 2024
1 parent 6ac4e4e commit 9d55c0f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions supabase/functions/process-invoice/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,39 @@ Deno.serve(async (req) => {
),
];

const unmatched = documentAnalysisResult
?.filter(
(analysis) =>
!matchAliasesToRecognizedData.recognizedAliases.some(
(recognizedAlias) => recognizedAlias === analysis?.sanitizedName
)
)
.reduce(
(acc, item) => {
if (item?.sanitizedName == null) return acc;

return {
...acc,
[item.sanitizedName]: {
price_per_unit: item?.price_per_unit ?? null,
quantity: item?.quantity ?? null,
},
};
},
{} as Record<
string,
{
price_per_unit: number | null;
quantity: number | null;
}
>
);

return new Response(
JSON.stringify({
form: matchAliasesToRecognizedData.recognized,
unmatchedAliases,
unmatched,
}),
{
headers: { ...corsHeaders, "Content-Type": "application/json" },
Expand Down

0 comments on commit 9d55c0f

Please sign in to comment.