Skip to content

Commit

Permalink
Merge pull request RocketChat#624 from Shailesh351/sb_custom_field_en…
Browse files Browse the repository at this point in the history
…dpoint

Add livechat/custom-field post API Endpoint
  • Loading branch information
ear-dev authored Apr 22, 2021
2 parents afc3f72 + d096011 commit 9ee882f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions app/livechat/server/api/v1/customField.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,31 @@ API.v1.addRoute('livechat/custom.field', {
},
});

API.v1.addRoute('livechat/custom-field', { authRequired: true }, {
post() {
try {
check(this.bodyParams, {
field: String,
label: String,
scope: String,
visibility: Boolean,
regexp: String,
});

const { field, visibility } = this.bodyParams;
const { customField } = Promise.await(findCustomFieldById({ userId: this.userId, customFieldId: field }));

API.v1.success(
Meteor.runAsUser(this.userId,
() => Meteor.call('livechat:saveCustomField', customField ? field : undefined, { ...this.bodyParams, visibility: visibility ? 'visible' : 'hidden' }),
),
);
} catch (e) {
return API.v1.failure(e);
}
},
});

API.v1.addRoute('livechat/custom.fields', {
post() {
check(this.bodyParams, {
Expand Down

0 comments on commit 9ee882f

Please sign in to comment.