Difficulty using `populate` with `groupBy` and `sum` with Waterline query in Sails.js - sails.js

I have run into a strange problem with the groupBy and sum methods when used with populate. I have a set of associated models: User, Source (books, etc), Recommendation, and Discipline (i.e. academic discipline).
I attempted the following waterline query:
Recommendation.find({
where: {discipline: '5559ea07dfa9bd0499f9f799'},
groupBy: ['source'], sum: ['rating']
}).exec(console.log);
This worked well, returning:
[
{
"source": "5571e72ab50f0c3c49fe19f6",
"rating": 4
},
{
"source": "5571b88c51861950360fac1c",
"rating": 12
}
]
I then tried it with populate on the source because I wanted to have the full source data linked to the each recommendation. So I tried:
Recommendation.find({
where: {discipline: '5559ea07dfa9bd0499f9f799'},
groupBy: ['source'], sum: ['rating']
}).populate('source').exec(console.log);
This yielded something strange:
[
{
"source": {
"type": "book",
"identifiers": [
{
"type": "ISBN_10",
"identifier": "1400823226"
},
{
"type": "ISBN_13",
"identifier": "9781400823222"
}
],
"title": "Patterns for America",
"subtitle": "Modernism and the Concept of Culture",
"publisher": "Princeton University Press",
"year": 1999,
"language": "en",
"categories": [
"Literary Criticism"
],
"abstract": "In recent decades, historians and social theorists have given much thought to the concept of \"culture,\" its origins in Western thought, and its usefulness for social analysis. In this book, Susan Hegeman focuses on the term's history in the United States in the first half of the twentieth century. She shows how, during this period, the term \"culture\" changed from being a technical term associated primarily with anthropology into a term of popular usage. She shows the connections between this movement of \"culture\" into the mainstream and the emergence of a distinctive \"American culture,\" with its own patterns, values, and beliefs. Hegeman points to the significant similarities between the conceptions of culture produced by anthropologists Franz Boas, Edward Sapir, Ruth Benedict, and Margaret Mead, and a diversity of other intellectuals, including Randolph Bourne, Van Wyck Brooks, Waldo Frank, and Dwight Macdonald. Hegeman reveals how relativist anthropological ideas of human culture--which stressed the distance between modern centers and \"primitive\" peripheries--came into alliance with the evaluating judgments of artists and critics. This anthropological conception provided a spatial awareness that helped develop the notion of a specifically American \"culture.\" She also shows the connections between this new view of \"culture\" and the artistic work of the period by, among others, Sherwood Anderson, Jean Toomer, Thomas Hart Benton, Nathanael West, and James Agee and depicts in a new way the richness and complexity of the modernist milieu in the United States.",
"imageLinks": {
"smallThumbnail": "http://bks3.books.google.de/books/content?id=OwYWU2H3me4C&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_api",
"thumbnail": "http://bks3.books.google.de/books/content?id=OwYWU2H3me4C&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api"
},
"createdAt": "2015-06-05T14:56:12.714Z",
"updatedAt": "2015-06-05T14:56:12.724Z",
"id": "5571b88c51861950360fac1c"
},
"rating": 4
},
{
"source": {
"_bsontype": "ObjectID",
"id": "Uq¸Q\u0019P6\u000f¬\u001c"
},
"rating": 12
}
]
As you can see rather than replacing the source id with the full source properties, it added the source as an object in the returned array, and then added another object with a new source id reference, and the summed rating amount. Strangely, it also attached just one of the rating values to the source object it appended to the results.
Is this what should be happening. I can't follow the logic and it feels a bit buggy. In any case, what I would like is to have the source within each returned row, alongside the summed total. Can anyone explain what's going on here, and if I made an error perhaps?

Related

Strapi API Rest V 3.6.8 how to search posts by title?

