@@ -385,44 +385,6 @@ WHERE
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *Audits) CountByControlID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
controlID gid.GID,
|
||||
) (int, error) {
|
||||
q := `
|
||||
WITH audits_by_control AS (
|
||||
SELECT
|
||||
a.id,
|
||||
a.tenant_id
|
||||
FROM
|
||||
audits a
|
||||
INNER JOIN
|
||||
controls_audits ca ON a.id = ca.audit_id
|
||||
WHERE
|
||||
ca.control_id = @control_id
|
||||
)
|
||||
SELECT
|
||||
COUNT(id)
|
||||
FROM
|
||||
audits_by_control
|
||||
WHERE %s
|
||||
`
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"control_id": controlID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
row := conn.QueryRow(ctx, q, args)
|
||||
|
||||
var count int
|
||||
if err := row.Scan(&count); err != nil {
|
||||
return 0, fmt.Errorf("cannot scan count: %w", err)
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (a *Audits) LoadByControlID(
|
||||
ctx context.Context,
|
||||
|
||||
Reference in New Issue
Block a user