def rest_del_blsAlarms(request):
    try:

        payload = get_payload(request)
        data = payload.get("data", [])
        res = []
        ret = {}
        modcrud = getCrud()
        for obj in data:

            device_id, eventtime = get_keys_blsAlarms(obj)
            result = get_blsalarms(device_id, eventtime)

            for item in result:
                item.activo = 0
                item.modificacion_crud = modcrud
                item.save()
                res.append("{}".format((item.device_id, item.eventtime)))

        ret["meta"] = getMeta(request, len(res))
        ret["data"] = res
        config.log.Info("Response: {0}".format(ret))
        return getResponse(
            request,
            JsonResponse(ret, content_type='application/json; charset=utf-8'))

    except Exception as e:
        status = 400
        ret = getErrorResponse(status, e, request)
        return getResponse(
            request,
            JsonResponse(ret,
                         content_type='application/json; charset=utf-8',
                         status=status))
def rest_get_blsAlarms(request):
    try:

        payload = get_payload(request)
        data = payload.get("data", [])
        res = []
        ret = {}
        for obj in data:
            device_id, eventtime = get_keys_blsAlarms(obj)
            result = get_blsalarms(device_id, eventtime)
            res = res + jsonify(result)

        ret["meta"] = getMeta(request, len(res))
        ret["data"] = res
        config.log.Info("Response: {0}".format(ret))
        return getResponse(
            request,
            JsonResponse(ret, content_type='application/json; charset=utf-8'))

    except Exception as e:
        status = 400
        ret = getErrorResponse(status, e, request)
        return getResponse(
            request,
            JsonResponse(ret,
                         content_type='application/json; charset=utf-8',
                         status=status))
    def resolve_blsAlarms(self, info, device_id, eventtime=None, **kwargs):

        if device_id is not None:
            result = get_blsalarms(device_id, eventtime)
        else:
            result = None

        return result
    def mutate(self, info, blsAlarms_data=None):
        result = get_blsalarms(device_id=blsAlarms_data.device_id,
                               eventtime=blsAlarms_data.eventtime)
        status = False
        for r in result:
            r.activo = 0
            r.modificacion_crud = getCrud()
            r.save()
            status = True

        return delete_Blsalarms(status=status)
    def resolve_blsAlarms_all(self, info, device_id, eventtime=None, **kwargs):

        complete = BlsalarmsType_all()

        if device_id is not None:
            result = get_blsalarms(device_id, eventtime)
        else:
            result = None

        complete.total_count = len(result)
        complete.blsalarms = result

        return complete