graph2: Added move mutation to chapter.
the build was successful

This commit is contained in:
2018-10-27 14:59:47 +02:00
parent cf545cde3b
commit 9affdbd20e
4 changed files with 63 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
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 models.Chapter{}, 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
}