Skip to content

Commit

Permalink
update controller
Browse files Browse the repository at this point in the history
  • Loading branch information
maanimis committed Sep 3, 2024
1 parent dd69715 commit 4a15c63
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
11 changes: 8 additions & 3 deletions src/controllers/localController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/memoryController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }));
};
2 changes: 1 addition & 1 deletion src/utils/common.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 4a15c63

Please sign in to comment.