@@ -0,0 +1,81 @@
|
||||
const {query} = require("../client")
|
||||
|
||||
class Change {
|
||||
/**
|
||||
* @param {string} id
|
||||
* @param {string} model
|
||||
* @param {string} op
|
||||
* @param {string} author
|
||||
* @param {Date | string | number} date
|
||||
* @param {{model:string,id:string}[]} keys '
|
||||
* @param {{type:string, [x:string]:any}[]} objects
|
||||
*/
|
||||
constructor(id, model, op, author, date, keys, objects) {
|
||||
this.id = id
|
||||
this.model = model
|
||||
this.op = op
|
||||
this.author = author
|
||||
this.date = date
|
||||
this.keys = keys
|
||||
this.objects = objects
|
||||
}
|
||||
|
||||
static fromData(data) {
|
||||
return new Change(data.id, data.model, data.op, data.author, data.date, data.keys, data.objects)
|
||||
}
|
||||
}
|
||||
|
||||
class ChangesAPI {
|
||||
/**
|
||||
* Call `channels(filter)` query
|
||||
*
|
||||
* @param {{limit:int, keys: {model:string,id:string}[]}} filter
|
||||
* @returns {Promise<Change[]>}
|
||||
*/
|
||||
list(filter = null) {
|
||||
return query(`
|
||||
query ListChanges($filter:ChangesFilter) {
|
||||
changes(filter:$filter) {
|
||||
id
|
||||
model
|
||||
op
|
||||
author
|
||||
date
|
||||
keys {
|
||||
model
|
||||
id
|
||||
}
|
||||
objects {
|
||||
type: __typename
|
||||
|
||||
...on Character {
|
||||
id
|
||||
name
|
||||
}
|
||||
|
||||
...on Chapter {
|
||||
id
|
||||
title
|
||||
}
|
||||
|
||||
...on Story {
|
||||
id
|
||||
name
|
||||
}
|
||||
|
||||
...on Post {
|
||||
id
|
||||
time
|
||||
nick
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`, {filter}).then(({changes}) => {
|
||||
return changes.map(d => Change.fromData(d))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { Change, changesApi: new ChangesAPI }
|
||||
|
||||
Reference in New Issue
Block a user