Your IP : 216.73.217.95


Current Path : /home/deltalab/PMS/partner-manager-backend/rest/routes/
Upload File :
Current File : //home/deltalab/PMS/partner-manager-backend/rest/routes/buybutton.js

const express = require('express');
const { dotenv } = require('dotenv').config();
const ims = require('../../services/ims');
const { channelModel } = require('../../models/mongoose/channel');

const router = express.Router({ mergeParams: true });

//TODO: fare controlli con il body passato

router.post('/', async (req, res) => {
  try {
    const { productSKUs, channelId } = req.body;
    const channel = await channelModel.findById({ _id: channelId });
    if (!channel) {
      return res.status(400).send({ success: false, message: 'Error creating the buybutton: specified channel does not exist' });
    }

    const buyButton = await ims.getBuyButton(productSKUs, channel);

    return res.status(200).send({ success: true, data: buyButton });
  } catch (error) {
    console.log(error);
    return res.status(400).send({ success: false, message: 'Error creating buybutton' });
  }
});

module.exports = router;