Make risk delete prove document mapping cleanup
Removing junction rows before deleteRisk hid missing soft-delete cleanup in e2e. Assert deleteRisk succeeds only after deleteDocument clears mappings, and document links must be removed first. Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
This commit is contained in:
committed by
Bryan Frimin
parent
24d137e536
commit
255bea4738
@@ -108,33 +108,6 @@ WHERE
|
||||
return err
|
||||
}
|
||||
|
||||
func (rp RiskDocument) DeleteByRiskID(
|
||||
ctx context.Context,
|
||||
conn pg.Tx,
|
||||
scope Scoper,
|
||||
riskID gid.GID,
|
||||
) error {
|
||||
q := `
|
||||
DELETE
|
||||
FROM
|
||||
risks_documents
|
||||
WHERE
|
||||
%s
|
||||
AND risk_id = @risk_id;
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"risk_id": riskID,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (rp RiskDocument) DeleteByDocumentIDs(
|
||||
ctx context.Context,
|
||||
conn pg.Tx,
|
||||
|
||||
@@ -612,15 +612,10 @@ func (s RiskService) Delete(
|
||||
riskID gid.GID,
|
||||
) error {
|
||||
risk := &coredata.Risk{}
|
||||
riskDocument := &coredata.RiskDocument{}
|
||||
|
||||
return s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(ctx context.Context, tx pg.Tx) error {
|
||||
if err := riskDocument.DeleteByRiskID(ctx, tx, scope, riskID); err != nil {
|
||||
return fmt.Errorf("cannot delete risk document mappings: %w", err)
|
||||
}
|
||||
|
||||
return risk.Delete(ctx, tx, scope, riskID)
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user