const {query} = require("../client") const {Character} = require("./Character") const {Channel} = require("./Channel") const {Post} = require("./Post") class Log { /** * @param {string} id * @param {string} shortId * @param {Date | string | number} date * @param {string} title * @param {string} eventName * @param {string} description * @param {string} open * @param {any} channel * @param {any[]} characters * @param {any[]} posts */ constructor(id, shortId, date, title, eventName, description, open, channel, characters, posts) { this.id = id this.shortId = shortId this.date = date this.title = title this.eventName = eventName this.description = description this.open = open this.channel = Channel.fromData(channel) this.characters = characters.map(c => Character.fromData(c)) this.posts = posts.map(p => Post.fromData(p)) } static fromData(data) { return new Log(data.id, data.shortId, data.date, data.title, data.eventName, data.description, data.open, data.channel, data.characters, data.posts) } } const logsApi = { find(id) { return query(` query FindLog($id: String!) { log(id: $id) { id shortId date title eventName description open channel { name logged hub eventName locationName } characters { id nicks author name shortName description } posts { id position time kind nick text } } } `, {id}).then(({log}) => { return Log.fromData(log) }) }, } module.exports = { Log, logsApi }