forked from vegeta999/Rocket.Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreportMessage.js
More file actions
32 lines (26 loc) · 856 Bytes
/
Copy pathreportMessage.js
File metadata and controls
32 lines (26 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import { Messages, Reports } from '../../app/models';
Meteor.methods({
reportMessage(messageId, description) {
check(messageId, String);
check(description, String);
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'reportMessage',
});
}
if ((description == null) || description.trim() === '') {
throw new Meteor.Error('error-invalid-description', 'Invalid description', {
method: 'reportMessage',
});
}
const message = Messages.findOneById(messageId);
if (!message) {
throw new Meteor.Error('error-invalid-message_id', 'Invalid message id', {
method: 'reportMessage',
});
}
return Reports.createWithMessageDescriptionAndUserId(message, description, Meteor.userId());
},
});