{"size": 2211, "ext": "js", "max_stars_repo_path": "packages/rocketchat-livechat/imports/server/rest/transferir.js", "max_stars_repo_name": "eckenbre/rocketchat_v2", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "packages/rocketchat-livechat/imports/server/rest/transferir.js", "max_issues_repo_name": "eckenbre/rocketchat_v2", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/rocketchat-livechat/imports/server/rest/transferir.js", "max_forks_repo_name": "eckenbre/rocketchat_v2", "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": 24.0326086957, "max_line_length": 120, "alphanum_fraction": 0.657620986}
RocketChat.API.v1.addRoute('livechat/transferir', { authRequired: true }, {
	post() {
		if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) {
			return RocketChat.API.v1.unauthorized();
		}
		try {



      //const departamento = this.bodyParams.depto;
    //  const salaId = this.bodyParams.roomId;
    const transferirData = this.bodyParams;
      check(transferirData, {
  			roomId: String,
  			userId: Match.Optional(String),
  			departmentId: Match.Optional(String)
  		});

       const retorno = "Exito";
      Meteor.call('livechat:transfer', transferirData, (error, result) => {
			if (error) {

				SystemLogger.error('---- HSBC Error al transferir ->: ', error.error);
				return RocketChat.API.v1.failure(error);
			} else if (result) {

				return RocketChat.API.v1.success(result);
			} else {
				//console.log("No_available_agents_to_transfer");

			}
		});




		} catch (e) {
			console.log(e.error);
			return RocketChat.API.v1.failure(e.error);
		}
	}
	/*
	,

	get() {
		if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) {
			return RocketChat.API.v1.unauthorized();
		}

		return RocketChat.API.v1.success({
			users: RocketChat.models.Users.find({"operator": true, "statusLivechat" : "available", "status" : "online" }).fetch()
		});
	},
	*/
});

RocketChat.API.v1.addRoute('livechat/availableOperators', { authRequired: true }, {
get() {
		if (!RocketChat.authz.hasPermission(this.userId, 'view-livechat-manager')) {
			return RocketChat.API.v1.unauthorized();
		}
		var availableOperators = false;
		const availableOper = RocketChat.models.Users.find({
$and:[{ "roles" : "livechat-agent"}, {"status" : "online" }, {"roles" : {$ne: "bot"}}]
	  }).fetch();
    if(availableOper.length > 0){
			availableOperators = true;

		}

		return RocketChat.API.v1.success({
			availableOperators
		});
	}
});

RocketChat.API.v1.addRoute('livechat/checkWorkingHours', { authRequired: true}, {
get() {
		var inWorkingHours = false;
    const checkingData = this.bodyParams;

		if (RocketChat.models.LivechatOfficeHour.isNowWithinHours()) {
			inWorkingHours = true;
		}
		else{
		}
		return RocketChat.API.v1.success({
			inWorkingHours
		});
	}
});
