Skip to content

Commit

Permalink
Reset document created date when publishing a doc (#632)
Browse files Browse the repository at this point in the history
* Fix the field used for Created

* Reset document created date when publishing a doc
  • Loading branch information
jfreda authored Mar 5, 2024
1 parent a086ed1 commit b09f182
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions internal/api/v2/reviews.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ func ReviewsHandler(srv server.Server) http.Handler {
return
}

// Reset the document creation time to the current time of publish.
now := time.Now()
doc.Created = now.Format("Jan 2, 2006")
doc.CreatedTime = now.Unix()

// Set the document number.
nextDocNum := latestNum + 1
doc.DocNumber = fmt.Sprintf("%s-%03d",
Expand Down Expand Up @@ -459,6 +464,7 @@ func ReviewsHandler(srv server.Server) http.Handler {
}
return
}
d.DocumentCreatedAt = now // Reset to document published time.
d.Status = models.InReviewDocumentStatus
d.DocumentNumber = nextDocNum
d.DocumentModifiedAt = modifiedTime
Expand Down
2 changes: 1 addition & 1 deletion pkg/document/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func NewFromDatabaseModel(
doc.Contributors = contributors

// Created.
doc.Created = model.CreatedAt.Format("Jan 2, 2006")
doc.Created = model.DocumentCreatedAt.Format("Jan 2, 2006")

// CreatedTime.
doc.CreatedTime = model.DocumentCreatedAt.Unix()
Expand Down

0 comments on commit b09f182

Please sign in to comment.