- creating Alternative to SyncManager
- fix: refreshing with FF now it works!
This commit is contained in:
@@ -10,6 +10,7 @@ import Paths from '@paths'
|
||||
import { rescodes } from '@src/store/Modules/rescodes'
|
||||
|
||||
import { UserStore } from '@modules'
|
||||
import globalroutines from './../../globalroutines/index'
|
||||
|
||||
|
||||
// const algoliaApi = new AlgoliaSearch()
|
||||
@@ -52,8 +53,11 @@ export namespace ApiTool {
|
||||
sendRequest(url, lang, mytok, method, mydata)
|
||||
.then(resreceived => {
|
||||
ricevuto = true
|
||||
let res = resreceived
|
||||
console.log('SendReq RES=', res)
|
||||
let res = resreceived.clone()
|
||||
if (process.env.DEV) {
|
||||
console.log('SendReq RES [', res.status, ']', res)
|
||||
}
|
||||
|
||||
let x_auth_token = ''
|
||||
if (res.status === 200) {
|
||||
try {
|
||||
@@ -105,6 +109,75 @@ export namespace ApiTool {
|
||||
})
|
||||
}
|
||||
|
||||
export async function syncAlternative(mystrparam) {
|
||||
console.log('[ALTERNATIVE Background syncing', mystrparam)
|
||||
|
||||
let multiparams = mystrparam.split('|')
|
||||
if (multiparams) {
|
||||
if (multiparams.length > 3) {
|
||||
let cmd = multiparams[0]
|
||||
let table = multiparams[1]
|
||||
let method = multiparams[2]
|
||||
let token = multiparams[3]
|
||||
// let lang = multiparams[3]
|
||||
|
||||
if (cmd === 'sync-todos') {
|
||||
console.log('[Alternative] Syncing', cmd, table, method)
|
||||
|
||||
const headers = new Headers()
|
||||
headers.append('content-Type', 'application/json')
|
||||
headers.append('Accept', 'application/json')
|
||||
headers.append('x-auth', token)
|
||||
|
||||
console.log('A1) INIZIO.............................................................')
|
||||
|
||||
await globalroutines(null, 'readall', table, null)
|
||||
.then(function (alldata) {
|
||||
const myrecs = [...alldata]
|
||||
console.log('----------------------- LEGGO QUALCOSA ')
|
||||
if (myrecs) {
|
||||
for (let rec of myrecs) {
|
||||
// console.log('syncing', table, '', rec.descr)
|
||||
let link = process.env.MONGODB_HOST + '/todos'
|
||||
|
||||
if (method !== 'POST')
|
||||
link += '/' + rec._id
|
||||
|
||||
console.log(' [Alternative] ++++++++++++++++++ SYNCING !!!! ', rec.descr, table, 'FETCH: ', method, link, 'data:')
|
||||
|
||||
// Insert/Delete/Update table to the server
|
||||
fetch(link, {
|
||||
method: method,
|
||||
headers: headers,
|
||||
mode: 'cors', // 'no-cors',
|
||||
body: JSON.stringify(rec)
|
||||
})
|
||||
.then(function (resData) {
|
||||
// console.log('Result CALL ', method, ' OK? =', resData.ok);
|
||||
|
||||
// Anyway Delete this, otherwise in some cases will return error, but it's not a problem.
|
||||
// for example if I change a record and then I deleted ...
|
||||
// if (resData.ok) {
|
||||
// deleteItemFromData(table, rec._id);
|
||||
globalroutines(null, 'delete', table, null, rec._id)
|
||||
|
||||
console.log('DELETE: ', mystrparam)
|
||||
// deleteItemFromData('swmsg', mystrparam)
|
||||
globalroutines(null, 'delete', 'swmsg', null, mystrparam)
|
||||
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.log(' [Alternative] !!!!!!!!!!!!!!! Error while sending data', err)
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
console.log(' [Alternative] A2) ?????????????????????????? ESCO DAL LOOP !!!!!!!!! err=')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
export default ApiTool
|
||||
|
||||
Reference in New Issue
Block a user