ngfor display not according to array received - ionic-framework

Below is the object i receive from the backend
{
"30-04-2022": [
{
"id": 3,
"user_id": 3,
"amount": 178000,
"created_at": "2022-04-30T17:12:12.000000Z",
"updated_at": "2022-04-30T08:39:45.000000Z",
},
{
"id": 4,
"user_id": 4,
"amount": 101500,
"created_at": "2022-04-30T20:13:13.000000Z",
"updated_at": "2022-04-30T08:39:33.000000Z",
}
],
"24-04-2022": [
{
"id": 3,
"user_id": 3,
"amount": 178000,
"created_at": "2022-04-30T17:12:12.000000Z",
"updated_at": "2022-04-30T08:39:45.000000Z",
},
{
"id": 4,
"user_id": 4,
"amount": 101500,
"created_at": "2022-04-30T20:13:13.000000Z",
"updated_at": "2022-04-30T08:39:33.000000Z",
}
]}
But the display in ngfor is reversed. Cant understand why this is happening. Please refer to the image below.
is there a way to display items as it is show in the object without reversing its order

Related

Strapi multi-level population with field selection

I want to populate a multilevel relational field on strapi with REST API with specific field selection, but only the id comes up at the response.
When I populate the field without field selections with a GET request at: localhost:1337/api/home?populate[0]=Reasons&populate[1]=Reasons.IconsList&populate[2]=Reasons.IconsList.Icon, I
get this JSON response:
{
"data": {
"id": 1,
"attributes": {
"createdAt": "2022-10-31T11:24:55.202Z",
"updatedAt": "2022-11-09T13:50:40.445Z",
"publishedAt": "2022-10-31T11:26:30.944Z",
"PageInfo": "Homepage",
"Reasons": {
"id": 1,
"IconsList": [
{
"id": 1,
"Content": "Free cancellation on most bookings",
"Icon": {
"data": {
"id": 3,
"attributes": {
"name": "cancellation.svg",
"alternativeText": "Free cancellation on most bookings",
"caption": "cancellation.svg",
"width": 21,
"height": 21,
"formats": null,
"hash": "cancellation_b2308d4b63",
"ext": ".svg",
"mime": "image/svg+xml",
"size": 1.57,
"url": "/uploads/cancellation_b2308d4b63.svg",
"previewUrl": null,
"provider": "local",
"provider_metadata": null,
"createdAt": "2022-10-20T12:02:37.735Z",
"updatedAt": "2022-10-31T11:23:48.326Z"
}
}
}
},
{
"id": 2,
"Content": "No credit card fees",
"Icon": {
"data": {
"id": 5,
"attributes": {
"name": "credit-card.svg",
"alternativeText": "credit-card.svg",
"caption": "credit-card.svg",
"width": 22,
"height": 16,
"formats": null,
"hash": "credit_card_06b9eca40f",
"ext": ".svg",
"mime": "image/svg+xml",
"size": 0.89,
"url": "/uploads/credit_card_06b9eca40f.svg",
"previewUrl": null,
"provider": "local",
"provider_metadata": null,
"createdAt": "2022-10-20T12:21:46.342Z",
"updatedAt": "2022-10-20T12:21:46.342Z"
}
}
}
},
{
"id": 3,
"Content": "24/7 Customer care",
"Icon": {
"data": {
"id": 2,
"attributes": {
"name": "customer-care.svg",
"alternativeText": "24/7 Customer care",
"caption": "customer-care.svg",
"width": 20,
"height": 22,
"formats": null,
"hash": "customer_care_6aa8ac8eea",
"ext": ".svg",
"mime": "image/svg+xml",
"size": 1.48,
"url": "/uploads/customer_care_6aa8ac8eea.svg",
"previewUrl": null,
"provider": "local",
"provider_metadata": null,
"createdAt": "2022-10-20T12:02:37.734Z",
"updatedAt": "2022-10-20T12:04:39.792Z"
}
}
}
}
]
}
}
},
"meta": {}
}
Following this guide: https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/populating-fields.html#combining-population-with-other-operators, when I try to define the fields I want from the response: localhost:1337/api/home?fields[0]=PageInfo&populate[Reasons][IconsList]fields]=Content, I only get this JSON:
{
"data": {
"id": 1,
"attributes": {
"PageInfo": "Homepage",
"Reasons": {
"id": 1
}
}
},
"meta": {}
}
I want to get IconsList's Content and Icon.alternativeText and Icon.url but I cannot find how to build my query parameters.
For future reference to this problem, my question was answered on Strapi forum: https://forum.strapi.io/t/strapi-multi-level-population-with-field-selection/23473
This tutorial explains the reasoning behind deep populating and filtering and it's really interesting.
The problem was that you need to pupulate the relational field again like that: localhost:1337/api/home?fields[0]=PageInfo&populate[Reasons][populate][IconsList][fields][0]=Content to be able to access its data.

