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. 21
      rpdata/api/Story.js

11
rpdata/api/Chapter.js

@ -1,4 +1,5 @@
const {query} = require("../client")
const {Comment} = require("./Comment")
class Chapter {
/**
@ -9,8 +10,12 @@ class Chapter {
* @param {string | Date} createdDate
* @param {string | Date} fictionalDate
* @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.title = title
this.author = author
@ -18,6 +23,10 @@ class Chapter {
this.createdDate = new Date(createdDate)
this.fictionalDate = fictionalDate != null ? new Date(fictionalDate) : null
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}

21
rpdata/api/Story.js

@ -29,7 +29,7 @@ class Story {
this.updatedDate = new Date(updatedDate)
this.fictionalDate = fictionalDate != null ? new Date(fictionalDate) : null
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
}
}
@ -114,6 +114,25 @@ const storyApi = {
createdDate
fictionalDate
editedDate
canComment
commentMode
commentsLocked
comments {
id
subject
author
characterName
character {
id
name
author
description
}
fictionalDate
createdDate
editedDate
source
}
}
}
}

Loading…
Cancel
Save