Skip to content

Commit

Permalink
Merge pull request RocketChat#706 from Shailesh351/sb_api_livechat_fi…
Browse files Browse the repository at this point in the history
…lter

Add livechat/trigger POST API Endpoint
  • Loading branch information
chadgoss authored May 26, 2021
2 parents a4ab7b7 + afa1b6d commit a83d133
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions app/livechat/imports/server/rest/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ API.v1.addRoute('livechat/filter', { authRequired: true }, {
post() {
try {
check(this.bodyParams, {
_id: String,
name: String,
description: String,
enabled: Boolean,
Expand Down
26 changes: 26 additions & 0 deletions app/livechat/imports/server/rest/triggers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';

import { API } from '../../../../api/server';
import { findTriggers, findTriggerById } from '../../../server/api/lib/triggers';

API.v1.addRoute('livechat/trigger', { authRequired: true }, {
post() {
try {
check(this.bodyParams, {
_id: String,
name: String,
description: String,
enabled: Boolean,
runOnce: Boolean,
registeredOnly: Boolean,
conditions: Array,
actions: Array,
});

API.v1.success(
Meteor.runAsUser(this.userId,
() => Meteor.call('livechat:saveTrigger', this.bodyParams),
),
);
} catch (e) {
return API.v1.failure(e);
}
},
});

API.v1.addRoute('livechat/triggers', { authRequired: true }, {
get() {
const { offset, count } = this.getPaginationItems();
Expand Down
5 changes: 1 addition & 4 deletions app/livechat/server/methods/saveFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ Meteor.methods({
slug: String,
});

if (filter._id) {
return LivechatFilter.updateById(filter._id, filter);
}
return LivechatFilter.insert(filter);
return LivechatFilter.insertOrUpsert(filter);
},
});
5 changes: 1 addition & 4 deletions app/livechat/server/methods/saveTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ Meteor.methods({
actions: Array,
});

if (trigger._id) {
return LivechatTrigger.updateById(trigger._id, trigger);
}
return LivechatTrigger.insert(trigger);
return LivechatTrigger.insertOrUpsert(trigger);
},
});
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a83d133

Please sign in to comment.