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