I have installed version 3.6.8 of Strapi
In the docs for v3.x
https://strapi.gitee.io/documentation/v3.x/content-api/parameters.html#filter
Filters are used as a suffix of a field name:
No suffix or eq: Equals
ne: Not equals
lt: Less than
gt: Greater than
lte: Less than or equal to
gte: Greater than or equal to
in: Included in an array of values
nin: Isn't included in an array of values
contains: Contains
ncontains: Doesn't contain
containss: Contains case sensitive
ncontainss: Doesn't contain case sensitive
null: Is null/Is not null
And I can see those examples
GET /restaurants?_where[price_gte]=3
GET /restaurants?id_in=3&id_in=6&id_in=8
etc..
So I tried
/posts?_where[title_contains]=foo
/posts?title_contains=foo
And I also tried the "new way" in V4
/posts?filters[title][contains]=foo
But all of this attempts return all the post, exactly the same than just doing
/posts?
Any idea how to filter by post title and/or post body?
Almost there my friend! The issue you are facing called deep filtering (please follow the link for documentation).
In Short: the title field is located inside the attributes object for each item
Your items may look something similar to this:
{
"data": [
{
"id": 1,
"attributes": {
"title": "Restaurant A",
"description": "Restaurant A's description"
},
"meta": {
"availableLocales": []
}
},
{
"id": 2,
"attributes": {
"title": "Restaurant B",
"description": "Restaurant B's description"
},
"meta": {
"availableLocales": []
}
},
]
}
And therefor the filter should be
/api/posts?filters[attributes][title][$contains]=Restaurant
Also note:
the $ sign that should be included for your operator (in our case contains)
the api prefix you should use before the plural api id (e.g. posts, users, etc.)
you may prefer using $containsi operator in order to ignore upper and lower case letters (better for searching operations)
Let me know if it worked for you!

How to make child-card Discussion notes rollup to parent card?

