|
|
const {query} = require("../client")
class LogHeader { /** * Construct a log header. You should probably use the logHeaderApi instead of doing * this manually, even for mutations. * * @param {string} id * @param {Date|string} date * @param {string} channelName * @param {string} title * @param {string} description * @param {string} event * @param {boolean} open * @param {{id:string,name:string,shortName:string,author:string}[]} characters */ constructor(id, shortId, date, channelName, title, description, event, open, characters) { this.id = id this.shortId = shortId this.date = new Date(date) this.channelName = channelName this.title = title || null this.description = description || null this.event = event || null this.open = open this.characters = characters.map(ch => new LogHeaderCharacter(ch.id, ch.name, ch.shortName, ch.author)) } }
class LogHeaderCharacter { /** * Construct a log header character list entry. * * @param {string} id * @param {string} name * @param {string} shortName * @param {string} author */ constructor(id, name, shortName, author) { this.id = id this.name = name this.shortName = shortName this.author = author } }
/** * logHeaderApi contains the API queries for the LogHeader frontend model, which is a subset of the * logs model. */ const logHeaderApi = { /** * Call `stories(filter)` query * * @param {{search:string, channels:string|string[], events:string|string[], open:boolean, characters:string|string[], limit:number}} filter * @returns {Promise<LogHeader[]>} */ list(filter = {}) { return query(`
query LogHeaders($filter: LogsFilter) { headers: logs(filter:$filter) { id shortId date channelName title description event open characters { id name shortName author } } } `, {filter}).then(({headers}) => {
return headers.map(h => new LogHeader(h.id, h.shortId, h.date, h.channelName, h.title, h.description, h.event, h.open, h.characters)) }) }, }
module.exports = {LogHeader, LogHeaderCharacter, logHeaderApi}
|