How to check $exists in one to many relationship mongodb sails js?

Is there any way to find records that collection is empty?
For example please find below array. I want only that records with index "companydata" is empty. and also how can i get data that does not have empty "companydata" data.
Thanks in advance.
[
{
"company_id": {
"company_name": "C2",
"slug": "c2",
"is_organized": 1,
"status": "1",
"id": "5adf158f547f7f0314ca8b56",
"companydata": []
},
"user_id": "5ab889aee74a151b50d04ec1",
"status": "0",
"id": "5ae014e7432e85298081be0b"
},
{
"company_id": {
"company_name": "My Compnay",
"slug": "my-compnay",
"is_organized": 1,
"status": "1",
"id": "5ad442d98a0e0c1358ca93df",
"companydata": [
{
"name": "Bhavesh Amin",
"company_id": "5ad442d98a0e0c1358ca93df",
"status": "0",
"id": "5ad442da8a0e0c1358ca93e0"
}
]
},
"user_id": "5ab889aee74a151b50d04ec1",
"status": "0",
"id": "5ae01388432e85298081bdf8"
},
{
"company_id": {
"company_name": "Organization Name",
"slug": "organization-name",
"is_organized": 1,
"status": "1",
"id": "5ad08f9b938d1131eceea624",
"companydata": [
{
"name": "Helen H. Langley",
"company_id": "5ad08f9b938d1131eceea624",
"status": "1",
"id": "5ad08f9b938d1131eceea625"
}
]
},
"user_id": "5ab889aee74a151b50d04ec1",
"status": "0",
"id": "5ad42a5f52851a2b1449db2d"
},
]

How to search by certain objects keys values

First sorry for my bad English!
Suppose this document looks like this:
{
"id": "598969845c274c145a935994",
"contract_ref": "ABCDEF1234",
"currency": "USD",
"per_unit_cost": [
{
"size": 22,
"price": 1000
},
{
"size": 42,
"price": 1500
}
]
},
{
"id": "598969845c274c145a93599b",
"contract_ref": "ABCDEF1234",
"currency": "USD",
"per_unit_cost": [
{
"size": 22,
"price": 1234
}
]
}
How do you find 'per_unit_cost.size' that exactly match with '$all' [22], i.e. retrieve the second document and ignore the first?

Update single sub document in multiple array in mgo

I have following mongodb (3.4.x) document, i code in golang with mgo driver
{
"id": "5981d4c2795a1b4a801ee027",
"scenarioId": "59804b10d8ee910085e33865",
"messages": [
{
"id": "5981d4c2795a1b4a801ee028",
"toQueue": [
{
"id": "5981d4c2795a1b4a801ee029",
"to": {
"email": "some#email.com"
},
"channel": "EMAIL",
"toType": "EMAIL",
"status": {
"id": 1,
"groupId": 1,
"groupName": "PROCESSING",
"name": "APPROVED",
"description": "MessageChain approved for processing"
}
},
{
"id": "5981d4c2795a1b4a801ee02a",
"to": {
"phone": "+381631891245"
},
"channel": "SMS",
"toType": "PHONE",
"status": {
"id": 1,
"groupId": 1,
"groupName": "PROCESSING",
"name": "APPROVED",
"description": "MessageChain approved for processing"
}
}
],
"status": {
"id": 1,
"groupId": 1,
"groupName": "PROCESSING",
"name": "APPROVED",
"description": "MessageChain approved for processing"
}
},
{
"id": "5981d4c2795a1b4a801ee02b",
"toQueue": [
{
"id": "5981d4c2795a1b4a801ee02c",
"to": {
"phone": "+123456789"
},
"channel": "SMS",
"toType": "PHONE",
"status": {
"id": 1,
"groupId": 1,
"groupName": "PROCESSING",
"name": "APPROVED",
"description": "MessageChain approved for processing"
}
}
],
"status": {
"id": 1,
"groupId": 1,
"groupName": "PROCESSING",
"name": "APPROVED",
"description": "MessageChain approved for processing"
}
}
],
"messageStages": [
{
"id": "5981d4c2795a1b4a801ee033",
"validityPeriod": 5,
"validityPeriodTimeUnit": "MINUTES",
"providerId": 5,
"email": {
"text": "this is the email text",
"subject": "and here the email subject"
},
"status": {
"id": 1,
"groupId": 1,
"groupName": "PROCESSING",
"name": "APPROVED",
"description": "MessageChain approved for processing"
}
}
]
}
and I know the value of messages.$.toQueue.id, where i want to update status.id in the related toQueue Array Item.
I tried to do it that way:
query = bson.M{
"messages.toQueue._id": toQueueId,
}
update = bson.M{
"$set": bson.M{
"messages.$.toQueue.$.status.id": status.Id,
"messages.$.toQueue.$.status.name": status.Name,
"messages.$.toQueue.$.status.groupId": status.GroupId,
"messages.$.toQueue.$.status.groupName": status.GroupName,
"messages.$.toQueue.$.status.description": status.Description,
},
}
err = cr.Update(query,update)
but multiple $ are not allowed. Without it's also not updateable.
Is there any way to update only the subdocument, which i found in query ?
Neil Lunn gave the right answer.
It's not possible to work with nested arrays the way I tried to do. And he is also right, that problem is coming from design mistake.
So I changed it as him and Markus W Mahlberg suggested to move the toQueue part in a separate collection, with messageId as a reference.

