This commit is contained in:
@@ -8,7 +8,7 @@ namespace AyaNova.KPI
|
||||
AuthorizationRoles AllowedRoles { get; }
|
||||
|
||||
//build the data and meta queries based on the criteria and this kpi's standard query
|
||||
void BuildQuery(string criteria, DateTimeOffset clientTimeStamp);
|
||||
void BuildQuery(KPIRequestOptions options);
|
||||
string MetaQuery{get;}//Query to fetch json meta data for report purposes mainly (lookup stuff like names etc where applicable)
|
||||
string DataQuery{get;}//Query to fetch json format data for result set
|
||||
string ErrorMessage{get;}//if there was a problem then this is set with the error message
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace AyaNova.KPI
|
||||
// Get the kpi data requested
|
||||
//
|
||||
//
|
||||
internal static async Task<JObject> GetResponseAsync(AyContext ct, string kpiName, string criteria, DateTimeOffset clientTimeStamp, AuthorizationRoles userRoles, ILogger log, long userId)
|
||||
internal static async Task<JObject> GetResponseAsync(AyContext ct, KPIRequestOptions options, AuthorizationRoles userRoles, ILogger log, long userId)
|
||||
{
|
||||
|
||||
/*
|
||||
@@ -30,8 +30,17 @@ namespace AyaNova.KPI
|
||||
}
|
||||
*/
|
||||
//instantiate the list
|
||||
var kpi = KPIFactory.GetAyaKPI(kpiName);
|
||||
kpi.BuildQuery(criteria, clientTimeStamp);
|
||||
var kpi = KPIFactory.GetAyaKPI(options.KPIName);
|
||||
|
||||
if (!AyaNova.Api.ControllerHelpers.Authorized.HasAnyRole(userRoles, kpi.AllowedRoles))
|
||||
{
|
||||
return JObject.FromObject(new
|
||||
{
|
||||
error = "NOT AUTHORIZED"
|
||||
});
|
||||
}
|
||||
|
||||
kpi.BuildQuery(options);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(kpi.ErrorMessage))
|
||||
{
|
||||
|
||||
29
server/AyaNova/kpi/KPIRequestOptions.cs
Normal file
29
server/AyaNova/kpi/KPIRequestOptions.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
|
||||
namespace AyaNova.KPI
|
||||
{
|
||||
|
||||
//string kpiName, string criteria, DateTimeOffset clientTimeStamp
|
||||
|
||||
|
||||
public sealed class KPIRequestOptions
|
||||
{
|
||||
|
||||
[FromBody]
|
||||
public string KPIName { get; set; }
|
||||
|
||||
[FromBody]
|
||||
public string Criteria { get; set; }
|
||||
|
||||
[FromBody]
|
||||
public DateTimeOffset Template { get; set; }
|
||||
|
||||
public KPIRequestOptions()
|
||||
{
|
||||
KPIName=string.Empty;
|
||||
Criteria=string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,17 +10,31 @@ namespace AyaNova.KPI
|
||||
{
|
||||
private string _metaQuery = null;
|
||||
private string _dataQuery = null;
|
||||
private string _errorMessage=null;
|
||||
private string _errorMessage = null;
|
||||
|
||||
public AuthorizationRoles AllowedRoles { get => BizRoles.GetRoleSet(AyaType.WorkOrderItemLabor).ReadFullRecord; }
|
||||
|
||||
|
||||
public string MetaQuery => _metaQuery;
|
||||
public string DataQuery => _dataQuery;
|
||||
public string ErrorMessage => _errorMessage;
|
||||
|
||||
public void BuildQuery(string criteria, DateTimeOffset clientTimeStamp)
|
||||
public void BuildQuery(KPIRequestOptions options)
|
||||
{
|
||||
//build data and meta queries
|
||||
|
||||
_dataQuery = @"SELECT row_to_json(t) as res from (
|
||||
select SUM(AWORKORDERITEMLABOR.serviceratequantity) SERVICERATESUM, date_trunc('month',AWORKORDERITEMLABOR.servicestartdate) timeframe
|
||||
FROM AWORKORDER
|
||||
LEFT JOIN AWORKORDERITEM ON AWORKORDER.ID = AWORKORDERITEM.WORKORDERID
|
||||
LEFT JOIN AWORKORDERITEMLABOR ON AWORKORDERITEM.ID = AWORKORDERITEMLABOR.WORKORDERITEMID
|
||||
WHERE AWORKORDERITEMLABOR.userid = 10
|
||||
GROUP BY timeframe
|
||||
ORDER BY timeframe ASC
|
||||
) t";
|
||||
|
||||
_metaQuery = @"SELECT row_to_json(t) as res from (
|
||||
select name from auser where id = 10
|
||||
) t";
|
||||
}
|
||||
|
||||
// public string GetVariantCriteria(string variant)
|
||||
|
||||
Reference in New Issue
Block a user