summaryrefslogtreecommitdiff
path: root/src/pages/api/search-flashsale.js
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-12-24 08:51:37 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-12-24 08:51:37 +0700
commit22bf497d3fd524a95982e090f2c8a1be6bde656b (patch)
tree1c394154c78ea81e06b302eeffcb9dfb14497144 /src/pages/api/search-flashsale.js
parentb2afb5c847c9983b098a3223fbcfdb666e65c8cb (diff)
parentd76f96c44f85e7e0efbd544e6b97bd80920b0039 (diff)
Merge branch 'new-release' into Feature/switch-account
# Conflicts: # src-migrate/modules/register/components/FormBisnis.tsx # src/lib/auth/components/Menu.jsx
Diffstat (limited to 'src/pages/api/search-flashsale.js')
-rw-r--r--src/pages/api/search-flashsale.js26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/pages/api/search-flashsale.js b/src/pages/api/search-flashsale.js
index d9e56c83..c00f6c64 100644
--- a/src/pages/api/search-flashsale.js
+++ b/src/pages/api/search-flashsale.js
@@ -23,20 +23,28 @@ export default async function handler(req, res) {
if (cachedData) {
const data = JSON.parse(cachedData);
+ // Periksa apakah data adalah array dan panjangnya 0
+ if (!data || (Array.isArray(data) && data.length === 0)) {
+ await client.del(cacheKey); // Hapus kunci jika data kosong
+ return res.status(200).json({ data: [] });
+ }
return res.status(200).json({ data });
} else {
const dataProductSearch = await axios(
`${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/search?${query}&operation=${operation}]`
);
-
- await client.set(
- cacheKey,
- JSON.stringify(dataProductSearch.data),
- 'EX',
- duration
- );
- cachedData = await client.get(cacheKey);
- return res.status(200).json({ data: cachedData });
+ if (dataProductSearch.data.length === 0) {
+ return res.status(200).json({ data: [] });
+ } else {
+ await client.set(
+ cacheKey,
+ JSON.stringify(dataProductSearch.data),
+ 'EX',
+ duration
+ );
+ cachedData = await client.get(cacheKey);
+ return res.status(200).json({ data: cachedData });
+ }
}
} catch (error) {
console.error('Error interacting with Redis or fetching data:', error);