PrismaP
Prisma12mo ago
4 replies
ReDev1L

Property '[PrivateResultType]' is missing in type 'TypedSql<Parameters, Result>'

Error:
Argument of type 'TypedSql<Parameters, Result>' is not assignable to parameter of type 'TypedSql<unknown[], Result>'.
  Property '[PrivateResultType]' is missing in type 'TypedSql<Parameters, Result>' but required in type 'TypedSql<unknown[], Result>'.ts(2345)


usage:
    const usageByUser = await db.$queryRawTyped<getUsageByOrgId.Result>(
      getUsageByOrgId(from, to, organizationId.toString())
    )

TypedSQL:
WITH RECURSIVE params(from_period, to_period, organizationId) AS (
  SELECT ? AS from_period, ? AS to_period, ? AS organizationId
),

usage_stats AS (
    SELECT 
        cu.id,
        cu.email,
        SUM(bpu.billable_seconds) as total_seconds,
        SUM(CASE 
            WHEN bpu.created_at >= (SELECT from_period FROM params)
            AND bpu.created_at <= (SELECT to_period FROM params)
            THEN bpu.billable_seconds 
            ELSE 0 
        END) as period_minutes,
        COUNT(DISTINCT bpu.session_id) as total_billed_sessions,
        COUNT(DISTINCT CASE 
            WHEN bpu.created_at >= (SELECT from_period FROM params)
            AND bpu.created_at <= (SELECT to_period FROM params)
            THEN bpu.session_id 
            ELSE NULL 
        END) as period_billed_sessions
    FROM billing_v2_product_usage bpu
    JOIN copilot_user cu ON cu.id = bpu.user_id
    JOIN copilot_organizationuser cou ON cou.user_id = cu.id AND cou.organization_id = (SELECT organizationId FROM params)
    WHERE bpu.created_at >= cou.created_at
        AND cu.id IN (
            SELECT user_id 
            FROM copilot_organizationuser 
            WHERE organization_id = (SELECT organizationId FROM params)
        )
    GROUP BY cu.id, cu.email
)
SELECT 
    id,
    email,
    CASE WHEN total_seconds = 0 OR total_seconds IS NULL THEN 0 ELSE ROUND(total_seconds / 60) END AS total_minutes,
    CASE WHEN period_minutes = 0 OR period_minutes IS NULL THEN 0 ELSE ROUND(period_minutes / 60) END AS period_minutes,
    total_billed_sessions,
    period_billed_sessions
FROM usage_stats
ORDER BY total_minutes DESC;

Generated types:
export const getUsageByOrgId: (from_period: Date, to_period: Date, organizationId: string) => $runtime.TypedSql<getUsageByOrgId.Parameters, getUsageByOrgId.Result>

export namespace getUsageByOrgId {
  export type Parameters = [from_period: Date, to_period: Date, organizationId: string]
  export type Result = {
    id: bigint
    email: string
    total_minutes: $runtime.Decimal | null
    period_minutes: $runtime.Decimal | null
    total_billed_sessions: bigint
    period_billed_sessions: bigint
  }
}


How to fix this error?
Was this page helpful?