|
@ -27,4 +27,98 @@ class Character { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
module.exports = { Character } |
|
|
|
|
|
|
|
|
class ChracterAPI { |
|
|
|
|
|
/** |
|
|
|
|
|
* Call `characters(filter)` query |
|
|
|
|
|
* |
|
|
|
|
|
* @param {{ids:string[], nicks:string[], names:string[], author:string, search:string, logged:boolean}} filter |
|
|
|
|
|
* @returns {Promise<Story[]>} |
|
|
|
|
|
*/ |
|
|
|
|
|
list(filter = {}) { |
|
|
|
|
|
if (filter.earliestFictionalDate != null && typeof(filter.earliestFictionalDate) !== "string") { |
|
|
|
|
|
filter.earliestFictionalDate = filter.earliestFictionalDate.toISOString() |
|
|
|
|
|
} |
|
|
|
|
|
if (filter.latestFictionalDate != null && typeof(filter.latestFictionalDate) !== "string") { |
|
|
|
|
|
filter.latestFictionalDate = filter.latestFictionalDate.toISOString() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return query(`
|
|
|
|
|
|
query ListCharacters($filter: CharactersFilter) { |
|
|
|
|
|
characters(filter: $filter) { |
|
|
|
|
|
id |
|
|
|
|
|
nicks |
|
|
|
|
|
author |
|
|
|
|
|
name |
|
|
|
|
|
shortName |
|
|
|
|
|
description |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
`, {filter}).then(({characters}) => {
|
|
|
|
|
|
return characters.map(d => Character.fromData(d)) |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Call `addCharacter(input)` mutation, returns addable fields. |
|
|
|
|
|
* |
|
|
|
|
|
* @param {{id:string, name:string, shortName:string, author:string, description:string}} input |
|
|
|
|
|
* @returns {Promise<Character>} |
|
|
|
|
|
*/ |
|
|
|
|
|
add(input) { |
|
|
|
|
|
return query(`
|
|
|
|
|
|
mutation AddCharacter($input: CharacterAddInput!) { |
|
|
|
|
|
addCharacter(input: $input) { |
|
|
|
|
|
id |
|
|
|
|
|
nicks |
|
|
|
|
|
author |
|
|
|
|
|
name |
|
|
|
|
|
shortName |
|
|
|
|
|
description |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
`, {input}, {permissions: ["member", "character.add"]}).then(({addCharacter}) => {
|
|
|
|
|
|
return Character.fromData(addCharacter) |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Call `editCharacter(input)` mutation, returns editable fields. |
|
|
|
|
|
* |
|
|
|
|
|
* @param {{id:string, name:string, shortName:string, description:string}} input |
|
|
|
|
|
* @returns {Promise<{id:string, name:string, shortName:string, description:string}>} |
|
|
|
|
|
*/ |
|
|
|
|
|
edit(input) { |
|
|
|
|
|
return query(`
|
|
|
|
|
|
mutation EditCharacters($input: CharacterEditInput!) { |
|
|
|
|
|
editCharacter(input: $input) { |
|
|
|
|
|
id |
|
|
|
|
|
name |
|
|
|
|
|
shortName |
|
|
|
|
|
description |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
`, {input}, {permissions: ["member", "character.edit"]}).then(({editCharacter}) => {
|
|
|
|
|
|
return editCharacter |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Call `removeCharacter(input)` mutation |
|
|
|
|
|
* |
|
|
|
|
|
* @param {{id:string}} input |
|
|
|
|
|
* @returns {Promise<{id:string}>} |
|
|
|
|
|
*/ |
|
|
|
|
|
remove(input) { |
|
|
|
|
|
return query(`
|
|
|
|
|
|
mutation RemoveCharacters($input: CharacterRemoveInput!) { |
|
|
|
|
|
removeCharacter(input: $input) { |
|
|
|
|
|
id |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
`, {input}, {permissions: ["member", "character.remove"]}).then(({removeCharacter}) => {
|
|
|
|
|
|
return removeCharacter |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports = { Character, charactersApi: new ChracterAPI } |