From 8ec1cfe292558353233a66754dc03ca817639ed6 Mon Sep 17 00:00:00 2001 From: shreyvishal Date: Tue, 9 Apr 2024 00:13:15 +0530 Subject: [PATCH] Added: API to Unpublish an Item --- controllers/ControlCenter.js | 50 ++++++++++++++++++++++++++++++++++++ server.js | 4 ++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/controllers/ControlCenter.js b/controllers/ControlCenter.js index 4458215..fd6de79 100644 --- a/controllers/ControlCenter.js +++ b/controllers/ControlCenter.js @@ -167,4 +167,54 @@ export const updateStatus = async (req, res) => { logger.error(error.message) return res.status(400).send({ message: error.message, status:false }) } +} + +export const unpublishItem = async (req, res) => { + try{ + const {domain="", itemId=""} = req.body + let DOMAIN_DETAILS = { + url:"", + token:"" + } + + switch(domain){ + case DOMAINS.ENERGY: + DOMAIN_DETAILS = { + url:ENERGY_STRAPI_URL, + token:process.env.STRAPI_ENERGY_TOKEN, + + } + break; + case DOMAINS.RETAIL: + DOMAIN_DETAILS = { + url:RETAIL_STRAPI_URL, + token:process.env.STRAPI_RETAIL_TOKEN, + } + break; + case DOMAINS.HOTEL: + DOMAIN_DETAILS = { + url:HOTEL_STRAPI_URL, + token:process.env.STRAPI_HOTEL_TOKEN, + } + break; + case DOMAINS.TOURISM: + DOMAIN_DETAILS = { + url:TOURISM_STRAPI_URL, + token:process.env.STRAPI_TOURISM_TOKEN, + } + break; + } + const unpublishItemResp = await action.call_api(`${DOMAIN_DETAILS.url}/items/${itemId}`,'PUT',{ + "data":{"publishedAt": null} + },{ Authorization: `Bearer ${DOMAIN_DETAILS.token}`}) + return res.status(200).json({ + status:unpublishItemResp.status, + message: unpublishItemResp.error || 'Item Unpublished' + }) + }catch(error){ + return res.status(400).json({ + status:false, + message:error.message + }) + } } \ No newline at end of file diff --git a/server.js b/server.js index 723c16e..b5e0d0a 100644 --- a/server.js +++ b/server.js @@ -11,7 +11,8 @@ import { cancelBooking, updateCatalog, notify, - updateStatus + updateStatus, + unpublishItem } from './controllers/ControlCenter.js' const app = express() app.use(cors()) @@ -29,6 +30,7 @@ app.post('/cancel-booking', cancelBooking) app.post('/update-catalog', updateCatalog) app.post('/update-status', updateStatus) app.get('/notify-status', messageController.notifyStatusUpdate) +app.post('/unpublish-item', unpublishItem) // Reset all sessions export const db = new DBService()