|
@ -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) |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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<boolean>} `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(`
|
|
|
return query(`
|
|
|
query UpdateChapter($id: String!) { |
|
|
|
|
|
update: chapter(id: $id) { |
|
|
|
|
|
|
|
|
mutation EditChapter($input: ChapterEditInput!) { |
|
|
|
|
|
editChapter(input: $input) { |
|
|
title |
|
|
title |
|
|
source |
|
|
|
|
|
fictionalDate |
|
|
fictionalDate |
|
|
editedDate |
|
|
|
|
|
|
|
|
source |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
`, {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 |
|
|
|
|
|
|
|
|
`, {input}, {permissions: ["member", "story.edit"]}).then(({editChapter}) => {
|
|
|
|
|
|
if (editChapter.fictionalDate != null) { |
|
|
|
|
|
editChapter.fictionalDate = new Date(editChapter.fictionalDate) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return wasEdited |
|
|
|
|
|
|
|
|
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} |
|
|
|
|
|
|
|
|
module.exports = {Chapter, chapterApi} |