From 3bfb8fe9191deeea5e6ba63a5d8ce1f9696dd3d2 Mon Sep 17 00:00:00 2001 From: Gisle Aune Date: Wed, 19 Sep 2018 18:54:23 +0200 Subject: [PATCH] api: Added editChapter mutation --- rpdata/api/Chapter.js | 51 ++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/rpdata/api/Chapter.js b/rpdata/api/Chapter.js index ef3e754..260022c 100644 --- a/rpdata/api/Chapter.js +++ b/rpdata/api/Chapter.js @@ -19,35 +19,50 @@ class Chapter { this.fictionalDate = fictionalDate != null ? new Date(fictionalDate) : null this.editedDate = new Date(editedDate) } +} +const chapterApi = { /** - * Query the chapter's editable fields and update this object. This promise returns a boolean - * whether there has been a change. + * Call `editChapter(input)` mutation * - * @returns {Promise} `true` if the story was edited in the meantime + * @param {{id:string, title:string, fictionalDate:Date, source: string}} input + * @returns {Promise<{title:string, fictionalDate:Date, source:string}>} */ - update() { + editChapter(input) { return query(` - query UpdateChapter($id: String!) { - update: chapter(id: $id) { + mutation EditChapter($input: ChapterEditInput!) { + editChapter(input: $input) { title - source fictionalDate - editedDate + source } } - `, {id: this.id}).then(({update}) => { - const editedDate = new Date(udpate.editedDate) - const wasEdited = editedDate.getTime() != this.editedDate.getTime() + `, {input}, {permissions: ["member", "story.edit"]}).then(({editChapter}) => { + if (editChapter.fictionalDate != null) { + editChapter.fictionalDate = new Date(editChapter.fictionalDate) + } - this.title = update.title - this.source = update.source - this.fictionalDate = new Date(update.fictionalDate) - this.editedDate = editedDate + return editChapter + }) + }, - return wasEdited + /** + * Call `removeChapter(input)` mutation + * + * @param {{id:string}} input + * @returns {Promise<{id: string}>} + */ + removeChapter(input) { + return query(` + mutation RemoveChapter($input: ChapterRemoveInput!) { + removeChapter(input: $input) { + id + } + } + `, {input}, {permissions: ["member", "story.edit"]}).then(({removeChapter}) => { + return removeChapter }) - } + }, } -module.exports = {Chapter} \ No newline at end of file +module.exports = {Chapter, chapterApi} \ No newline at end of file