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.
 
 
 
 

84 lines
2.0 KiB

const {query} = require("../client")
class Channel {
constructor(name, logged, hub, eventName, locationName) {
this.name = name
this.logged = logged
this.hub = hub
this.eventName = eventName
this.locationName = locationName
}
static fromData(data) {
return new Channel(data.name, data.logged, data.hub, data.eventName, data.locationName)
}
}
class ChannelAPI {
/**
* Call `channels(filter)` query
*
* @param {{logged:boolean, eventName:string, locationName:string}} filter
* @returns {Promise<Channel[]>}
*/
list(filter = {}) {
return query(`
query ListChannel($filter: ChannelsFilter) {
channels(filter: $filter) {
name
logged
hub
eventName
locationName
}
}
`, {filter}).then(({channels}) => {
return channels.map(d => Channel.fromData(d))
})
}
/**
* Call `channels(filter)` query
*
* @param {{name:string, logged:boolean, eventName:string, locationName:string}} filter
* @returns {Promise<Channel>}
*/
add(input = {}) {
return query(`
mutation AddChannel($input: ChannelAddInput!) {
addChannel(input: $input) {
name
hub
logged
eventName
locationName
}
}
`, {input}, {permissions: ["channel.add"]}).then(({addChannel}) => {
return Channel.fromData(addChannel)
})
}
/**
* Call `channels(filter)` query
*
* @param {{name:string, logged:boolean, eventName:string, locationName:string}} filter
* @returns {Promise<{name:string, logged:boolean, eventName:string, locationName:string}>}
*/
edit(input = {}) {
return query(`
mutation EditChannel($input: ChannelEditInput!) {
editChannel(input: $input) {
name
logged
eventName
locationName
}
}
`, {input}, {permissions: ["channel.edit"]}).then(({editChannel}) => {
return editChannel
})
}
}
module.exports = { Channel, channelApi: new ChannelAPI }