How JSON format for calling Checking out REST Api of Broadleaf commerce looks like

I have followed setting up Broadleaf to make it running by following its documentation (http://docs.broadleafcommerce.org/current/REST-Tutorials.html). I wanted to do checking out the cart using REST Api; that's, /cart/checkout. Therefore, I looked inside the code in order to understand how the JSON format being sent will look alike. By looking through the code, I found that it is required to pass the JSON data as shown following:
{
"paymentInfo": {
"id": ,
"orderId": ,
"type": ,
"address": {
"id":
"firstname":
"lastname":
"addressLine1":
"addressLine2":
"city":
"state":
"country":
"postalCode":
},
"phone": "",
"additionalFields": "",
"amount": "",
"amountItems": "",
"customerIpAddress": "",
"referenceNumber": ""
},
"referenced": {
"id": "",
"referenceNumber": "",
"type": "",
"pan": "",
"cvvCode:" "",
"expirationMonth": "",
"expirationYear": "",
"accountNumber": "",
"routingNumber": "",
"pin": ""
}
}
However, I have no idea such the JSON data looks like. Therefore, if anyone who has ever used the api, please help me by showing an example of data in order to make the request. Looking forward to the answers.
Thanks in advance.
All of our REST APIs are exposed through a 'wrapper' concept. For instance, there is a CustomerWrapper, OrderWrapper, etc. These wrappers define which properties are serialized back and forth with the REST APIs.
For your specific case, you should look at PaymentReferenceMapWrapper.
{
"id": 1751,
"status": "IN_PROCESS",
"totalTax": {
"amount": "0.00",
"currency": "INR"
},
"totalShipping": {
"amount": "0.00",
"currency": "INR"
},
"subTotal": {
"amount": "860.00",
"currency": "INR"
},
"total": {
"amount": "860.00",
"currency": "INR"
},
"customer": {
"id": 2600
},
"orderItems": [
{
"id": 1752,
"name": "abc",
"quantity": 2,
"retailPrice": {
"amount": "430.00",
"currency": "INR"
},
"salePrice": {
"amount": "430.00",
"currency": "INR"
},
"orderId": 1751,
"categoryId": 10300,
"skuId": 10212,
"productId": 10212,
"isBundle": false,
"orderItemPriceDetails": [
{
"id": 1752,
"totalAdjustmentValue": {
"amount": "0.00",
"currency": "INR"
},
"totalAdjustedPrice": {
"amount": "860.00",
"currency": "INR"
},
"quantity": 2,
"adjustments": []
}
],
"isDiscountingAllowed": true
}
],
"fulfillmentGroups": [
{
"id": 1502,
"orderId": 1751,
"total": {
"amount": "860.00",
"currency": "INR"
},
"fulfillmentGroupItems": [
{
"id": 1752,
"fulfillmentGroupId": 1502,
"orderItemId": 1752,
"totalTax": {
"amount": "0.00",
"currency": "INR"
},
"quantity": 2,
"totalItemAmount": {
"amount": "860.00",
"currency": "INR"
}
}
]
}
],
"payments": [
{
"id": 601,
"orderId": 1751,
"type": "COD",
"amount": "860.00",
"currency": "INR",
"gatewayType": "Passthrough",
"transactions": [
{
"id": 601,
"orderPaymentId": 601,
"type": "AUTHORIZE_AND_CAPTURE",
"success": true,
"amount": "860.00",
"currency": "INR"
}
]
}
]
}
This is the same json you will get from /cart?customerId="" with method GET after successfully executing /cart/checkout/payment