Algolia filter down nested array values - javascript

I have the following in the Algolia index:
{
objectID: 1,
subject: 'yyy',
messages: [
{visible: false, content: 'password: xxx'},
{visible: true, content: 'qqq'},
]
}
Some users can see invisible messages, the other don't.
Is it possible to filter down messages only to {visible: true} ones?
The reason is that I don't want the invisible messages to show up in the xhr query response.

I think you can't do it with one request to Algolia. What you can do is add 'message_visibility_false' and 'message_visibility_true' as attributes to main object.
{
objectID: 1,
subject: 'yyy',
message_visibility_false: 'password: xxx',
message_visibility_true: 'qqq'
}

You should be able to do it using dot notation. Try the following query:
messages.visible = true
Make sure you add messages.visible to your attributesForFaceting in Algolia console.
This seems to be a duplicate from another issue though: Algolia filter by nested attribute JavaScript

Related

ais-refinement-list in VueInstantSearch(Algolia) doesn't renders list

I have stucked with an issue using refinement list widget of algolia.
First of all my resulting data structure is like that:
[
{
objectID: 999,
title: 'some title',
categories: [
{
id: 444,
name: 'some name',
},
{...},
]
}
]
I have that type of structure on my page:
<ais-instant-search
:search-client="searchClient"
:initial-ui-state="{
index_Name: { query: searchedValue },
}"
index-name="index_Name"
>
<ais-index index-name="index_Name">
<ais-configure
:filters="facetsFilters"
:facets="['categories.id']"
:hits-per-page.camel="items"
/>
<ais-refinement-list attribute="categories.id" />
<div> ...Some other widgets nested in divs as ais-search-box, ais-sort-by, etc </div>
</ais-index>
</ais-instant-search>
Within ais-configure I have passed to filters a facetsFilters variable which contains string with such content:
"categories.id:1 OR categories.id:5"
and it works ok, I'm getting results within selected categories,
problems starts, when i try to get refinement-list here:
<ais-refinement-list attribute="categories.id" />
I have an empty list despite that on dashboard this attribute is added as an attributesForFacetings and in ais-configure filters parameters with categories.id in it also works well.
Any suggestions is highly appreciated !
Problem was in Dashboard of Algolia.
When we clicked on 'searchable' instead of 'filter only' radiobutton for chosen attributeForFaceting - everything starts working good.

javascript stripe add items with if

I cant seem to get the list of items created dynamically, i want to add additional items, but only if a value is true
stripe.redirectToCheckout({
items: [{
plan: plan,
quantity: quantity,
},
{
plan: 'plan_ddddddd0Hxlu',
quantity: aditionalStorageDays,
}],
successUrl: 'https://example.com/success',
cancelUrl: 'https://example.com/cancel',
customerEmail: '<?php echo $userInfo['email']?>',
}).then(function (result) {
// If `redirectToCheckout` fails due to a browser or network
// error, display the localized error message to your customer
// using `result.error.message`.
});
How do i add the secound item only if aditionalStorage is true?
{
plan: 'plan_ddddddd0Hxlu',
quantity: aditionalStorageDays,
}
Can you explain more...
You mean you want to push the object into array?
Or you want to splace the existing object and then push the new one ?

Sequelize options.nest in query() method doesn't work

I have a raw query like
squelize.query(
`select "order".id, "orderCustomer".id as "orderCustomer.id", "orderCustomer".forename as "orderCustomer.forename"
from orders as "order"
join customers as "orderCustomer" on "orderCustomer".id = "order"."orderCustomerId"
where "orderCustomer".forename ilike '%petra%';`,
{
type: Sequelize.QueryTypes.SELECT,
model: order,
nest: true,
mapToModel: true
})
When I query this in psql I get a correct result set:
-[ RECORD 1 ]----------+------
id | 383
orderCustomer.id | 446
orderCustomer.forename | Petra
-[ RECORD 2 ]----------+------
id | 419
orderCustomer.id | 9
orderCustomer.forename | Petra
The problem is, that Sequelize is apparently not able to form this into an Array of the kind
[
{
id: 383,
orderCustomer: {
id: 446,
forename: 'Petra'
}
},
...
]
Instead I get something like this:
[
{
id: 383,
'orderCustomer.id': 446,
'orderCustomer.forename': 'Petra'
},
...
]
Do I need to include the customer-model in the query's option-object?
UPDATE
I logged the result of my query. There is this property _options on all of the returned order-instances:
_options:{
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true, // <--------- possible cause?
attributes: undefined
}
Somehow, I cannot set options.raw to false on my query definition! Maybe that is the reason why …
…sequelize will not try to format the results of the query, or build an instance of a model from the result (see docs > query() > options.raw)
Any ideas?
I'm using your solution: nest: true and it works perfectly!
[err, rows] = await to(sequelize.query(query,{ replacements: { search: '%'+search+'%', limit: limit, offset: skip}, type: sequelize.QueryTypes.SELECT,nest: true}));
Try it without the
model: order,
this solved it for me
It is 2021 and seems that this is still doesn't work with Sequelize 6.6.2. Or rather I can't work out how to make the mapToModel work in conjunction with the nested properties.
I worked around the issue by removing the model: MyModel, mapToModel: true, part so that the query options look like this:
{ type: QueryTypes.SELECT, bind: [mainAssetId], nest: true, raw: false }
I get the object back with all the fields and nested works but it is of course not an instance of the Model. It looks like the model from data perspective so as long as you don't have methods on your model you should be fine.
You could always use something like the class-transformer package to transform it to the model instance.
Assuming you have the models set up properly,
Why not query it using associations, instead of using a raw query.
Something like this should generate a similar result
Model.Order.findAll({
where:{forename:{$iLike:'someString'}},
attributes:[/*Columns to fetch*/]
include:[{model:Model.Customer,attributes:[/*Columns to fetch*/]}]
});
Also IMO using the nest attributes, wont club across multiple rows returned.
I had the same issue and made it work this way:
sequelize.query(
`SELECT q.id, q.title, a.id AS "answers.id"
FROM questions q
JOIN answers a ON a.question_id = q.id`,
model: Question,
mapToModel: true,
nest: true,
raw: true,
type: sequelize.QueryTypes.SELECT }
)

