B2B-49: save codes to db in sync script (#16)

* save codes to db

* save codes to db

---------

Co-authored-by: Helena <helena@Helenas-MacBook-Pro.local>
This commit is contained in:
Helena
2025-06-16 15:11:40 +03:00
committed by GitHub
parent 8209fb874f
commit 084653b5ea

View File

@@ -1,4 +1,5 @@
import { createClient as createCustomClient } from '@supabase/supabase-js';
import axios from 'axios';
import { format } from 'date-fns';
import { config } from 'dotenv';
@@ -126,6 +127,7 @@ async function syncData() {
});
}
const codes: any[] = [];
for (const analysisGroup of analysisGroups) {
// SAVE ANALYSIS GROUP
const { data: insertedAnalysisGroup, error } = await supabase
@@ -148,7 +150,8 @@ async function syncData() {
const analysisGroupId = insertedAnalysisGroup[0].id;
const analysisGroupCodes = toArray(analysisGroup.Kood);
const codes = analysisGroupCodes.map((kood) => ({
codes.push(
...analysisGroupCodes.map((kood) => ({
hk_code: kood.HkKood,
hk_code_multiplier: kood.HkKoodiKordaja,
coefficient: kood.Koefitsient,
@@ -156,7 +159,8 @@ async function syncData() {
analysis_group_id: analysisGroupId,
analysis_element_id: null,
analysis_id: null,
}));
})),
);
const analysisGroupItems = toArray(analysisGroup.Uuring);
@@ -229,7 +233,7 @@ async function syncData() {
}
const insertedAnalysisId = insertedAnalysis[0].id;
if (analysisElement.Kood) {
if (analysis.Kood) {
const analysisCodes = toArray(analysis.Kood);
codes.push(
@@ -249,6 +253,8 @@ async function syncData() {
}
}
await supabase.from('codes').upsert(codes);
await supabase.schema('audit').from('sync_entries').insert({
operation: 'ANALYSES_SYNC',
status: 'SUCCESS',