Skip to content

Commit

Permalink
[#1153] Add new lib: sync datapoints process
Browse files Browse the repository at this point in the history
  • Loading branch information
ifirmawan committed Feb 7, 2024
1 parent eae82b7 commit 6801f5c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions app/src/lib/sync-datapoints.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { crudMonitoring } from '../database/crud';
import api from './api';

export const fetchDatapoints = async (form, pageNumber = 1, allData = []) => {
try {
const response = await api.get(`/datapoint-list?page=${pageNumber}&form=${form}`);
const data = response.data.data;

const updatedData = [...allData, ...data];

if (data.hasMorePages) {
return fetchDatapoints(form, pageNumber + 1, updatedData);
} else {
return updatedData;
}
} catch (error) {
return Promise.reject(error);
}
};

export const downloadDatapointsJson = async (formId, url) => {
try {
const response = await api.get(url);
if (response.status === 200) {
const jsonData = response.data;
const res = await crudMonitoring.syncForm({
formId,
formJSON: jsonData,
});
console.info('[SYNCED MONITORING]', res);
}
} catch (error) {
return Promise.reject(error);
}
};

0 comments on commit 6801f5c

Please sign in to comment.