Node JS Using AND or OR operator - Fetching data - node.js

Good Day!
I need help on the below issue:
Goal: is to filter data depending on the department content. What I'm trying to do is to fetch data from MongoDB based on your designation or department. For example, I'm from the Email Team:
I was able to fetch the data correctly using the below code:
return Announcement.find({ department: params.department }).collation({locale:'en',strength: 2}).sort({createdOn:1}).then(announcement => {
return announcement
})
However, what I'm trying to achieve is to get the data from the "All" department. For example, Email Team data plus the All data. This is a notification app. Wherein agents will receive or be notified if there are news recently published.
Example: As admin I have the option to assign a news to a specific department. I'm using a ComboBox for the selection: All, Email, Chat, Phone
So, if I selected All, since I'm from the email team, I should be getting the notification too.

After few minutes of research, I found this:
return Announcement.find({ $or: [{"department" : "All"},{department: params.department}]}).collation({locale:'en',strength: 2}).sort({createdOn:1}).then(announcement => {
return announcement
})

Related

How to fetch the Finance Charge Preferences values using SuiteScript in NetSuite?

We need to perform calculations in SuiteScript using the values in Setup/Accounting/Finance Charge Preferences. Which record is this stored on? Specifically, we're looking for these finance charge fields:
Annual Rate
Minimum Finance Charge
Grace Period
We've tried to create saved searches in all of the obvious records but have not been able to find these fields.
Not documented but N/runtime can be used to get this info (at least in the console)
require(['N/runtime'], runtime=>{
const user = runtime.getCurrentUser();
console.log(user.getPreference({
name:'FC_GRACEPERIOD'
}));
});
You can get the field ids by clicking the field help on the Finance Charge Preferences page.
If that doesn't work to get the fields you can see if the fields are available but not documented by creating a server side script (I'd use a suitelet) to get the accounting preferences object and dump the field names.
If the config module was available client side this would be the console version:
require(['N/config'], config=>{
const conf = config.load({type:'accountingpreferences'});
conf.getFields().forEach(f=>console.log(f));
});

Stripe: Get card information so customer can update their card