How to make child-card Discussion notes rollup to parent card in Azure DevOps?
The way we use ADO is like this:
User Story -> Task 1
-> Task 2
-> Task 3
Both User Story cards and Task cards contain Discussion fields, and we have hit a quandary as to "which cards' discussion fields should we use to enter ongoing notes and discussions"? The Parent (user story)? Or the child (task)? It makes more sense for devs to enter discussion notes in the tasks, but our Support people and managers like to just look at the parent User Story card where they hope to see all discussion notes.
For now I am double-entering discussion notes in both tasks and their parent user story cards, which is not only an inefficient pain, but also violates DRY.
Then it occurred to me that the ideal solution would be for user story cards to be able to display (within the Discussion section) all discussion notes from all child cards. So if I enter a note in a Task (child) card and save it, automatically it would appear as a discussion note within its parent user story card. Ideally I could still enter user-story-specific discussion notes on occasion, but all child cards' notes would be automatically pulled in and displayed (maybe readonly? editable only in the child?) in the parent card, in all cases.
Is there an easy way to make this happen?
If the answer to #1 above is no, then is there a difficult way to make it happen? Maybe via customizations or custom API calls? What would be the best way to achieve my desired result?
This is not possible out of the box in Azure DevOps (at least not to my knowledge).
However I can think of a few ways to get this done, but it requires some custom scripting, and have some drawbacks that may of may not affect your use case.
Option 1. Create a custom extension that aggregates the comments on the parent
This option gives you complete freedom of how to visually design the feature. It is also completely DRY
You can develop your own custom extension for Azure DevOps and create a dynamic section on the User Story card that pulls in the comments from all tasks.
Option 2. Setup a Web Hook for the event "Workitem commented on"
This option does is not completely DRY, but it will at least automate the copying of comments across work items.
By configuring a web hook in Azure Devops to post a json object containing information about the new comment to a REST endpoint of your choice. The payload posted looks like below.
{
"subscriptionId": "5be97cbc-ee4b-4c21-91ea-866a61d624c4",
"notificationId": 4,
"id": "fb2617ed-60df-4518-81fa-749faa6c5cd6",
"eventType": "workitem.commented",
"publisherId": "tfs",
"message": {
"markdown": "[Bug #5](http://fabrikam-fiber-inc.visualstudio.com/web/wi.aspx?pcguid=74e918bf-3376-436d-bd20-8e8c1287f465&id=5) (Some great new idea!) commented on by Jamal Hartnett."
},
"detailedMessage": {
"markdown": "[Bug #5](http://fabrikam-fiber-inc.visualstudio.com/web/wi.aspx?pcguid=74e918bf-3376-436d-bd20-8e8c1287f465&id=5) (Some great new idea!) commented on by Jamal Hartnett.\r\nThis is a great new idea"
},
"resource": {
"id": 5,
"rev": 4,
"fields": {
"System.AreaPath": "FabrikamCloud",
"System.TeamProject": "FabrikamCloud",
"System.IterationPath": "FabrikamCloud\\Release 1\\Sprint 1",
"System.WorkItemType": "Bug",
"System.State": "New",
"System.Reason": "New defect reported",
"System.CreatedDate": "2014-07-15T17:42:44.663Z",
"System.CreatedBy": {
"displayName": "Jamal Hartnett",
"url": "https://vssps.dev.azure.com/fabrikam/_apis/Identities/e5a5f7f8-6507-4c34-b397-6c4818e002f4",
"_links": {
"avatar": {
"href": "https://dev.azure.com/mseng/_apis/GraphProfile/MemberAvatars/aad.YTkzODFkODYtNTYxYS03ZDdiLWJjM2QtZDUzMjllMjM5OTAz"
}
},
"id": "e5a5f7f8-6507-4c34-b397-6c4818e002f4",
"uniqueName": "Jamal Hartnett",
"imageUrl": "https://dev.azure.com/fabrikam/_api/_common/identityImage?id=e5a5f7f8-6507-4c34-b397-6c4818e002f4",
"descriptor": "ukn.VXkweExUVXRNakV0TWpFME5qYzNNekE0TlMwNU1ETXpOak15T0RVdE56RTVNelEwTnpBM0xURXpPRGswTlRN"
},
"System.ChangedDate": "2014-07-15T17:42:44.663Z",
"System.ChangedBy": {
"displayName": "Jamal Hartnett",
"url": "https://vssps.dev.azure.com/fabrikam/_apis/Identities/e5a5f7f8-6507-4c34-b397-6c4818e002f4",
"_links": {
"avatar": {
"href": "https://dev.azure.com/mseng/_apis/GraphProfile/MemberAvatars/aad.YTkzODFkODYtNTYxYS03ZDdiLWJjM2QtZDUzMjllMjM5OTAz"
}
},
"id": "e5a5f7f8-6507-4c34-b397-6c4818e002f4",
"uniqueName": "Jamal Hartnett",
"imageUrl": "https://dev.azure.com/fabrikam/_api/_common/identityImage?id=e5a5f7f8-6507-4c34-b397-6c4818e002f4",
"descriptor": "ukn.VXkweExUVXRNakV0TWpFME5qYzNNekE0TlMwNU1ETXpOak15T0RVdE56RTVNelEwTnpBM0xURXpPRGswTlRN"
},
"System.Title": "Some great new idea!",
"System.Parent": 26
"Microsoft.VSTS.Common.Severity": "3 - Medium",
"WEF_EB329F44FE5F4A94ACB1DA153FDF38BA_Kanban.Column": "New",
"System.History": "This is a great new idea"
},
"_links": {
"self": {
"href": "http://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/5"
},
"workItemUpdates": {
"href": "http://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/5/updates"
},
"workItemRevisions": {
"href": "http://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/5/revisions"
},
"workItemType": {
"href": "http://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/ea830882-2a3c-4095-a53f-972f9a376f6e/workItemTypes/Bug"
},
"fields": {
"href": "http://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/fields"
}
},
"url": "http://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/5"
},
"resourceVersion": "1.0",
"resourceContainers": {
"collection": {
"id": "c12d0eb8-e382-443b-9f9c-c52cba5014c2"
},
"account": {
"id": "f844ec47-a9db-4511-8281-8b63f4eaf94e"
},
"project": {
"id": "be9b3917-87e6-42a4-a549-2bc06a7a878f"
}
},
"createdDate": "2022-07-03T12:30:03.0691717Z"
}
In particular you have the comment message under message, the author of the message under fields.System.ChangedBy, the date of the comment in fields.System.ChangedDate and the parent workitem id in System.Parent
Using this information your REST service that receives the json object can create a comment on the parent work item using the Comments Rest API or post an update to the workitem where you set the System.History field to the value of the comment. This also allows you to set the original comment time and author, given that the user account you use in your automation has the permission Bypass rules on work item updates granted.
Drawbacks
If tasks can be moved from one user story to another, then the task comments on the user stories need to be moved. The same idea as above can be applied to solve this. By configuring a webhook for WorkItem updated you can listen for all updates to tasks.
By fetching the previous revision (Revision is found in resource.rev) from the Revision Rest API and comparing the field System.Parent you can determine whether the task has been moved or not and add the comments to the new parent and remove them from the old.
Similarly if you want to propagate comment updates and reactions, you would need to extend the webhook functionality even further.

