use transaction check for PatchSubmissionModel

This commit is contained in:
Quaternions 2024-11-27 19:04:24 -08:00
parent f5fb895aeb
commit 86204e877e

View File

@ -128,13 +128,12 @@ func (svc *Service) PatchSubmissionCompleted(ctx context.Context, params api.Pat
func (svc *Service) PatchSubmissionModel(ctx context.Context, params api.PatchSubmissionModelParams) error { func (svc *Service) PatchSubmissionModel(ctx context.Context, params api.PatchSubmissionModelParams) error {
// check if caller has Submitter role // check if caller has Submitter role
// check if Status is ChangesRequested|Submitted|UnderConstruction // check if Status is ChangesRequested|Submitted|UnderConstruction
// PROBLEM how to deal with async? data may become out of date
pmap := datastore.Optional() pmap := datastore.Optional()
pmap.AddNotNil("asset_id", params.ModelID) pmap.AddNotNil("asset_id", params.ModelID)
pmap.AddNotNil("asset_version", params.VersionID) pmap.AddNotNil("asset_version", params.VersionID)
//always reset completed when model changes //always reset completed when model changes
pmap.Add("completed",false) pmap.Add("completed",false)
err := svc.DB.Submissions().Update(ctx, params.SubmissionID, pmap) err := svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.Status{model.StatusChangesRequested,model.StatusSubmitted,model.StatusUnderConstruction}, pmap)
return err return err
} }