- Update the way to use the data records on Vuex with Getters!
- Fix: mongodb call passing array todos and categiroes already splitted
This commit is contained in:
@@ -4,7 +4,7 @@ import router from '@router'
|
||||
import { clone } from 'lodash'
|
||||
import * as Types from './ApiTypes'
|
||||
import { GlobalStore, UserStore } from '@store'
|
||||
import { rescodes } from '@src/store/Modules/rescodes'
|
||||
import { tools } from '@src/store/Modules/tools'
|
||||
import { serv_constants } from '@src/store/Modules/serv_constants'
|
||||
|
||||
export const API_URL = process.env.MONGODB_HOST
|
||||
@@ -40,7 +40,7 @@ export const removeAuthHeaders = () => {
|
||||
async function Request(type: string, path: string, payload: any, setAuthToken?: boolean): Promise<Types.AxiosSuccess | Types.AxiosError> {
|
||||
let ricevuto = false
|
||||
try {
|
||||
console.log(`Axios Request [${type}]:`, axiosInstance.defaults)
|
||||
// console.log(`Axios Request [${type}]:`, axiosInstance.defaults)
|
||||
let response: AxiosResponse
|
||||
if (type === 'post' || type === 'put' || type === 'patch') {
|
||||
response = await axiosInstance[type](path, payload, {
|
||||
@@ -50,7 +50,7 @@ async function Request(type: string, path: string, payload: any, setAuthToken?:
|
||||
}
|
||||
})
|
||||
ricevuto = true
|
||||
console.log('response', response)
|
||||
// console.log('Request Response: ', response)
|
||||
// console.log(new Types.AxiosSuccess(response.data, response.status))
|
||||
|
||||
const setAuthToken = (path === '/updatepwd')
|
||||
@@ -62,26 +62,26 @@ async function Request(type: string, path: string, payload: any, setAuthToken?:
|
||||
x_auth_token = String(response.headers['x-auth'])
|
||||
|
||||
if (x_auth_token === '') {
|
||||
UserStore.mutations.setServerCode(rescodes.ERR_AUTHENTICATION)
|
||||
UserStore.mutations.setServerCode(tools.ERR_AUTHENTICATION)
|
||||
}
|
||||
if (setAuthToken) {
|
||||
UserStore.mutations.UpdatePwd(x_auth_token)
|
||||
localStorage.setItem(rescodes.localStorage.token, x_auth_token)
|
||||
localStorage.setItem(tools.localStorage.token, x_auth_token)
|
||||
}
|
||||
|
||||
UserStore.mutations.setAuth(x_auth_token)
|
||||
localStorage.setItem(rescodes.localStorage.token, x_auth_token)
|
||||
localStorage.setItem(tools.localStorage.token, x_auth_token)
|
||||
}
|
||||
|
||||
GlobalStore.mutations.setStateConnection(ricevuto ? 'online' : 'offline')
|
||||
UserStore.mutations.setServerCode(rescodes.OK)
|
||||
UserStore.mutations.setServerCode(tools.OK)
|
||||
} catch (e) {
|
||||
if (setAuthToken) {
|
||||
UserStore.mutations.setServerCode(rescodes.ERR_AUTHENTICATION)
|
||||
UserStore.mutations.setServerCode(tools.ERR_AUTHENTICATION)
|
||||
UserStore.mutations.setAuth('')
|
||||
}
|
||||
GlobalStore.mutations.setStateConnection(ricevuto ? 'online' : 'offline')
|
||||
return Promise.reject(new Types.AxiosError(serv_constants.RIS_CODE__HTTP_FORBIDDEN_INVALID_TOKEN, null, rescodes.ERR_AUTHENTICATION))
|
||||
return Promise.reject(new Types.AxiosError(serv_constants.RIS_CODE__HTTP_FORBIDDEN_INVALID_TOKEN, null, tools.ERR_AUTHENTICATION))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,11 +120,11 @@ async function Request(type: string, path: string, payload: any, setAuthToken?:
|
||||
}
|
||||
let mycode = 0
|
||||
if (!ricevuto) {
|
||||
mycode = rescodes.ERR_SERVERFETCH
|
||||
UserStore.mutations.setServerCode(rescodes.ERR_SERVERFETCH)
|
||||
mycode = tools.ERR_SERVERFETCH
|
||||
UserStore.mutations.setServerCode(tools.ERR_SERVERFETCH)
|
||||
} else {
|
||||
mycode = rescodes.ERR_GENERICO
|
||||
UserStore.mutations.setServerCode(rescodes.ERR_GENERICO)
|
||||
mycode = tools.ERR_GENERICO
|
||||
UserStore.mutations.setServerCode(tools.ERR_GENERICO)
|
||||
}
|
||||
|
||||
if (error.response) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import axios from 'axios'
|
||||
export { addAuthHeaders, removeAuthHeaders, API_URL } from './Instance'
|
||||
// import {AlgoliaSearch} from './AlgoliaController'
|
||||
import Paths from '@paths'
|
||||
import { rescodes } from '@src/store/Modules/rescodes'
|
||||
import { tools } from '@src/store/Modules/tools'
|
||||
|
||||
import { GlobalStore, UserStore } from '@modules'
|
||||
import globalroutines from './../../globalroutines/index'
|
||||
@@ -62,7 +62,7 @@ export namespace ApiTool {
|
||||
}
|
||||
|
||||
export async function SendReq(url: string, method: string, mydata: any, setAuthToken: boolean = false): Promise<Types.AxiosSuccess | Types.AxiosError> {
|
||||
UserStore.mutations.setServerCode(rescodes.EMPTY)
|
||||
UserStore.mutations.setServerCode(tools.EMPTY)
|
||||
UserStore.mutations.setResStatus(0)
|
||||
return await new Promise(function (resolve, reject) {
|
||||
|
||||
@@ -85,10 +85,10 @@ export namespace ApiTool {
|
||||
if (res.status === serv_constants.RIS_CODE__HTTP_FORBIDDEN_INVALID_TOKEN) {
|
||||
// Forbidden
|
||||
// You probably is connectiong with other page...
|
||||
UserStore.mutations.setServerCode(rescodes.ERR_AUTHENTICATION)
|
||||
UserStore.mutations.setServerCode(tools.ERR_AUTHENTICATION)
|
||||
UserStore.mutations.setAuth('')
|
||||
router.push('/signin')
|
||||
return reject({ code: rescodes.ERR_AUTHENTICATION })
|
||||
return reject({ code: tools.ERR_AUTHENTICATION })
|
||||
}
|
||||
|
||||
return resolve(res)
|
||||
@@ -147,7 +147,7 @@ export namespace ApiTool {
|
||||
if (method !== 'POST')
|
||||
link += '/' + rec._id
|
||||
|
||||
console.log(' [Alternative] ++++++++++++++++++ SYNCING !!!! ', rec.descr, table, 'FETCH: ', method, link, 'data:')
|
||||
// console.log(' [Alternative] ++++++++++++++++++ SYNCING !!!! ', rec.descr, table, 'FETCH: ', method, link, 'data:')
|
||||
|
||||
// Insert/Delete/Update table to the server
|
||||
return SendReq(link, method, rec)
|
||||
|
||||
Reference in New Issue
Block a user