Multiple response in action on google dialogflow

How can i get multiple response on action on google console using dialogflow ?
i simulated on Action on google console but only two responses are showing on it
where as third response are not showing
here is my json response
{
"source": "webhook",
"data": {
"google": {
"is_ssml": true,
"permissions_request": null,
"expect_user_response": true
}
},
"messages": [
{
"type": 0,
"speech": "peter Got around 28 marks in maths. which is ranked 1 among 3 candidate in class 1"
},
{
"textToSpeech": "peter Got around 28 marks in maths. which is ranked 1 among 3 candidate in class 1",
"platform": "google",
"displayText": "peter Got around 28 marks in maths. which is ranked 1 among 3 candidate in class 1",
"type": "simple_response"
},
{
"textToSpeech": "Working",
"platform": "google",
"displayText": "Working",
"type": "simple_response"
},
{
"textToSpeech": "Working 2",
"platform": "google",
"displayText": "Working 2",
"type": "simple_response"
}
]
}
Here is my console output
any help regarding this is much appreciated
Thank you
Regards Saif
Only two simple responses will be accepted as a response. If you want more content you will need to consolidate your text into one of the two responses.
As you can see on the AoG Responses docs, it is specified as a requirement :
At most 2 chat bubbles per turn
So your third bubble won't display, as intended by Google.
As suggested in the previous answer from Nick, you need to consolidate your text and wrap everything in your 2 bubbles. In a simple response, you can line break by adding a \n where needed.
In a Basic Card however, you can access a limited subset of markdown, as stated in the docs link I provided, like that :
New line with a double space
**bold**
*italics*
Rich responses have the following requirements and optional properties that you can configure:
Supported on surfaces with the actions.capability.SCREEN_OUTPUT
capability.
The first item in a rich response must be a simple response.
At most two simple responses.
At most one basic card or StructuredResponse.
At most 8 suggestion chips. (you can add more than 8 also but you will get a warning not an error.)
Suggestion chips are not allowed in a FinalResponse
Linking out to the web from smart displays is currently not
supported.

Can I access ReimburseCharge objects in the IPP QBO v3 API?

