'use strict';
var express = require('express');
var inspect = require('util').inspect;
var connect = require('../../../models/maria.js');
var c = new connect.maria();

exports.getAdminReplies = function (req, res) {

    var data = req.body;
    var adminId = req.body.adminId;
    var catId = req.body.catId;

    if(catId)
      var baseQuery = 'select * from predefinedreplies where adminID = ' + adminId + ' and categoryID = ' + catId + ' ';
    else
      var baseQuery = 'select * from predefinedreplies where adminID = ' + adminId + '';


    var data = [];
    c.query(baseQuery)
            .on('result', function (resrow) {
                resrow.on('row', function (row) {
                    data.push(row)
                }).on('error', function (err) {
                    console.log('Result error in getAdminReplies: ' + inspect(err));
                }).on('end', function (info) {
                    res.json({
                        Data: data,
                        code: 200
                    });
                    console.log('Result finished successfully');
                });
            })
}
