Skip to content
Snippets Groups Projects
Commit 07c60b9d authored by Marcos Spessatto Defendi's avatar Marcos Spessatto Defendi Committed by Diego Sampaio
Browse files

[NEW] Add delete channel mutation to GraphQL API (#11860)

parent d2ab3f12
No related branches found
No related tags found
No related merge requests found
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';
import { authenticated } from '../../helpers/authenticated';
import schema from '../../schemas/channels/deleteChannel.graphqls';
const resolver = {
Mutation: {
deleteChannel: authenticated((root, { channelId }, { user }) => {
const channel = RocketChat.models.Rooms.findOne({
_id: channelId,
t: 'c',
});
if (!channel) {
throw new Error('error-room-not-found', 'The required "channelId" param provided does not match any channel');
}
const sub = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(channel._id, user._id);
if (!sub) {
throw new Error(`The user/callee is not in the channel "${ channel.name }.`);
}
if (!sub.open) {
throw new Error(`The channel, ${ channel.name }, is already closed to the sender`);
}
Meteor.runAsUser(user._id, () => {
Meteor.call('eraseRoom', channel._id);
});
return true;
}),
},
};
export {
schema,
resolver,
};
......@@ -9,6 +9,7 @@ import * as channelsByUser from './channelsByUser';
import * as createChannel from './createChannel';
import * as leaveChannel from './leaveChannel';
import * as hideChannel from './hideChannel';
import * as deleteChannel from './deleteChannel';
// types
import * as ChannelType from './Channel-type';
import * as ChannelSort from './ChannelSort-enum';
......@@ -26,6 +27,7 @@ export const schema = mergeTypes([
createChannel.schema,
leaveChannel.schema,
hideChannel.schema,
deleteChannel.schema,
// types
ChannelType.schema,
ChannelSort.schema,
......@@ -44,6 +46,7 @@ export const resolvers = mergeResolvers([
createChannel.resolver,
leaveChannel.resolver,
hideChannel.resolver,
deleteChannel.resolver,
// types
ChannelType.resolver,
]);
type Mutation {
deleteChannel(channelId: String!): Boolean
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment