-
Notifications
You must be signed in to change notification settings - Fork 13.1k
[FIX] Livechat.RegisterGuest method removing unset fields #20124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
c4cf843
Update index.js
ggazzo 97b69f7
Fix Livechat.registerGuest method.
renatobecker a0f2498
Merge branch 'develop' into omnichannel/fix-register-guest-method
renatobecker 90def2b
Merge branch 'develop' into omnichannel/fix-register-guest-method
renatobecker efad87f
pass only fields that need to be inserted
rafaelblink b411319
Merge remote-tracking branch 'origin/omnichannel/fix-register-guest-m…
rafaelblink d53a299
undo changes on Livechat, registerGuest method.
rafaelblink b4c18ea
refactor contacts using your own lib file.
rafaelblink 3cd9e9d
remove unnecessary http header method
rafaelblink 8741c80
refactor null value on server side.
rafaelblink 5317135
check if customFields are valid and adding only valid fields.
rafaelblink 7544559
check if customField is visitor and it has some value.
rafaelblink 278930d
Improve code style.
renatobecker d68d5dc
Merge branch 'develop' into omnichannel/fix-register-guest-method
renatobecker af2354e
Implements search for fields check if either email or phone already e…
rafaelblink d2b55a5
validate if both email and phone already exist
rafaelblink b5a88ef
Merge branch 'develop' into omnichannel/fix-register-guest-method
renatobecker 4d33bc3
code enhancements on api and field validations.
rafaelblink fbf27e8
Merge remote-tracking branch 'origin/omnichannel/fix-register-guest-m…
rafaelblink d972a01
undo unecessary field clean validation.
rafaelblink 934dee4
remove email field icon to avoid weird error validation and clear err…
rafaelblink aa29aa1
Merge branch 'develop' into omnichannel/fix-register-guest-method
renatobecker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import { check } from 'meteor/check'; | ||
| import s from 'underscore.string'; | ||
|
|
||
| import { | ||
| LivechatVisitors, | ||
| LivechatCustomField, | ||
| } from '../../../models'; | ||
|
|
||
|
|
||
| export const Contacts = { | ||
|
|
||
| registerContact({ token, name, email, phone, username, customFields = {}, contactManager = {} } = {}) { | ||
| check(token, String); | ||
|
|
||
| let contactId; | ||
| const updateUser = { | ||
| $set: { | ||
| token, | ||
| }, | ||
| }; | ||
|
|
||
| const user = LivechatVisitors.getVisitorByToken(token, { fields: { _id: 1 } }); | ||
|
|
||
| if (user) { | ||
| contactId = user._id; | ||
| } else { | ||
| if (!username) { | ||
| username = LivechatVisitors.getNextVisitorUsername(); | ||
| } | ||
|
|
||
| let existingUser = null; | ||
|
|
||
| if (s.trim(email) !== '' && (existingUser = LivechatVisitors.findOneGuestByEmailAddress(email))) { | ||
| contactId = existingUser._id; | ||
| } else { | ||
| const userData = { | ||
| username, | ||
| ts: new Date(), | ||
| }; | ||
|
|
||
| contactId = LivechatVisitors.insert(userData); | ||
| } | ||
| } | ||
|
|
||
| updateUser.$set.name = name; | ||
| updateUser.$set.phone = (phone && [{ phoneNumber: phone }]) || null; | ||
| updateUser.$set.visitorEmails = (email && [{ address: email }]) || null; | ||
|
|
||
| const allowedCF = LivechatCustomField.find({ scope: 'visitor' }).map(({ _id }) => _id); | ||
|
|
||
| const livechatData = Object.keys(customFields) | ||
| .filter((key) => allowedCF.includes(key) && customFields[key] !== '' && customFields[key] !== undefined) | ||
| .reduce((obj, key) => { | ||
| obj[key] = customFields[key]; | ||
| return obj; | ||
| }, {}); | ||
|
|
||
| updateUser.$set.livechatData = livechatData; | ||
rafaelblink marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| updateUser.$set.contactManager = (contactManager?.username && { username: contactManager.username }) || null; | ||
|
|
||
| LivechatVisitors.updateById(contactId, updateUser); | ||
|
|
||
| return contactId; | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.