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.
 
 
 
 

65 lines
1.5 KiB

const {query} = require("../client")
class Post {
/**
* @param {string} id
* @param {number} position
* @param {Date | string | number} time
* @param {string} kind
* @param {string} nick
* @param {string} text
*/
constructor(id, position, time, kind, nick, text) {
this.id = id
this.position = position
this.time = new Date(time)
this.kind = kind
this.nick = nick
this.text = text
}
static fromData(data) {
return new Post(data.id, data.position, data.time, data.kind, data.nick, data.text)
}
}
class PostAPI {
/**
* Call `movePost(input)` mutation, returns the id and position of all affected posts.
*
* @param {{id:string, toPosition: number}} input
* @returns {Promise<{id:string, position:number}[]>}
*/
move(input) {
return query(`
mutation MovePost($input: PostMoveInput!) {
movePost(input: $input) {
id
position
}
}
`, {input}, {permissions: ["post.move"]}).then(({movePost}) => {
return movePost
})
}
/**
* Call `removePost(input)` mutation, returns the id of the affected post.
*
* @param {{id:string, toPosition: number}} input
* @returns {Promise<{id:string}>}
*/
remove(input) {
return query(`
mutation RemovePost($input: PostRemoveInput!) {
removePost(input: $input) {
id
}
}
`, {input}, {permissions: ["post.remove"]}).then(({removePost}) => {
return removePost
})
}
}
module.exports = {Post, postApi: new PostAPI}