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.
117 lines
2.9 KiB
117 lines
2.9 KiB
const {query} = require("../client")
|
|
|
|
let eventNames = []
|
|
|
|
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, eventName, 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.eventName = eventName || 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 `logs` query, returns event name
|
|
*
|
|
* @returns {Promise<string[]>}
|
|
*/
|
|
eventNames() {
|
|
return query(`
|
|
query LogHeadersEventNames() {
|
|
headers: logs(filter:{limit:0}) {
|
|
eventName
|
|
}
|
|
}
|
|
`, {}).then(({headers}) => {
|
|
const eventNames = []
|
|
const seen = {}
|
|
|
|
for (const header of headers) {
|
|
if (!header.eventName) {
|
|
continue
|
|
}
|
|
|
|
if (!seen[header.eventName]) {
|
|
eventNames.push(header.eventName)
|
|
seen[header.eventName] = true
|
|
}
|
|
}
|
|
|
|
return eventNames
|
|
})
|
|
},
|
|
|
|
/**
|
|
* Call `logs(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
|
|
eventName
|
|
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.eventName, h.open, h.characters))
|
|
})
|
|
},
|
|
}
|
|
|
|
module.exports = {LogHeader, LogHeaderCharacter, logHeaderApi, eventNames}
|