--this function works fine
fetchVerifiedUserData = function(mailHash)
local dbName = "server"
local collectionName = "users"
local key = "email"
local value = mailHash
local jsonDoc = nil
local App42CallBackForFetch = {}
function App42CallBackForFetch:onSuccess(object)
print ("Got user data")
print("dbName is "..object:getDbName())
for i=1,table.getn(object:getJsonDocList()) do
print("DocId is "..object:getJsonDocList()[i]:getDocId())
print("CreatedAt is "..object:getJsonDocList()[i]:getCreatedAt())
end
jsonDoc = object.jsonDocList[1].jsonDoc
for k, v in pairs(jsonDoc) do
Global.user[k] = v
print ("k/v", k,v)
end
if Global.user["verified"] == "false" then
print ("set true locally")
Global.user["verified"] = "true"
end
end
function App42CallBackForFetch:onException(exception)
print("Message is : "..exception:getMessage())
print("App Error code is : "..exception:getAppErrorCode())
print("Http Error code is "..exception:getHttpErrorCode())
print("Detail is : "..exception:getDetails())
end
--add check to see if exists
storageService:findDocumentByKeyValue(dbName, collectionName, key, value, App42CallBackForFetch)
end
--this function fails
writeDataToDB = function (mailHash, dataTable)
local dbName = "server"
local collectionName = "users"
local key = "email"
local value = mailHash --mailHash
local jsonDoc = {}
jsonDoc.email = true
local App42CallBackForWrite = {}
function App42CallBackForWrite:onSuccess(object)
print ("Wrote data")
print("dbName is "..object:getDbName())
for i=1,table.getn(object:getJsonDocList()) do
print("DocId is "..object:getJsonDocList()[i]:getDocId())
print("CreatedAt is "..object:getJsonDocList()[i]:getCreatedAt())
end
end
function App42CallBackForWrite:onException(exception)
print ("Failed to write data")
print("Message is : "..exception:getMessage())
print("App Error code is : "..exception:getAppErrorCode())
print("Http Error code is "..exception:getHttpErrorCode())
print("Detail is : "..exception:getDetails())
end
storageService:updateDocumentByKeyValue(dbName,collectionName,key,value,jsonDoc,App42CallBackForWrite)
end
--- error info
Header Key is : dataACL Header Value is : ""
Header Key is : emailAuth Header Value is : "true"
Header Key is : jsonObject Header Value is : "[]"
Header Key is : loggedInUser Header Value is : "Tom"
Header Key is : resource Header Value is : "storage"
Header Key is : selectKeys Header Value is : "[]"
Header Key is : sessionId Header Value is : "eb8f3d83-d8f4-474a-a90f-c120db74b7c1"
Header Key is : signature Header Value is : "YjHSCFGkpj5o43XSFRzRaQx7ppw%3D"
Header Key is : timeStamp Header Value is : "2016-10-07T04:31:36.000Z"
Header Key is : version Header Value is : "1.0"
Oct 06 09:31:36.312 Excpetion is : {"app42Fault":{"httpErrorCode":404,"appErrorCode":2601,"message":"Not Found","details":"Document by key 'email' and value 'c876f512363ed428a6b31cfee9432f18' does not exist."}}
Oct 06 09:31:36.312 No
Message is : Not Found
App Error code is : 2601
Http Error code is 404
Detail is : Document by key 'email' and value 'c876f512363ed428a6b31cfee9432f18' does not exist.