{"size": 1612, "ext": "js", "max_stars_repo_path": "servers/controllers/Utterance.controller.js", "max_stars_repo_name": "polo33333/chatbot_server_22012022", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "servers/controllers/Utterance.controller.js", "max_issues_repo_name": "polo33333/chatbot_server_22012022", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "servers/controllers/Utterance.controller.js", "max_forks_repo_name": "polo33333/chatbot_server_22012022", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.3090909091, "max_line_length": 78, "alphanum_fraction": 0.547146402}
const sR = require('../functions/M_SendResponse.function');
const message = require('../functions/C_String.function');
const P_Wit = require('../functions/P_Wit.function');

module.exports = {

    // get all with intentId
    getAll: async (req, res) => {
        try {

            let { botId } = req.params;
            let r = await P_Wit.getUtterances(botId);
            return sR.sendResponse(res, 200, r, message.getSuccess);

        } catch (error) {

            console.log('Error[UnknowRequest:getAll]: ' + error);
            return sR.sendResponse(res, 400, null, error);
        }
    },

    getByIntent: async (req, res) => {
        try {

            let { botId, intent } = req.params;
            let r = await P_Wit.getUtterancesByIntent(botId, intent, 5);
            return sR.sendResponse(res, 200, r, message.getSuccess);

        } catch (error) {

            console.log('Error[UnknowRequest:getByIntent]: ' + error);
            return sR.sendResponse(res, 400, null, error);
        }
    },

    // remove method with id
    remove: async (req, res) => {
        try {

            let { botId } = req.params;
            let obj = req.body;
            let r = await P_Wit.deleteUtterances([{ text: obj.text }], botId);
            if (r) {
                return sR.sendResponse(res, 200, null, message.deleteSuccess);
            }
            return sR.sendResponse(res, 400, null, message.deleteFail);

        } catch (error) {

            console.log('Error[UnknowRequest:remove]: ' + error);
            return sR.sendResponse(res, 400, null, error);
        }

    }
}