api: Added editChapter mutation
This commit is contained in:
+45
-30
@@ -19,35 +19,50 @@ class Chapter {
|
|||||||
this.fictionalDate = fictionalDate != null ? new Date(fictionalDate) : null
|
this.fictionalDate = fictionalDate != null ? new Date(fictionalDate) : null
|
||||||
this.editedDate = new Date(editedDate)
|
this.editedDate = new Date(editedDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Query the chapter's editable fields and update this object. This promise returns a boolean
|
|
||||||
* whether there has been a change.
|
|
||||||
*
|
|
||||||
* @returns {Promise<boolean>} `true` if the story was edited in the meantime
|
|
||||||
*/
|
|
||||||
update() {
|
|
||||||
return query(`
|
|
||||||
query UpdateChapter($id: String!) {
|
|
||||||
update: chapter(id: $id) {
|
|
||||||
title
|
|
||||||
source
|
|
||||||
fictionalDate
|
|
||||||
editedDate
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`, {id: this.id}).then(({update}) => {
|
|
||||||
const editedDate = new Date(udpate.editedDate)
|
|
||||||
const wasEdited = editedDate.getTime() != this.editedDate.getTime()
|
|
||||||
|
|
||||||
this.title = update.title
|
|
||||||
this.source = update.source
|
|
||||||
this.fictionalDate = new Date(update.fictionalDate)
|
|
||||||
this.editedDate = editedDate
|
|
||||||
|
|
||||||
return wasEdited
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {Chapter}
|
const chapterApi = {
|
||||||
|
/**
|
||||||
|
* Call `editChapter(input)` mutation
|
||||||
|
*
|
||||||
|
* @param {{id:string, title:string, fictionalDate:Date, source: string}} input
|
||||||
|
* @returns {Promise<{title:string, fictionalDate:Date, source:string}>}
|
||||||
|
*/
|
||||||
|
editChapter(input) {
|
||||||
|
return query(`
|
||||||
|
mutation EditChapter($input: ChapterEditInput!) {
|
||||||
|
editChapter(input: $input) {
|
||||||
|
title
|
||||||
|
fictionalDate
|
||||||
|
source
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`, {input}, {permissions: ["member", "story.edit"]}).then(({editChapter}) => {
|
||||||
|
if (editChapter.fictionalDate != null) {
|
||||||
|
editChapter.fictionalDate = new Date(editChapter.fictionalDate)
|
||||||
|
}
|
||||||
|
|
||||||
|
return editChapter
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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, chapterApi}
|
||||||
Reference in New Issue
Block a user