fix: recalculer le score après correction manuelle
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { z } from "zod";
|
||||
import { COOKIE_NAME } from "@shared/const";
|
||||
import { BAP_MIN_QUALITY_SCORE, meetsBapQualityThreshold } from "@shared/bapEligibility";
|
||||
import { calculateInvoiceQualityScore } from "@shared/invoiceQuality";
|
||||
|
||||
interface Condition {
|
||||
field: string;
|
||||
@@ -476,13 +477,23 @@ export const appRouter = router({
|
||||
if (!invoice || (ctx.user.role !== 'admin' && invoice.userId !== ctx.user.id)) {
|
||||
throw new TRPCError({ code: "NOT_FOUND" });
|
||||
}
|
||||
|
||||
// Le score reflète toujours les valeurs actuellement enregistrées, y compris
|
||||
// celles corrigées manuellement. La configuration est celle du propriétaire
|
||||
// de la facture afin de conserver la même règle que lors de son extraction.
|
||||
const fieldsConfiguration = await getLlmFieldsConfigByUser(invoice.userId);
|
||||
const qualityScore = calculateInvoiceQualityScore(
|
||||
{ ...invoice, ...input.data },
|
||||
fieldsConfiguration,
|
||||
);
|
||||
|
||||
await updateInvoice(input.id, {
|
||||
...input.data,
|
||||
qualityScore,
|
||||
manuallyEdited: 1,
|
||||
});
|
||||
|
||||
return { success: true };
|
||||
return { success: true, qualityScore };
|
||||
}),
|
||||
|
||||
delete: protectedProcedure
|
||||
|
||||
Reference in New Issue
Block a user