Foursquare API Not returning photos on the Venue Search

So I'm playing around with the Venues just trying to get it to show some stuff before I both getting specific with my queries. I'm using nodejs and this module.
https://www.npmjs.com/package/foursquarevenues
If that matters. Anyways when I put a call to the api to getVenues with a simple call like:
var params = {
venuePhotos : '1',
near : "Rome, Italy"
};
Everything works fine with the exception that no photos are returned. A standard venue object from this call will look like this:
id: '523b15ce11d2d66df7dca8d0',
name: 'Qlub Radio, Roma',
contact: {},
location:
{ lat: 41.891096,
lng: 12.5106,
labeledLatLngs: [Object],
cc: 'IT',
country: 'Italia',
formattedAddress: [Object] },
categories: [ [Object] ],
verified: false,
stats: { checkinsCount: 3, usersCount: 2, tipCount: 0 },
venueRatingBlacklisted: true,
beenHere: { lastCheckinExpiredAt: 0 },
specials: { count: 0, items: [] },
referralId: 'v-1493396577',
venueChains: [],
hasPerk: false }
Which as far as I can tell returns no photo url for the venue which is contrary to what the documentation suggests. I've been putting in a bunch of different parameters as suggested in other threads and it hasn't changed anything. Am I missing something here?
Thanks.
After looking at the node.js module you're using the getVenues call is hitting the Foursquare venue/search endpoint which doesn't return photos with the search results. Calling exploreVenues in that module will hit the venues/explore endpoint which can return photos by including the venuePhotos=1 parameter (as you've done).
Also, if you only details for a specific venue you can use getVenue and if you only need the photos you can use getVenueAspect.
Hope this helps.

Malformed request when creating billing plan

So I a using the node paypal-rest-sdk module and I'm trying to create a billing plan. Using the documentation here I made this JSON:
const billingPlanAttributes = {
name: 'Subscription',
description: 'Monthly subscription plan',
type: 'INFINITE',
payment_definitions: [{
name: 'Regular monthly infinite payments',
type: 'REGULAR',
frequency_interval: '1',
frequency: 'MONTH',
cycles: '0',
amount: {
currency: 'USD',
amount: '4.99',
},
}],
merchant_preferences: {
cancel_url: 'http://localhost:3000/subscribe/cancel',
return_url: 'http://localhost:3000/subscribe/return',
auto_bill_amount: 'YES',
},
};
But when using the paypal.billingPlan.create(... function I get the error 'MALFORMED_REQUEST', 'Incoming JSON request does not map to API request'. So I guess my JSON is not in the correct format or I'm missing something that is need.
The documentation has a charge_models key but it does not mention that it is required unlike other keys.
If you can point me in the right direction that would be great.
Edit: changed the return url and cancel url to include the full domain but still same error.
There could be more to this, but I noticed one thing wrong with your JSON. Remove commas for items last in a list. After 'amount' and 'merchant_preferences'. JSON is picky.
late answer, I know, but ran in exactly the same issue than you.
In the create function of the billing plan
public function create($apiContext = null, $restCall = null)
{
$payLoad = $this->toJSON();
$json = self::executeCall(
"/v1/payments/billing-plans/",
"POST",
$payLoad,
null,
$apiContext,
$restCall
);
$this->fromJson($json);
return $this;
}
I found out, that the toJSON method always returned false. Why the hell!?!
I did the same as you did and copied the complete sample code into my code. Then it worked as expected. Now I checked, what the difference was in to my code.
I realized, that I used an umlauts (ä,ü,ö) in the name and description of the billing plan. I changed the umlauts to
'ä' => 'ae',
'ö' => 'oe'
'ü' => 'ue'
Then it worked fine! Maybe someone else is running in this issue, too.

Categories

Resources