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

const client = require("../graphql-client/graphql-client").client;

exports.default = async (req, res) => {
  try {
    logger.log("csi-surveyID-submit", "DEBUG", "csi", req.body.surveyId, null);
    const gql_response = await client.request(queries.COMPLETE_SURVEY, {
      surveyId: req.body.surveyId,
      survey: {
        response: req.body.values,
        valid: false,
        completedon: new Date()
      }
    });
    res.status(200).json(gql_response);
  } catch (error) {
    logger.log("csi-surveyID-submit", "ERROR", "csi", req.body.surveyId, error);
    res.status(400).json(error);
  }
};
