Skip to content

Commit

Permalink
Added: API to Unpublish an Item
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyvishal committed Apr 8, 2024
1 parent 5ed9fb5 commit 8ec1cfe
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
50 changes: 50 additions & 0 deletions controllers/ControlCenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
}
4 changes: 3 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
cancelBooking,
updateCatalog,
notify,
updateStatus
updateStatus,
unpublishItem
} from './controllers/ControlCenter.js'
const app = express()
app.use(cors())
Expand All @@ -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()

Expand Down

0 comments on commit 8ec1cfe

Please sign in to comment.