const sequelize = require("../config/dbconnection");
const Sequelize = require("sequelize");

const getAllCalls = async (userType) => {
    let sql = `SELECT c.id, c.name, c.parent_category_id, c.parent_id, c.call_status_id,`+
    ` c.direction_id, c.start_date_time, c.end_date_time, c.duration_id, c.description, c.updated_by, c.updated_time, `+
    ` c.status, CONCAT(COALESCE(u.first_name,''),' ',COALESCE(u.last_name,'')) as added_by`+
    ` FROM calls c`+
    ` LEFT JOIN users u ON c.updated_by=u.id`+
    ` WHERE c.status != 2`
    if(userType != 1)
    {
        sql += ` AND c.added_by = ${userType}`
    }
    sql += ` ORDER BY c.updated_time DESC`
    let result = await sequelize.query(sql);
	if(result){
		if(result[0] > 0){
			return result[0];
        }
    }
}

module.exports = {getAllCalls}