Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update document number when patching product of a draft document #113

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion internal/api/drafts.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ func DraftsDocumentHandler(
}

// Validate product if it is in the patch request.
var productAbbreviation string
if req.Product != "" {
p := models.Product{Name: req.Product}
if err := p.Get(db); err != nil {
Expand All @@ -649,6 +650,10 @@ func DraftsDocumentHandler(
http.StatusBadRequest)
return
}

// Set product abbreviation because we use this later to update the
// doc number in the Algolia object.
productAbbreviation = p.Abbreviation
}

// Compare contributors in request and stored object in Algolia
Expand Down Expand Up @@ -735,8 +740,9 @@ func DraftsDocumentHandler(
"contributors_count", len(contributorsToRemoveSharing))
}

// Update product in the database (if it is in the patch request).
// Update product (if it is in the patch request).
if req.Product != "" {
// Update in database.
d := models.Document{
GoogleFileID: docId,
Product: models.Product{Name: req.Product},
Expand All @@ -752,6 +758,9 @@ func DraftsDocumentHandler(
http.StatusInternalServerError)
return
}

// Update doc number in Algolia object.
docObj.SetDocNumber(fmt.Sprintf("%s-???", productAbbreviation))
}

// Save new modified draft doc object in Algolia.
Expand Down