Add missing validation on relation existence
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -189,6 +189,10 @@ func (s AssetService) Update(
|
|||||||
asset.Amount = *req.Amount
|
asset.Amount = *req.Amount
|
||||||
}
|
}
|
||||||
if req.OwnerID != nil {
|
if req.OwnerID != nil {
|
||||||
|
people := &coredata.People{}
|
||||||
|
if err := people.LoadByID(ctx, conn, s.svc.scope, *req.OwnerID); err != nil {
|
||||||
|
return fmt.Errorf("cannot load owner: %w", err)
|
||||||
|
}
|
||||||
asset.OwnerID = *req.OwnerID
|
asset.OwnerID = *req.OwnerID
|
||||||
}
|
}
|
||||||
if req.AssetType != nil {
|
if req.AssetType != nil {
|
||||||
@@ -243,6 +247,11 @@ func (s AssetService) Create(
|
|||||||
}
|
}
|
||||||
|
|
||||||
err := s.svc.pg.WithTx(ctx, func(conn pg.Conn) error {
|
err := s.svc.pg.WithTx(ctx, func(conn pg.Conn) error {
|
||||||
|
people := &coredata.People{}
|
||||||
|
if err := people.LoadByID(ctx, conn, s.svc.scope, req.OwnerID); err != nil {
|
||||||
|
return fmt.Errorf("cannot load owner: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := asset.Insert(ctx, conn, s.svc.scope); err != nil {
|
if err := asset.Insert(ctx, conn, s.svc.scope); err != nil {
|
||||||
return fmt.Errorf("cannot insert asset: %w", err)
|
return fmt.Errorf("cannot insert asset: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -196,6 +196,10 @@ func (s DatumService) Update(
|
|||||||
datum.DataClassification = *req.DataClassification
|
datum.DataClassification = *req.DataClassification
|
||||||
}
|
}
|
||||||
if req.OwnerID != nil {
|
if req.OwnerID != nil {
|
||||||
|
people := &coredata.People{}
|
||||||
|
if err := people.LoadByID(ctx, conn, s.svc.scope, *req.OwnerID); err != nil {
|
||||||
|
return fmt.Errorf("cannot load owner: %w", err)
|
||||||
|
}
|
||||||
datum.OwnerID = *req.OwnerID
|
datum.OwnerID = *req.OwnerID
|
||||||
}
|
}
|
||||||
datum.UpdatedAt = now
|
datum.UpdatedAt = now
|
||||||
@@ -245,6 +249,11 @@ func (s DatumService) Create(
|
|||||||
err := s.svc.pg.WithTx(
|
err := s.svc.pg.WithTx(
|
||||||
ctx,
|
ctx,
|
||||||
func(conn pg.Conn) error {
|
func(conn pg.Conn) error {
|
||||||
|
people := &coredata.People{}
|
||||||
|
if err := people.LoadByID(ctx, conn, s.svc.scope, req.OwnerID); err != nil {
|
||||||
|
return fmt.Errorf("cannot load owner: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := datum.Insert(ctx, conn, s.svc.scope); err != nil {
|
if err := datum.Insert(ctx, conn, s.svc.scope); err != nil {
|
||||||
return fmt.Errorf("cannot insert datum: %w", err)
|
return fmt.Errorf("cannot insert datum: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -209,9 +209,19 @@ func (s *NonconformityService) Update(
|
|||||||
nonconformity.CorrectiveAction = *req.CorrectiveAction
|
nonconformity.CorrectiveAction = *req.CorrectiveAction
|
||||||
}
|
}
|
||||||
if req.OwnerID != nil {
|
if req.OwnerID != nil {
|
||||||
|
people := &coredata.People{}
|
||||||
|
if err := people.LoadByID(ctx, conn, s.svc.scope, *req.OwnerID); err != nil {
|
||||||
|
return fmt.Errorf("cannot load owner: %w", err)
|
||||||
|
}
|
||||||
nonconformity.OwnerID = *req.OwnerID
|
nonconformity.OwnerID = *req.OwnerID
|
||||||
}
|
}
|
||||||
if req.AuditID != nil {
|
if req.AuditID != nil {
|
||||||
|
if *req.AuditID != nil {
|
||||||
|
audit := &coredata.Audit{}
|
||||||
|
if err := audit.LoadByID(ctx, conn, s.svc.scope, **req.AuditID); err != nil {
|
||||||
|
return fmt.Errorf("cannot load audit: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
nonconformity.AuditID = *req.AuditID
|
nonconformity.AuditID = *req.AuditID
|
||||||
}
|
}
|
||||||
if req.DueDate != nil {
|
if req.DueDate != nil {
|
||||||
|
|||||||
@@ -111,6 +111,19 @@ func (s TaskService) Create(
|
|||||||
err = s.svc.pg.WithTx(
|
err = s.svc.pg.WithTx(
|
||||||
ctx,
|
ctx,
|
||||||
func(conn pg.Conn) error {
|
func(conn pg.Conn) error {
|
||||||
|
if req.MeasureID != nil {
|
||||||
|
measure := &coredata.Measure{}
|
||||||
|
if err := measure.LoadByID(ctx, conn, s.svc.scope, *req.MeasureID); err != nil {
|
||||||
|
return fmt.Errorf("cannot load measure: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.AssignedToID != nil {
|
||||||
|
people := &coredata.People{}
|
||||||
|
if err := people.LoadByID(ctx, conn, s.svc.scope, *req.AssignedToID); err != nil {
|
||||||
|
return fmt.Errorf("cannot load assignee: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := task.Insert(ctx, conn, s.svc.scope); err != nil {
|
if err := task.Insert(ctx, conn, s.svc.scope); err != nil {
|
||||||
return fmt.Errorf("cannot insert task: %w", err)
|
return fmt.Errorf("cannot insert task: %w", err)
|
||||||
@@ -159,6 +172,11 @@ func (s TaskService) Assign(
|
|||||||
return fmt.Errorf("cannot load task %q: %w", taskID, err)
|
return fmt.Errorf("cannot load task %q: %w", taskID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
people := &coredata.People{}
|
||||||
|
if err := people.LoadByID(ctx, conn, s.svc.scope, assignedToID); err != nil {
|
||||||
|
return fmt.Errorf("cannot load assignee: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
task.AssignedToID = &assignedToID
|
task.AssignedToID = &assignedToID
|
||||||
task.UpdatedAt = time.Now()
|
task.UpdatedAt = time.Now()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user