diff --git a/package.json b/package.json index 6808103..d4d2cfc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "localcache-meisam", - "version": "2.5.0", + "version": "2.6.0", "description": "[personal] An Express.js API for managing in-memory and local storage.", "main": "src/models/index.js", "type": "module", diff --git a/src/controllers/localController.js b/src/controllers/localController.js index 6ccdfe7..2827a3d 100644 --- a/src/controllers/localController.js +++ b/src/controllers/localController.js @@ -24,13 +24,18 @@ export const setLocalItem = (req, res) => { export const getLocalItem = (req, res) => { const keys = req.params.keys.split(","); debug("[localStorage]getting:", keys); - const value = localStorage.getItem(...keys); - if (value === null) { + const values = localStorage.getItem(...keys); + // if (value === null) { + // return res + // .status(404) + // .json(new Msg({ success: false, msg: "Data not found" })); + // } + if (Object.values(values).every((value) => value === null)) { return res .status(404) .json(new Msg({ success: false, msg: "Data not found" })); } - res.status(200).json(new Msg({ success: true, obj: { value } })); + res.status(200).json(new Msg({ success: true, obj: { ...values } })); }; export const removeLocalItem = (req, res) => { diff --git a/src/controllers/memoryController.js b/src/controllers/memoryController.js index a959ea1..cf7f3ae 100644 --- a/src/controllers/memoryController.js +++ b/src/controllers/memoryController.js @@ -26,5 +26,5 @@ export const getMemoryItems = (req, res) => { .status(404) .json(new Msg({ success: false, msg: "Data not found" })); } - res.status(200).json(new Msg({ success: true, obj: values })); + res.status(200).json(new Msg({ success: true, obj: { ...values } })); }; diff --git a/src/utils/common.js b/src/utils/common.js index 4657650..3a2f281 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -1,7 +1,7 @@ import Msg from "./msg.js"; function isJson(str) { - const result = new Msg(); + const result = new Msg({}); try { result.obj = JSON.parse(str); result.success = true;