feat: complete phase2 baseline cdr quality rbac

This commit is contained in:
hectorzhao
2026-06-24 18:40:21 +08:00
parent 7057fd3c42
commit a86de6545f
63 changed files with 7853 additions and 3678 deletions
+27 -9
View File
@@ -176,20 +176,25 @@ class PrismaCdrRatingTransaction implements CdrRatingTransaction {
id: rawCdrId,
eventId: storageEventId(event.event_id),
callId: event.call_id,
customerId: nullableId(event.customer_id),
customerGatewayId: nullableId(event.customer_gateway_id),
customerGatewayPolicyId: nullableId(event.customer_gateway_policy_id),
customerId: normalizeCdrNullableId(event.customer_id),
customerGatewayId: normalizeCdrNullableId(event.customer_gateway_id),
customerGatewayPolicyId: normalizeCdrNullableId(event.customer_gateway_policy_id),
sourceIp: emptyToNull(event.source_ip),
caller: event.caller || 'unknown',
callee: event.callee || 'unknown',
rawCallee: emptyToNull(event.raw_callee),
businessPrefixId: normalizeCdrNullableId(event.business_prefix_id),
businessPrefix: emptyToNull(event.business_prefix),
calleeCityCode: emptyToNull(event.callee_city_code),
calleeCityName: emptyToNull(event.callee_city_name),
calleeProvinceName: emptyToNull(event.callee_province_name),
calleeOperator: numberCarrier(event.callee_operator),
calleeNumberType: phoneNumberType(event.callee_number_type),
vendorId: nullableId(event.vendor_id),
vendorGatewayId: nullableId(event.vendor_gateway_id),
lineGroupId: nullableId(event.line_group_id),
vendorId: normalizeCdrNullableId(event.vendor_id),
vendorGatewayId: normalizeCdrNullableId(event.vendor_gateway_id),
lineGroupId: normalizeCdrNullableId(event.line_group_id),
landingCaller: emptyToNull(event.landing_caller),
landingCallee: emptyToNull(event.landing_callee),
startedAt: parseCdrDate(event.started_at, event.created_at),
answeredAt: parseOptionalCdrDate(event.answered_at),
endedAt: parseCdrDate(event.ended_at, event.created_at),
@@ -274,12 +279,19 @@ function prefixedId(prefix: string): string {
}
function billableId(value: string): boolean {
return Boolean(nullableId(value));
return Boolean(normalizeCdrNullableId(value));
}
function nullableId(value: string): string | null {
export function normalizeCdrNullableId(value: string): string | null {
const normalized = value.trim();
if (!normalized || normalized === 'none' || normalized === 'unknown' || normalized === 'no_active_version') {
if (
!normalized ||
normalized === 'none' ||
normalized === 'unknown' ||
normalized === 'no_active_version' ||
normalized === 'no_policy_match' ||
normalized === 'single_gateway'
) {
return null;
}
return normalized;
@@ -330,6 +342,12 @@ function eventToJson(event: ParsedCdrStreamEvent): Prisma.InputJsonValue {
source_ip: event.source_ip,
caller: event.caller,
callee: event.callee,
raw_callee: event.raw_callee,
business_prefix_id: event.business_prefix_id,
business_prefix: event.business_prefix,
landing_caller: event.landing_caller,
landing_callee: event.landing_callee,
normalized_callee: event.normalized_callee,
callee_city_code: event.callee_city_code,
callee_city_name: event.callee_city_name,
callee_province_name: event.callee_province_name,