GraphQL API and utilities for the rpdata project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

28 lines
686 B

package chapters
import (
"time"
"git.aiterp.net/rpdata/api/models"
"github.com/globalsign/mgo/bson"
)
// Move updates the chapter, moving it to the given story.
func Move(chapter models.Chapter, story models.Story) (*models.Chapter, error) {
now := time.Now()
err := collection.UpdateId(chapter.ID, bson.M{"$set": bson.M{"editedDate": now, "storyId": story.ID}})
if err != nil {
return nil, err
}
chapter.EditedDate = now
if chapter.CreatedDate.After(story.UpdatedDate) {
if err := storyCollection.UpdateId(story.ID, bson.M{"$set": bson.M{"updatedDate": chapter.CreatedDate}}); err == nil {
story.UpdatedDate = chapter.CreatedDate
}
}
return &chapter, nil
}