I queried an Invoice that contains a billable expense charge. The response includes (and I'm showing just the relevant portions of it):
....
"Line": [
{
"LineNum": 1,
"DescriptionLineDetail": {
"ServiceDate": "2015-11-15"
},
"Id": "3",
"DetailType": "DescriptionOnly",
"Description": "Test Billable Transaction 1"
},
{
"LineNum": 2,
"DescriptionLineDetail": {
"ServiceDate": "2015-11-15"
},
"Id": "4",
"DetailType": "DescriptionOnly",
"Description": "Test Billable Expense Transaction 3"
},
{
"DetailType": "SubTotalLineDetail",
"Amount": 8.01,
"SubTotalLineDetail": {}
}
],
"LinkedTxn": [
{
"TxnId": "1938",
"TxnType": "ReimburseCharge"
},
{
"TxnId": "1932",
"TxnType": "ReimburseCharge"
}
],
...
I tried querying the API for ReimburseCharge and got only errors back. Is this business object on the roadmap?
On a related note, I observe that a billable line (at least in Purchase objects) can have its BillableStatus attribute set to "HasBeenBilled" with an Update call. It cannot be set back to "Billable" without first setting it to "NotBillable", but this does seem to work more than once so that it's not a one-way effect. If the line has actually been billed though, I get a validation fault when I try to change the BillableStatus from "HasBeenBilled" to "NotBillable", which I suppose makes sense.
Here's what's decidedly problematic though: I cannot use the API to either link a billable expense to an invoice or figure out where an already-linked expense is invoiced. Also, I cannot see the amount of the individual lines contained in these "DescriptionOnly" lines, so all I get is the total. Does Intuit have plans to change this and, if so, when?
This decision for supporting Reimb Charge is still pending.
Regarding DescriptionOnly- This was meant to support only total and sub totals.
So, if you have to use lines then you should use SalesItemLineDetail

hat is the proper structure for Parcel Delivery schema if your delivery contains multiple tracking numbers?

It is possible for our orders to contain multiple SKU's as well as multiple tracking numbers per SKU on an order.
I have been referencing https://developers.google.com/gmail/markup/reference/parcel-delivery. We are also using the JSON-LD format.
{
"#context":"http://schema.org",
"#type":"ParcelDelivery",
"deliveryAddress":{
"#type":"PostalAddress",
"name":"John Frank",
"streetAddress":"24 Willie Mays Plaza",
"addressLocality":"San Francisco",
"addressRegion":"CA",
"addressCountry":"US",
"postalCode":"94107"
},
"originAddress":{
"#type":"PostalAddress",
"name":"John Frank",
"streetAddress":"25 Willie Mays Plaza",
"addressLocality":"San Francisco",
"addressRegion":"CA",
"addressCountry":"US",
"postalCode":"94107"
},
"expectedArrivalFrom":"2013-03-10T12:00:00-08:00",
"expectedArrivalUntil":"2013-03-12T12:00:00-08:00",
"carrier":{
"#type":"Organization",
"name":"FedEx",
"url":"http://fedex.com/"
},
"itemShipped":{
"#type":"Product",
"name":"iPod Mini",
"url":"http://apple.com/ipad32gb",
"image":"http://apple.com/images/ipad32gb.jpg",
"sku":"B00DR0PDNE",
"description":"iPod Mini 32Gb White",
"brand":{
"#type":"Brand",
"name":"Apple"
},
"color":"white"
},
"trackingNumber":"3453291231",
"trackingUrl":"http://fedex.com/track/3453291231",
"potentialAction":{
"#type":"TrackAction",
"target":"http://fedex.com/track/3453291231"
},
"hasDeliveryMethod":"http://schema.org/ParcelService",
"partOfOrder":{
"#type":"Order",
"orderNumber":"176057",
"merchant":{
"#type":"Organization",
"name":"Bob Dole",
"sameAs":"http://www.freebase.com/m/0fhkx"
},
"orderStatus":"http://schema.org/OrderInTransit"
}
}
I checked previous questions on SO and can not seem to find an answer on google or in their official documentation or schema.org. Any advice would be greatly appreciated. Cheers.
Please correct me if I am wrong but after some research I am quite certain you just need to replicate the same json snippet for each parcel in the order. This is how it would work if you were not using JSON-LD so it makes sense it would work the same way. Cheers.