- fix Indexdb:
1) ReadAllData 'GET' : OK 2) InsertTodo 'POST' : OK 3) DeleteItem 'DELETE': OK 4) Modify 'PATCH' : OK
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import axios, { AxiosInstance, AxiosPromise, AxiosResponse, AxiosInterceptorManager } from 'axios'
|
||||
|
||||
async function sendRequest (url: string, lang: string, mytok: string, method: string, mydata: any) {
|
||||
async function sendRequest(url: string, lang: string, mytok: string, method: string, mydata: any) {
|
||||
|
||||
console.log('sendRequest', method, url, '[', lang, ']')
|
||||
|
||||
@@ -18,6 +18,12 @@ async function sendRequest (url: string, lang: string, mytok: string, method: st
|
||||
cache: 'no-cache',
|
||||
headers: authHeader
|
||||
}
|
||||
} else if (method === 'DELETE') {
|
||||
configInit = {
|
||||
method: method,
|
||||
cache: 'no-cache',
|
||||
headers: authHeader
|
||||
}
|
||||
} else {
|
||||
configInit = {
|
||||
method: method,
|
||||
|
||||
@@ -77,12 +77,20 @@ namespace Actions {
|
||||
}
|
||||
|
||||
async function dbSaveTodo(context, itemtodo: ITodo) {
|
||||
console.log('dbSaveTodo', itemtodo)
|
||||
return await dbInsertSaveTodo(context, itemtodo, 'PATCH')
|
||||
}
|
||||
|
||||
async function dbInsertTodo(context, itemtodo: ITodo) {
|
||||
return await dbInsertSaveTodo(context, itemtodo, 'POST')
|
||||
}
|
||||
|
||||
async function dbInsertSaveTodo(context, itemtodo: ITodo, method) {
|
||||
console.log('dbInsertSaveTodo', itemtodo, method)
|
||||
let call = process.env.MONGODB_HOST + '/todos/' + itemtodo._id
|
||||
|
||||
const token = UserStore.state.idToken
|
||||
|
||||
let res = await Api.SendReq(call, UserStore.state.lang, token, 'PATCH', itemtodo)
|
||||
let res = await Api.SendReq(call, UserStore.state.lang, token, method, itemtodo)
|
||||
.then(function (res) {
|
||||
return rescodes.OK
|
||||
})
|
||||
@@ -127,6 +135,7 @@ namespace Actions {
|
||||
}
|
||||
|
||||
export const actions = {
|
||||
dbInsertTodo: b.dispatch(dbInsertTodo),
|
||||
dbSaveTodo: b.dispatch(dbSaveTodo),
|
||||
dbLoadTodo: b.dispatch(dbLoadTodo),
|
||||
dbDeleteTodo: b.dispatch(dbDeleteTodo),
|
||||
|
||||
Reference in New Issue
Block a user