const client = require("../graphql-client/graphql-client").client;
const queries = require("../graphql-client/queries");
const path = require("path");
const logger = require("../utils/logger");

require("dotenv").config({
  path: path.resolve(
    process.cwd(),
    `.env.${process.env.NODE_ENV || "development"}`
  ),
});

exports.default = async (req, res) => {
  const { operationName, time, dbevent, user, imexshopid } = req.body;

  try {
    // await client.request(queries.INSERT_IOEVENT, {
    //   event: {
    //     operationname: operationName,
    //     time,
    //     dbevent,
    //   },
    // });
    console.log("IOEVENT", operationName, time, dbevent, user, imexshopid);
    logger.log("ioevent", "trace", user, null, {
      imexshopid,
      operationName,
      time,
      dbevent,
    });

    res.sendStatus(200);
  } catch (error) {
    console.log("error", error);
    res.status(400).send(error);
  }
};
