Fix error when mapping already exist

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2025-07-26 17:07:57 +04:00
parent 3befb9e986
commit d87dfa439c
2 changed files with 1 additions and 32 deletions

View File

@@ -68,37 +68,6 @@ ON CONFLICT (control_id, measure_id) DO NOTHING;
return err
}
func (cm ControlMeasure) Insert(
ctx context.Context,
conn pg.Conn,
scope Scoper,
) error {
q := `
INSERT INTO
controls_measures (
control_id,
measure_id,
tenant_id,
created_at
)
VALUES (
@control_id,
@measure_id,
@tenant_id,
@created_at
);
`
args := pgx.StrictNamedArgs{
"control_id": cm.ControlID,
"measure_id": cm.MeasureID,
"tenant_id": scope.GetTenantID(),
"created_at": cm.CreatedAt,
}
_, err := conn.Exec(ctx, q, args)
return err
}
func (cm ControlMeasure) Delete(
ctx context.Context,
conn pg.Conn,

View File

@@ -370,7 +370,7 @@ func (s ControlService) CreateMeasureMapping(
return fmt.Errorf("cannot load measure: %w", err)
}
return controlMeasure.Insert(ctx, conn, s.svc.scope)
return controlMeasure.Upsert(ctx, conn, s.svc.scope)
},
)