mirror of
https://github.com/wassname/talk.git
synced 2026-08-06 13:41:02 +08:00
Added graph API for assets
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
const errors = require('../../errors');
|
||||
const {
|
||||
UPDATE_ASSET_SETTINGS,
|
||||
UPDATE_ASSET_STATUS,
|
||||
} = require('../../perms/constants');
|
||||
|
||||
const AssetsService = require('../../services/assets');
|
||||
const AssetModel = require('../../models/asset');
|
||||
|
||||
/**
|
||||
* updateSettings will update the settings on an asset.
|
||||
*
|
||||
* @param {Object} ctx graphql context
|
||||
* @param {String} id the asset's id to update
|
||||
* @param {Object} settings the settings to update on the asset.
|
||||
*/
|
||||
const updateSettings = async (ctx, id, settings) => AssetsService.overrideSettings(id, settings);
|
||||
|
||||
/**
|
||||
* updateStatus will update the status of an asset.
|
||||
*
|
||||
* @param {Object} ctx graphql context
|
||||
* @param {String} id the asset's id to update
|
||||
* @param {Object} status the status to change on the asset relating to it's
|
||||
* current state.
|
||||
*/
|
||||
const updateStatus = async (ctx, id, {closedAt, closedMessage}) => AssetModel.update({
|
||||
id,
|
||||
}, {
|
||||
$set: {
|
||||
closedAt,
|
||||
closedMessage
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = (ctx) => {
|
||||
let mutators = {
|
||||
Asset: {
|
||||
updateSettings: () => Promise.reject(errors.ErrNotAuthorized),
|
||||
updateStatus: () => Promise.reject(errors.ErrNotAuthorized)
|
||||
}
|
||||
};
|
||||
|
||||
if (ctx.user) {
|
||||
if (ctx.user.can(UPDATE_ASSET_SETTINGS)) {
|
||||
mutators.Asset.updateSettings = (id, settings) => updateSettings(ctx, id, settings);
|
||||
}
|
||||
|
||||
if (ctx.user.can(UPDATE_ASSET_STATUS)) {
|
||||
mutators.Asset.updateStatus = (id, status) => updateStatus(ctx, id, status);
|
||||
}
|
||||
}
|
||||
|
||||
return mutators;
|
||||
};
|
||||
@@ -328,7 +328,7 @@ const createPublicComment = async (context, commentInput) => {
|
||||
* @param {String} id identifier of the comment (uuid)
|
||||
* @param {String} status the new status of the comment
|
||||
*/
|
||||
const setStatus = async ({user, loaders: {Comments}, pubsub}, {id, status}) => {
|
||||
const setStatus = async ({user, loaders: {Comments}}, {id, status}) => {
|
||||
let comment = await CommentsService.pushStatus(id, status, user ? user.id : null);
|
||||
|
||||
// If the loaders are present, clear the caches for these values because we
|
||||
|
||||
@@ -3,6 +3,7 @@ const debug = require('debug')('talk:graph:mutators');
|
||||
|
||||
const Comment = require('./comment');
|
||||
const Action = require('./action');
|
||||
const Asset = require('./asset');
|
||||
const Tag = require('./tag');
|
||||
const Token = require('./token');
|
||||
const User = require('./user');
|
||||
@@ -14,6 +15,7 @@ let mutators = [
|
||||
// Load in the core mutators.
|
||||
Comment,
|
||||
Action,
|
||||
Asset,
|
||||
Tag,
|
||||
Token,
|
||||
User,
|
||||
|
||||
Reference in New Issue
Block a user