Browse Source

api: Added Comment and hooked it up to the Story.find response.

master
Gisle Aune 6 years ago
parent
commit
5260d96f37
  1. 11
      rpdata/api/Chapter.js
  2. 51
      rpdata/api/Comment.js
  3. 51
      rpdata/api/Story.js

11
rpdata/api/Chapter.js

@ -1,4 +1,5 @@
const {query} = require("../client") const {query} = require("../client")
const {Comment} = require("./Comment")
class Chapter { class Chapter {
/** /**
@ -9,8 +10,12 @@ class Chapter {
* @param {string | Date} createdDate * @param {string | Date} createdDate
* @param {string | Date} fictionalDate * @param {string | Date} fictionalDate
* @param {string | Date} editedDate * @param {string | Date} editedDate
* @param {boolean} canComment
* @param {"Disabled"|"Article"|"Chat"|"Message"} commentMode
* @param {boolean} commentsLocked
* @param {any[]} comments
*/ */
constructor(id, title, author, source, createdDate, fictionalDate, editedDate) {
constructor(id, title, author, source, createdDate, fictionalDate, editedDate, canComment, commentMode, commentsLocked, comments) {
this.id = id this.id = id
this.title = title this.title = title
this.author = author this.author = author
@ -18,6 +23,10 @@ class Chapter {
this.createdDate = new Date(createdDate) this.createdDate = new Date(createdDate)
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)
this.canComment = canComment
this.commentMode = commentMode
this.commentsLocked = commentsLocked
this.comments = (comments||[]).map(c => Comment.fromData(c))
} }
} }

51
rpdata/api/Comment.js

@ -0,0 +1,51 @@
const {query} = require("../client")
class Comment {
/**
* @param {string} id
* @param {string} subject
* @param {string} author
* @param {string} characterName
* @param {CommentCharacter} character
* @param {string | number | Date} fictionalDate
* @param {string | number | Date} createdDate
* @param {string | number | Date} editedDate
* @param {string} source
*/
constructor(id, subject, author, characterName, character, fictionalDate, createdDate, editedDate, source) {
this.id = id
this.subject = subject
this.author = author
this.characterName = characterName
this.character = CommentCharacter.fromData(character)
this.fictionalDate = new Date(fictionalDate)
this.createdDate = new Date(createdDate)
this.editedDate = new Date(editedDate)
this.source = source
}
static fromData(data) {
return new Comment(data.id, data.subject, data.author, data.characterName, data.character, data.fictionalDate, data.createdDate, data.editedDate, data.source)
}
}
class CommentCharacter {
/**
* @param {string} id
* @param {string} name
* @param {string} author
* @param {string} description
*/
constructor(id, name, author, description) {
this.id = id
this.name = name
this.author = author
this.description = description
}
static fromData(data) {
return new CommentCharacter(data.id, data.name, data.author, data.description)
}
}
module.exports = {Comment, CommentCharacter}

51
rpdata/api/Story.js

@ -29,7 +29,7 @@ class Story {
this.updatedDate = new Date(updatedDate) this.updatedDate = new Date(updatedDate)
this.fictionalDate = fictionalDate != null ? new Date(fictionalDate) : null this.fictionalDate = fictionalDate != null ? new Date(fictionalDate) : null
this.tags = tags.map(dt => new Tag(dt.kind, dt.name)) this.tags = tags.map(dt => new Tag(dt.kind, dt.name))
this.chapters = chapters != null ? chapters.map(c => new Chapter(c.id, c.title, c.author, c.source, c.createdDate, c.fictionalDate, c.editedDate)) : null
this.chapters = chapters != null ? chapters.map(c => new Chapter(c.id, c.title, c.author, c.source, c.createdDate, c.fictionalDate, c.editedDate, c.canComment, c.commentMode, c.commentsLocked, c.comments)) : null
} }
} }
@ -91,32 +91,51 @@ const storyApi = {
*/ */
find(id) { find(id) {
return query(` return query(`
query FindStory($id: String!) {
story(id: $id) {
id
query FindStory($id: String!) {
story(id: $id) {
id
name
author
category
tags {
kind
name name
}
listed
open
createdDate
fictionalDate
updatedDate
chapters {
id
title
author author
category
tags {
kind
name
}
listed
open
source
createdDate createdDate
fictionalDate fictionalDate
updatedDate
chapters {
editedDate
canComment
commentMode
commentsLocked
comments {
id id
title
subject
author author
source
createdDate
characterName
character {
id
name
author
description
}
fictionalDate fictionalDate
createdDate
editedDate editedDate
source
} }
} }
} }
}
`, {id}).then(({story}) => { `, {id}).then(({story}) => {
return new Story( return new Story(
story.id, story.name, story.author, story.category, story.id, story.name, story.author, story.category,

Loading…
Cancel
Save