My app uses subscriptions with Stripe.
I want to create a standard "account" page, which will list the customer's current card information (like "MasterCard" and last 4 of card number), and give the customer the option of updating that information.
I'm stuck on the first piece--getting back the current card information. To do this, I need the current card_id. I have tried the "listSources" method, but this returns blank data where the card info is supposed to be. What do I need to do to get that card info?
Here is what I've tried:
(I'm using Node, and running this server side)
The closest method I have found is here:
var stripe = require('stripe')(STRIPE_TOKEN);
stripe.customers.listSources(
CUSTOMER_ID,
{object: 'bank_account', limit: 3},
function(err, cards) {
// asynchronously called
}
);
This returns information (there's no error), but the docs say this method should return a data array of the cards that includes the card id for each. In testing, the data array keeps coming back empty.
I am testing with a customer id that has a valid subscription and a card that I can see on my Stripe dashboard.
Why is the data array coming back empty?
Note: there's also a retrieve source method, which should give back card details, but this method requires you have the id of the card you want info on, and that's what I am not able to get right now.
Converting this to an answer...
Stripe has recently rolled out PaymentMethods, which replace (and are separate from) the older Tokens and Sources API.
OP's issue is that their integration creates PaymentMethod objects, which won't show up in the sources list, but can instead be accessed via stripe.paymentMethods.list.

Pushing visitor data from DialogFlow to ZohoCRM

So I have connected DialogFlow to Zobot (Zoho Chatbot) and want to push information from DF to ZohoCRM.
My chatbot could sign someone up to a newsletter and once the person gives me their email I want to save that email and name in the ZohoCRM.
From what I can gather I have to use the DF webhooks to send information anywhere, I have found a sample code that can push data to the ZohoCRM but I want to customise it.
My main questions:
If I have a user email that is stored in DF as #sys.email how do I refer to this value in my web-hook code?
How do I specify what table and column the information must be stored in?
Where do I set my Zoho CRM ZSC Key?
This is code taken from the Zobot integration documentation page (https://help.zoho.com/portal/community/topic/schedule-a-call-and-push-visitor-data-to-zoho-crm-with-zobot-26-11-2018):
info crmdata;
if(!crmdata.isEmpty())
{ // update existing
_crmdata = crmdata.get(0);
info _crmdata;
leadid = _crmdata.get("id");
crmdata = zoho.crm.update("Leads",leadid,{"Full_Name":name},Map(),"your CRM connection name");
}
else
{
// create new lead
crmdata = zoho.crm.create("Leads",{"Email":email,"Full_Name":name},Map(),"your CRM connection name");
}
leadid = crmdata.get("id");
info leadid;
1.If I have a user email that is stored in DF as #sys.email how do I refer to this value in my web-hook code?
When user will be added to zoho crm you can start with workflow rule function which will be adding the variable you want to.
How do I specify what table and column the information must be stored in?
You can not specify table or column where the information must be stored in. You can only add new one user. I've tried it many times, sorry ;/

I want to set entity values based on condition. How to do that in dialogflow?

I am making a bot for booking rooms. For booking rooms a user can choose "Premium Service" or "Standard Service".
However the hotels available to be booked depends on "Premium" or "Standard".
How to do this in dialog flow?
I tried to set entities "Service_type" and "Hotels". However how to set values for entity "Hotels" based on "Service_type" the user has selected?
Please note that the intent of the bot is book rooms. And there are many other steps to be followed to complete it.
You can start by creating an entity like quality and it's helpful to think of other ways that the user might refer to the quality that you define as "standard" and "premium"
Now when you create your intents you should see that Dialogflow automatically detects your entity in the training phrases
If Dialogflow doesn't already detect your entity, you can highlight a word in the training phrase and associate it to a type of your choosing
That's the easy part.
In order to present a different set of hotels depending on which standard that was selected, you should look into developing a fulfillment endpoint that handles the logic.
The quality choice that the user made in the first question will be passed as a parameter and you can easily make conditional logic to select hotels depending on that
conv.ask(`Here is a list of ${quality} hotel options for you`);
if (quality === "premium") {
conv.ask(getPremiumHotelOptions()); // Carousel or list
} else {
conv.ask(getStandardHotelOptions()); // Carousel or list
}
You can create an empty Hotels entity and then populate it with the relevant entity values for that session in your fulfillment webhook.
If you're using node.js for your webhook, you can look into the Dialogflow library to do much of this work. The call might look something like this:
const sessionEntityTypeRequest = {
parent: sessionPath,
sessionEntityType: {
name: sessionEntityTypePath,
entityOverrideMode: entityOverrideMode,
entities: entities,
},
};
const [response] = await sessionEntityTypesClient.createSessionEntityType(
sessionEntityTypeRequest
);
(See a more complete example at https://github.com/googleapis/nodejs-dialogflow/blob/master/samples/resource.js in the createSessionEntityType() function)

Implementing public and followers only news feed

I want to implement a news feed where users can post both private ( shared ) and public activities. The difference between the two is public activities are shown in all the user's news feed and private activities are shown to all of my followers news feed.
I have been reading some resources about implementing news feed and I have come across this open source project.
Quoting from the documentation
Next up we want to start publishing this activity on several feeds. First of all we want to insert it into your personal feed, and then into your followers' feeds
Now this works well for private activities, I post the activity to author's own feed as well as all of my followers feed.
But the issue is when the activity is public. In this case I have to post it to user's own feed as well as all other users in the system so that this activity is shown in their feed.
Suppose there are 1 million users in the system than this will require posting to 1 million feeds (possibly 1 million DB records). I believe this is not correct.
I thought of separating out public activities in other collection and these activities are visible to all. This issue with this solution is suppose I want to retrieve a user's feed than how do I combine data from user's followers feed with public feed.
Consider this example.
User A has 10 followers and they posted 10 activities in total. So User A's feed has 10 activities from his followers. Now there is User B which user A does not follow. User B also posted 2 public activities. Now the user A's feed should have 12 activities (10 from followers + 2 from user B public activities) so I do I combine data from these two collection and implement sorting, filtering etc on the combined result set.
Additional Info:
platform: node.js
DB: rethinkdb
A possible solution is to setup a notifications table that contains the private and public feeds, with an index on for.
To insert a private notification:
r.table('notifications')
.insert({'for': ['user', 'sonia'], message: "you've got mail"})
To insert a public notification:
r.table('notifications')
.insert({'for': ['public'], message: 'hello, world'})
Meanwhile, use getAll to select which notifications to subscribe too:
r.table('notifications')
.getAll(['public'], ['user', 'sonia'], {index: 'for'})
.changes()
If your notifications are stored across multiple tables, you can use union to combine them into a single changefeed, for example:
r.table('notifications').getAll('sonia', {index: 'for'})
.union(r.table('public_notifications'))
.changes()

Resources