Fix error when mapping already exist
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user