The frontend/UI server, written in JS using the MarkoJS library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.8 KiB

  1. const {query} = require("../client")
  2. const {Character} = require("./Character")
  3. const {Channel} = require("./Channel")
  4. const {Post} = require("./Post")
  5. class Log {
  6. /**
  7. * @param {string} id
  8. * @param {string} shortId
  9. * @param {Date | string | number} date
  10. * @param {string} title
  11. * @param {string} eventName
  12. * @param {string} description
  13. * @param {string} open
  14. * @param {any} channel
  15. * @param {any[]} characters
  16. * @param {any[]} posts
  17. */
  18. constructor(id, shortId, date, title, eventName, description, open, channel, characters, posts) {
  19. this.id = id
  20. this.shortId = shortId
  21. this.date = date
  22. this.title = title
  23. this.eventName = eventName
  24. this.description = description
  25. this.open = open
  26. this.channel = Channel.fromData(channel)
  27. this.characters = characters.map(c => Character.fromData(c))
  28. this.posts = posts.map(p => Post.fromData(p))
  29. }
  30. static fromData(data) {
  31. return new Log(data.id, data.shortId, data.date, data.title, data.eventName, data.description, data.open, data.channel, data.characters, data.posts)
  32. }
  33. }
  34. const logsApi = {
  35. find(id) {
  36. return query(`
  37. query FindLog($id: String!) {
  38. log(id: $id) {
  39. id
  40. shortId
  41. date
  42. title
  43. eventName
  44. description
  45. open
  46. channel {
  47. name
  48. logged
  49. hub
  50. eventName
  51. locationName
  52. }
  53. characters {
  54. id
  55. nicks
  56. author
  57. name
  58. shortName
  59. description
  60. }
  61. posts {
  62. id
  63. position
  64. time
  65. kind
  66. nick
  67. text
  68. }
  69. }
  70. }
  71. `, {id}).then(({log}) => {
  72. return Log.fromData(log)
  73. })
  74. },
  75. }
  76. module.exports = { Log, logsApi }