Getting undefined error when dynamically looping through JSON - javascript

I'm trying to output all of the customer id's within my JSON data. I am using ejs as my templating engine. So far I'm only able to succsefully output 1 customer id via:
<p><%= jsonOrderData.orders[0].customer.id %></p>
When I try to loop through each order I get Cannot read property 'id' of undefined
for loop to loop through
<% for (var i = 0; i < jsonOrderData.orders.length; i++) {%>
<p>Customer: <%= jsonOrderData.orders[i].customer.id %></p>
<% }; %>
If I remove the .id after customer the error then goes away. It then outputs
Customer:[object Object] 50 times which is the legth of the json data.
I don't understand why it's not working within the loop when adding .id when it works fine without the loop manually setting the index?
JSON DATA (Cut Down 2 Orders)
{
"orders": [
{
"id": 533078016054,
"email": "email#gmail.com",
"closed_at": null,
"created_at": "2018-08-10T05:03:36+01:00",
"updated_at": "2018-08-10T05:03:37+01:00",
"number": 52,
"note": "",
"token": "f4877048c08eb98180ee5fda34f978bc",
"gateway": "manual",
"test": false,
"total_price": "13.98",
"subtotal_price": "13.98",
"total_weight": 0,
"total_tax": "0.00",
"taxes_included": false,
"currency": "GBP",
"financial_status": "pending",
"confirmed": true,
"total_discounts": "0.00",
"total_line_items_price": "13.98",
"cart_token": null,
"buyer_accepts_marketing": false,
"name": "#MW1052",
"referring_site": null,
"landing_site": null,
"cancelled_at": null,
"cancel_reason": null,
"total_price_usd": "18.00",
"checkout_token": null,
"reference": null,
"user_id": 1706983449,
"location_id": null,
"source_identifier": null,
"source_url": null,
"processed_at": "2018-08-10T05:03:36+01:00",
"device_id": null,
"phone": null,
"customer_locale": null,
"app_id": 1354745,
"browser_ip": null,
"landing_site_ref": null,
"order_number": 1052,
"discount_applications": [],
"discount_codes": [],
"note_attributes": [],
"payment_gateway_names": [
"manual"
],
"processing_method": "manual",
"checkout_id": null,
"source_name": "shopify_draft_order",
"fulfillment_status": null,
"tax_lines": [],
"tags": "",
"contact_email": "email#gmail.com",
"order_status_url": "https://checkout.shopify.com/1245839385/orders/f4877048c08eb98180ee5fda34f978bc/authenticate?key=redacted",
"admin_graphql_api_id": "gid://shopify/Order/redacted",
"line_items": [
{
"id": 1350736445494,
"variant_id": 8725905539126,
"title": "Fruit of the Loom Poly/Cotton Piqué Polo Shirt",
"quantity": 1,
"price": "6.99",
"sku": "ss15",
"variant_title": "S / Bottle Green",
"vendor": "Fruit Of The Loom",
"fulfillment_service": "manual",
"product_id": 719146287158,
"requires_shipping": true,
"taxable": false,
"gift_card": false,
"name": "Fruit of the Loom Poly/Cotton Piqué Polo Shirt - S / Bottle Green",
"variant_inventory_management": "shopify",
"properties": [],
"product_exists": true,
"fulfillable_quantity": 1,
"grams": 0,
"total_discount": "0.00",
"fulfillment_status": null,
"discount_allocations": [],
"admin_graphql_api_id": "gid://shopify/LineItem/1350736445494",
"tax_lines": [
{
"title": "VAT",
"price": "0.00",
"rate": 0.2
}
]
},
{
"id": 1350736478262,
"variant_id": 8725905440822,
"title": "Fruit of the Loom Poly/Cotton Piqué Polo Shirt",
"quantity": 1,
"price": "6.99",
"sku": "ss12",
"variant_title": "S / Heather Grey",
"vendor": "Fruit Of The Loom",
"fulfillment_service": "manual",
"product_id": 719146287158,
"requires_shipping": true,
"taxable": false,
"gift_card": false,
"name": "Fruit of the Loom Poly/Cotton Piqué Polo Shirt - S / Heather Grey",
"variant_inventory_management": "shopify",
"properties": [],
"product_exists": true,
"fulfillable_quantity": 1,
"grams": 0,
"total_discount": "0.00",
"fulfillment_status": null,
"discount_allocations": [],
"admin_graphql_api_id": "gid://shopify/LineItem/1350736478262",
"tax_lines": [
{
"title": "VAT",
"price": "0.00",
"rate": 0.2
}
]
}
],
"shipping_lines": [],
"billing_address": {
"first_name": "John",
"address1": "17A Oaklands Business Centre",
"phone": null,
"city": "Worthing",
"zip": "BN11 5LH",
"province": null,
"country": "United Kingdom",
"last_name": "Doe",
"address2": "Elm Grove",
"company": null,
"latitude": 50.8162744,
"longitude": -0.4010653,
"name": "Jogn Doe",
"country_code": "GB",
"province_code": null
},
"shipping_address": {
"first_name": "John",
"address1": "17A Oaklands Business Centre",
"phone": null,
"city": "Worthing",
"zip": "BN11 5LH",
"province": null,
"country": "United Kingdom",
"last_name": "Doe",
"address2": "Elm Grove",
"company": null,
"latitude": 50.8162744,
"longitude": -0.4010653,
"name": "John Doe",
"country_code": "GB",
"province_code": null
},
"fulfillments": [],
"refunds": [],
"customer": {
"id": 556974014518,
"email": "email#gmail.com",
"accepts_marketing": false,
"created_at": "2018-06-26T00:26:55+01:00",
"updated_at": "2018-08-10T05:03:36+01:00",
"first_name": "John",
"last_name": "Doe",
"orders_count": 22,
"state": "enabled",
"total_spent": "0.00",
"last_order_id": 533078016054,
"note": null,
"verified_email": true,
"multipass_identifier": null,
"tax_exempt": false,
"phone": null,
"tags": "",
"last_order_name": "#MW1052",
"admin_graphql_api_id": "gid://shopify/Customer/556974014518",
"default_address": {
"id": 601657278518,
"customer_id": 556974014518,
"first_name": "John",
"last_name": "Doe",
"company": null,
"address1": "17A Oaklands Business Centre",
"address2": "Elm Grove",
"city": "Worthing",
"province": null,
"country": "United Kingdom",
"zip": "BN11 5LH",
"phone": null,
"name": "John Doe",
"province_code": null,
"country_code": "GB",
"country_name": "United Kingdom",
"default": true
}
}
},
{
"id": 532977778742,
"email": "james#bungeedesign.com",
"closed_at": null,
"created_at": "2018-08-09T22:18:53+01:00",
"updated_at": "2018-08-09T22:18:53+01:00",
"number": 51,
"note": "",
"token": "a292d75bd7011cf255a1bf236b23d0a5",
"gateway": "manual",
"test": false,
"total_price": "6.99",
"subtotal_price": "6.99",
"total_weight": 0,
"total_tax": "0.00",
"taxes_included": false,
"currency": "GBP",
"financial_status": "pending",
"confirmed": true,
"total_discounts": "0.00",
"total_line_items_price": "6.99",
"cart_token": null,
"buyer_accepts_marketing": true,
"name": "#MW1051",
"referring_site": null,
"landing_site": null,
"cancelled_at": null,
"cancel_reason": null,
"total_price_usd": "9.00",
"checkout_token": null,
"reference": null,
"user_id": 1706983449,
"location_id": 1327759385,
"source_identifier": null,
"source_url": null,
"processed_at": "2018-08-09T22:18:53+01:00",
"device_id": null,
"phone": null,
"customer_locale": null,
"app_id": 1354745,
"browser_ip": null,
"landing_site_ref": null,
"order_number": 1051,
"discount_applications": [],
"discount_codes": [],
"note_attributes": [],
"payment_gateway_names": [
"manual"
],
"processing_method": "manual",
"checkout_id": null,
"source_name": "shopify_draft_order",
"fulfillment_status": null,
"tax_lines": [],
"tags": "",
"contact_email": "james#bungeedesign.com",
"order_status_url": "https://checkout.shopify.com/1245839385/orders/a292d75bd7011cf255a1bf236b23d0a5/authenticate?key=9322877ce6ce34be2feeb127d73d0f89",
"admin_graphql_api_id": "gid://shopify/Order/532977778742",
"line_items": [
{
"id": 1350552453174,
"variant_id": 8725905408054,
"title": "Fruit of the Loom Poly/Cotton Piqué Polo Shirt",
"quantity": 1,
"price": "6.99",
"sku": "ss11",
"variant_title": "S / Black",
"vendor": "Fruit Of The Loom",
"fulfillment_service": "manual",
"product_id": 719146287158,
"requires_shipping": true,
"taxable": false,
"gift_card": false,
"name": "Fruit of the Loom Poly/Cotton Piqué Polo Shirt - S / Black",
"variant_inventory_management": "shopify",
"properties": [],
"product_exists": true,
"fulfillable_quantity": 1,
"grams": 0,
"total_discount": "0.00",
"fulfillment_status": null,
"discount_allocations": [],
"admin_graphql_api_id": "gid://shopify/LineItem/1350552453174",
"tax_lines": [
{
"title": "VAT",
"price": "0.00",
"rate": 0.2
}
]
}
],
"shipping_lines": [],
"fulfillments": [],
"refunds": [],
"customer": {
"id": 552537620534,
"email": "james#bungeedesign.com",
"accepts_marketing": true,
"created_at": "2018-06-15T10:44:13+01:00",
"updated_at": "2018-08-09T22:18:53+01:00",
"first_name": "James",
"last_name": "Rogers",
"orders_count": 18,
"state": "enabled",
"total_spent": "0.00",
"last_order_id": 532977778742,
"note": null,
"verified_email": true,
"multipass_identifier": null,
"tax_exempt": false,
"phone": null,
"tags": "password page, prospect",
"last_order_name": "#MW1051",
"admin_graphql_api_id": "gid://shopify/Customer/552537620534"
}
}
]
}

What you have runs fine. It might be possible that something is getting lost in translation or .id is at another level. My guess is that you are not setting the variable jsonOrderData as you are expecting.
If you do console.log(jsonOrderData); do you get what you expect?
This works fine:
const json = {
"orders": [
{
"id": 533078016054,
"email": "email#gmail.com",
"closed_at": null,
"created_at": "2018-08-10T05:03:36+01:00",
"updated_at": "2018-08-10T05:03:37+01:00",
"number": 52,
"note": "",
"token": "f4877048c08eb98180ee5fda34f978bc",
"gateway": "manual",
"test": false,
"total_price": "13.98",
"subtotal_price": "13.98",
"total_weight": 0,
"total_tax": "0.00",
"taxes_included": false,
"currency": "GBP",
"financial_status": "pending",
"confirmed": true,
"total_discounts": "0.00",
"total_line_items_price": "13.98",
"cart_token": null,
"buyer_accepts_marketing": false,
"name": "#MW1052",
"referring_site": null,
"landing_site": null,
"cancelled_at": null,
"cancel_reason": null,
"total_price_usd": "18.00",
"checkout_token": null,
"reference": null,
"user_id": 1706983449,
"location_id": null,
"source_identifier": null,
"source_url": null,
"processed_at": "2018-08-10T05:03:36+01:00",
"device_id": null,
"phone": null,
"customer_locale": null,
"app_id": 1354745,
"browser_ip": null,
"landing_site_ref": null,
"order_number": 1052,
"discount_applications": [],
"discount_codes": [],
"note_attributes": [],
"payment_gateway_names": [
"manual"
],
"processing_method": "manual",
"checkout_id": null,
"source_name": "shopify_draft_order",
"fulfillment_status": null,
"tax_lines": [],
"tags": "",
"contact_email": "email#gmail.com",
"order_status_url": "https://checkout.shopify.com/1245839385/orders/f4877048c08eb98180ee5fda34f978bc/authenticate?key=redacted",
"admin_graphql_api_id": "gid://shopify/Order/redacted",
"line_items": [
{
"id": 1350736445494,
"variant_id": 8725905539126,
"title": "Fruit of the Loom Poly/Cotton Piqué Polo Shirt",
"quantity": 1,
"price": "6.99",
"sku": "ss15",
"variant_title": "S / Bottle Green",
"vendor": "Fruit Of The Loom",
"fulfillment_service": "manual",
"product_id": 719146287158,
"requires_shipping": true,
"taxable": false,
"gift_card": false,
"name": "Fruit of the Loom Poly/Cotton Piqué Polo Shirt - S / Bottle Green",
"variant_inventory_management": "shopify",
"properties": [],
"product_exists": true,
"fulfillable_quantity": 1,
"grams": 0,
"total_discount": "0.00",
"fulfillment_status": null,
"discount_allocations": [],
"admin_graphql_api_id": "gid://shopify/LineItem/1350736445494",
"tax_lines": [
{
"title": "VAT",
"price": "0.00",
"rate": 0.2
}
]
},
{
"id": 1350736478262,
"variant_id": 8725905440822,
"title": "Fruit of the Loom Poly/Cotton Piqué Polo Shirt",
"quantity": 1,
"price": "6.99",
"sku": "ss12",
"variant_title": "S / Heather Grey",
"vendor": "Fruit Of The Loom",
"fulfillment_service": "manual",
"product_id": 719146287158,
"requires_shipping": true,
"taxable": false,
"gift_card": false,
"name": "Fruit of the Loom Poly/Cotton Piqué Polo Shirt - S / Heather Grey",
"variant_inventory_management": "shopify",
"properties": [],
"product_exists": true,
"fulfillable_quantity": 1,
"grams": 0,
"total_discount": "0.00",
"fulfillment_status": null,
"discount_allocations": [],
"admin_graphql_api_id": "gid://shopify/LineItem/1350736478262",
"tax_lines": [
{
"title": "VAT",
"price": "0.00",
"rate": 0.2
}
]
}
],
"shipping_lines": [],
"billing_address": {
"first_name": "John",
"address1": "17A Oaklands Business Centre",
"phone": null,
"city": "Worthing",
"zip": "BN11 5LH",
"province": null,
"country": "United Kingdom",
"last_name": "Doe",
"address2": "Elm Grove",
"company": null,
"latitude": 50.8162744,
"longitude": -0.4010653,
"name": "Jogn Doe",
"country_code": "GB",
"province_code": null
},
"shipping_address": {
"first_name": "John",
"address1": "17A Oaklands Business Centre",
"phone": null,
"city": "Worthing",
"zip": "BN11 5LH",
"province": null,
"country": "United Kingdom",
"last_name": "Doe",
"address2": "Elm Grove",
"company": null,
"latitude": 50.8162744,
"longitude": -0.4010653,
"name": "John Doe",
"country_code": "GB",
"province_code": null
},
"fulfillments": [],
"refunds": [],
"customer": {
"id": 556974014518,
"email": "email#gmail.com",
"accepts_marketing": false,
"created_at": "2018-06-26T00:26:55+01:00",
"updated_at": "2018-08-10T05:03:36+01:00",
"first_name": "John",
"last_name": "Doe",
"orders_count": 22,
"state": "enabled",
"total_spent": "0.00",
"last_order_id": 533078016054,
"note": null,
"verified_email": true,
"multipass_identifier": null,
"tax_exempt": false,
"phone": null,
"tags": "",
"last_order_name": "#MW1052",
"admin_graphql_api_id": "gid://shopify/Customer/556974014518",
"default_address": {
"id": 601657278518,
"customer_id": 556974014518,
"first_name": "John",
"last_name": "Doe",
"company": null,
"address1": "17A Oaklands Business Centre",
"address2": "Elm Grove",
"city": "Worthing",
"province": null,
"country": "United Kingdom",
"zip": "BN11 5LH",
"phone": null,
"name": "John Doe",
"province_code": null,
"country_code": "GB",
"country_name": "United Kingdom",
"default": true
}
}
},
{
"id": 532977778742,
"email": "james#bungeedesign.com",
"closed_at": null,
"created_at": "2018-08-09T22:18:53+01:00",
"updated_at": "2018-08-09T22:18:53+01:00",
"number": 51,
"note": "",
"token": "a292d75bd7011cf255a1bf236b23d0a5",
"gateway": "manual",
"test": false,
"total_price": "6.99",
"subtotal_price": "6.99",
"total_weight": 0,
"total_tax": "0.00",
"taxes_included": false,
"currency": "GBP",
"financial_status": "pending",
"confirmed": true,
"total_discounts": "0.00",
"total_line_items_price": "6.99",
"cart_token": null,
"buyer_accepts_marketing": true,
"name": "#MW1051",
"referring_site": null,
"landing_site": null,
"cancelled_at": null,
"cancel_reason": null,
"total_price_usd": "9.00",
"checkout_token": null,
"reference": null,
"user_id": 1706983449,
"location_id": 1327759385,
"source_identifier": null,
"source_url": null,
"processed_at": "2018-08-09T22:18:53+01:00",
"device_id": null,
"phone": null,
"customer_locale": null,
"app_id": 1354745,
"browser_ip": null,
"landing_site_ref": null,
"order_number": 1051,
"discount_applications": [],
"discount_codes": [],
"note_attributes": [],
"payment_gateway_names": [
"manual"
],
"processing_method": "manual",
"checkout_id": null,
"source_name": "shopify_draft_order",
"fulfillment_status": null,
"tax_lines": [],
"tags": "",
"contact_email": "james#bungeedesign.com",
"order_status_url": "https://checkout.shopify.com/1245839385/orders/a292d75bd7011cf255a1bf236b23d0a5/authenticate?key=9322877ce6ce34be2feeb127d73d0f89",
"admin_graphql_api_id": "gid://shopify/Order/532977778742",
"line_items": [
{
"id": 1350552453174,
"variant_id": 8725905408054,
"title": "Fruit of the Loom Poly/Cotton Piqué Polo Shirt",
"quantity": 1,
"price": "6.99",
"sku": "ss11",
"variant_title": "S / Black",
"vendor": "Fruit Of The Loom",
"fulfillment_service": "manual",
"product_id": 719146287158,
"requires_shipping": true,
"taxable": false,
"gift_card": false,
"name": "Fruit of the Loom Poly/Cotton Piqué Polo Shirt - S / Black",
"variant_inventory_management": "shopify",
"properties": [],
"product_exists": true,
"fulfillable_quantity": 1,
"grams": 0,
"total_discount": "0.00",
"fulfillment_status": null,
"discount_allocations": [],
"admin_graphql_api_id": "gid://shopify/LineItem/1350552453174",
"tax_lines": [
{
"title": "VAT",
"price": "0.00",
"rate": 0.2
}
]
}
],
"shipping_lines": [],
"fulfillments": [],
"refunds": [],
"customer": {
"id": 552537620534,
"email": "james#bungeedesign.com",
"accepts_marketing": true,
"created_at": "2018-06-15T10:44:13+01:00",
"updated_at": "2018-08-09T22:18:53+01:00",
"first_name": "James",
"last_name": "Rogers",
"orders_count": 18,
"state": "enabled",
"total_spent": "0.00",
"last_order_id": 532977778742,
"note": null,
"verified_email": true,
"multipass_identifier": null,
"tax_exempt": false,
"phone": null,
"tags": "password page, prospect",
"last_order_name": "#MW1051",
"admin_graphql_api_id": "gid://shopify/Customer/552537620534"
}
}
]
};
for (let i = 0; i < json.orders.length; i++) {
const order = json.orders[i];
console.log(order.customer.id);
}

Related

WooCommerece RestAPI - NodeJS

Im using wc rest api with nodejs and when trying to post new order via "orders" with method POST, I simply get response containing all the existing orders..
Even if not providing any request body, or providing false request body - same response always:
WooCommerce.post("orders", {
customer_id: 2000,
})
.then((response) => {
res.send(response.data);
})
.catch((err) => {
res.status(500).send(e.response.data);
});
Response:
[
{
"id": 32941,
"parent_id": 0,
"status": "pending",
"currency": "ILS",
"version": "5.3.1",
"prices_include_tax": false,
"date_created": "2022-02-17T11:23:28",
"date_modified": "2022-02-17T11:24:39",
"discount_total": "0.00",
"discount_tax": "0.00",
"shipping_total": "0.00",
"shipping_tax": "0.00",
"cart_tax": "0.00",
"total": "9.90",
"total_tax": "0.00",
"customer_id": 110,
"order_key": "wc_order_Gv1ZIlKqqMKFt",
"billing": {
"first_name": "",
"last_name": "",
"company": "",
"address_1": "",
"address_2": "",
"city": "",
"state": "",
"postcode": "",
"country": "",
"email": "raz#king.com",
"phone": ""
},
"shipping": {
"first_name": "",
"last_name": "",
"company": "",
"address_1": "",
"address_2": "",
"city": "",
"state": "",
"postcode": "",
"country": ""
},
"payment_method": "",
"payment_method_title": "",
"transaction_id": "",
"customer_ip_address": "",
"customer_user_agent": "",
"created_via": "admin",
"customer_note": "",
"date_completed": null,
"date_paid": null,
"cart_hash": "",
"number": "32941",
"meta_data": [],
"line_items": [
{
"id": 3267,
"name": "מלפפון",
"product_id": 32409,
"variation_id": 0,
"quantity": 1,
"tax_class": "",
"subtotal": "9.90",
"subtotal_tax": "0.00",
"total": "9.90",
"total_tax": "0.00",
"taxes": [],
"meta_data": [],
"sku": "10864",
"price": 9.9,
"parent_name": null
}
],
"tax_lines": [],
"shipping_lines": [],
"fee_lines": [],
"coupon_lines": [],
"refunds": [],
"date_created_gmt": "2022-02-17T09:23:28",
"date_modified_gmt": "2022-02-17T09:24:39",
"date_completed_gmt": null,
"date_paid_gmt": null,
"currency_symbol": "₪",
"_links": {
"self": [
{
"href": "https://XXX.XXX.XXX/wp-json/wc/v3/orders/32941"
}
],
"collection": [
{
"href": "https://XXX.XXX.XXX/wp-json/wc/v3/orders"
}
],
"customer": [
{
"href": "https://XXX.XXX.XXX/wp-json/wc/v3/customers/110"
}
]
}
}
]
Please be aware that I've masked some data :)
WooCommerce.post("orders?_method=POST", order)
.then((response) => {
res.send(response.data);
})
.catch((e) => {
console.log(e);
res
.status(e?.response?.status || 500)
.send(e?.response?.statusText || e?.response?.data || "Error!");
});
Found on google that need to use native http methods like get or post and pass in the param ?_method=METHOD to define what method to use....
Working.

Compare 2 arrays of objects check for value that matches

How do we set the checkbox on the table as checked by default if there is match in 2 objects ? . I am having 2 objects 1 is selectedNewUser array of object and transactionUserTable.data array of objects which is from the api.
I want to compare if each emailAddress in transactionUserTable.data array of objects has match on emailAddress of selectedNewUser array of object if there is match or emailAddress equal then set checkbox value as checked.
Can anyone help me how can this be possible ? If anyone has any solution or ideas. Thank you and have a great day.
Compare each object of selectedNewUser emailAddress to transactionUserTable.data emailAddress
#newly added users
selectedNewUser = [
{
"emailAddress": "aaa#gmail.com",
"firstName": "aa",
"lastName": "aa",
"phoneNumber": "232",
"companyName": "bb",
"title": "CEO",
"roleId": 7,
"associatedAccount": "WLGRN",
"accountId": 4,
"roles": [
{
"id": 12,
"name": "Architect",
"isShow": true,
"transactionRoleId": 12
},
{
"id": 11,
"name": "Construction Project Director",
"isShow": true,
"transactionRoleId": 11
}
]
},
{
"emailAddress": "bbb#gmail.com",
"firstName": "bb",
"lastName": "vv",
"phoneNumber": "34",
"companyName": "test",
"title": "CEO",
"roleId": 7,
"associatedAccount": "WLGRN",
"accountId": 4,
"roles": [
{
"id": 12,
"name": "Architect",
"isShow": true,
"transactionRoleId": 12
},
{
"id": 11,
"name": "Construction Project Director",
"isShow": true,
"transactionRoleId": 11
}
]
}
]
#html code for checkbox
<div class="table" [ngStyle.gt-md]="{'overflow': 'auto'}">
<mat-table [dataSource]="transactionUserTable.dataSource" [#animateStagger]="{value:'50'}" matMultiSort
(matSortChange)="transactionUserTable.onSortEvent()">
<!-- action Column -->
<ng-container matColumnDef="action">
<mat-header-cell *matHeaderCellDef> Action - Checkbox</mat-header-cell>
<mat-cell *matCellDef="let item" fxLayoutAlign="center center">
<mat-checkbox [checked]="userSelectedStatus(item)" color="primary" [disableRipple]="true"
(change)="appendUserList($event,item)"></mat-checkbox>
</mat-cell>
</ng-container>
#Code that pulls list of users
private _transactionUserPageEvent() {
this.isTransactionUserLoading = true;
this.transactionUserTable.data = [];
this._userProfileService.getUserProfileTableDropdown(
this.accountId,
this.transactionUserTable.pageIndex + 1,
this.transactionUserTable.pageSize,
this.searchTransactionUserInput.nativeElement.value,
this.transactionUserTable.sortParams,
this.transactionUserTable.sortDirs
)
.pipe(
finalize(() => this.isTransactionUserLoading = false)
)
.subscribe({
error: err => this._notificationService.showError(err),
next: res => {
console.log("new users" , this.selectedNewUser)
this.transactionUserTable.totalElements = res.totalItemCount;
this.transactionUserTable.data = res.items as UserProfileDropdownDto[];
this.totalData = res.totalItemCount;
this.currentDisplayedData = res.lastItemOnPage;
},
complete: noop
});
}
#Sample data of list of users from api (transactionUserTable.data)
[
{
"id": 90085,
"fullName": "1a 1a",
"roleDisplay": null,
"firstName": "1a",
"lastName": "1a",
"emailAddress": "aaa#gmail.com",
"phoneNumber": "fsdfsd",
"companyName": "test",
"title": "CEO",
"lastLogin": null,
"createdDate": "08/08/2021 11:20:25 pm",
"isVerified": false,
"roleDto": null,
"status": "Active",
"securityRole": "Unlicensed User",
"lastLoggedIn": "",
"teamCount": 0,
"transactionRoleList": null
},
{
"id": 90086,
"fullName": "1a 1bb",
"roleDisplay": null,
"firstName": "1a",
"lastName": "1bb",
"emailAddress": "bbb#gmail.com",
"phoneNumber": "32423",
"companyName": "dcbvc",
"title": "vsvfd",
"lastLogin": null,
"createdDate": "08/08/2021 11:25:59 pm",
"isVerified": false,
"roleDto": null,
"status": "Active",
"securityRole": "Unlicensed User",
"lastLoggedIn": "",
"teamCount": 0,
"transactionRoleList": null
},
{
"id": 90084,
"fullName": "1aaa aaa",
"roleDisplay": null,
"firstName": "1aaa",
"lastName": "aaa",
"emailAddress": "1aaa#gmail.com",
"phoneNumber": "asdas",
"companyName": "dfvdf",
"title": "CEO",
"lastLogin": null,
"createdDate": "08/08/2021 10:32:49 pm",
"isVerified": false,
"roleDto": null,
"status": "Active",
"securityRole": "Unlicensed User",
"lastLoggedIn": "",
"teamCount": 0,
"transactionRoleList": null
},
{
"id": 40108,
"fullName": "1aaaa#gmail.com 1aaaa#gmail.com",
"roleDisplay": null,
"firstName": "1aaaa#gmail.com",
"lastName": "1aaaa#gmail.com",
"emailAddress": "1aaaa#gmail.com",
"phoneNumber": "1",
"companyName": "1aaaa#gmail.com",
"title": "1aaaa#gmail.com",
"lastLogin": null,
"createdDate": "06/08/2021 1:22:50 pm",
"isVerified": false,
"roleDto": null,
"status": "Active",
"securityRole": "Unlicensed User",
"lastLoggedIn": "",
"teamCount": 0,
"transactionRoleList": null
},
{
"id": 70083,
"fullName": "23 asdasd",
"roleDisplay": null,
"firstName": "23",
"lastName": "asdasd",
"emailAddress": "asdasasdas",
"phoneNumber": "adasda",
"companyName": "asdasd",
"title": "assdasda",
"lastLogin": null,
"createdDate": "08/08/2021 7:28:05 pm",
"isVerified": false,
"roleDto": null,
"status": "Active",
"securityRole": "Unlicensed User",
"lastLoggedIn": "",
"teamCount": 0,
"transactionRoleList": null
}
]
In your UserProfileDropdownDto add a property called checked and default it to false when you initialise it. Then in your subscribe of getUserProfileTableDropdown loop through res.items
res.items.forEach(item => {
if(item.emailAddress && selectedNewUser.findIndex((x: any) => x.emailAddress === item.emailAddress) !== -1){
item.checked = true;
}
});
Then update your mat-checkbox code as:
<mat-checkbox [checked]="item.checked" color="primary" [disableRipple]="true" (change)="appendUserList($event,item)"></mat-checkbox>

Microsoft Graph Api - Appointment Bookings dateTime Issue

So i've been using the microsoft bookings Beta Api getting the List from this URL:
GET https://graph.microsoft.com/beta/bookingBusinesses/Contosolunchdelivery#M365B489948.onmicrosoft.com/appointments
it works fine except i need to get the start -> dateTime and end -> dateTime for the specific appointment but its returning wrong start dates? even though when i go to bookings i clearly put the start time.
This is what the JSON-Example should looks like:
{
"#odata.context": "https://graph.microsoft.com/beta/$metadata#bookingBusinesses('Contosolunchdelivery%40M365B489948.onmicrosoft.com')/appointments",
"value": [
{
"id": "AAMkADKoAAA=",
"selfServiceAppointmentId": "00000000-0000-0000-0000-000000000000",
"customerId": "829e3cb5-3d4d-4319-a8de-1953aedaa166",
"customerName": "Bob Kelly",
"customerEmailAddress": "bobk#tailspintoys.com",
"customerPhone": "213-555-0108",
"customerNotes": null,
"serviceId": "57da6774-a087-4d69-b0e6-6fb82c339976",
"serviceName": "Catered bento",
"duration": "PT30M",
"preBuffer": "PT5M",
"postBuffer": "PT10M",
"priceType": "fixedPrice",
"price": 10,
"serviceNotes": null,
"optOutOfCustomerEmail": false,
"staffMemberIds": [],
"invoiceAmount": 10,
"invoiceId": "1002",
"invoiceStatus": "open",
"invoiceUrl": "theInvoiceUrl",
"customerLocation": {
"displayName": "Customer",
"locationEmailAddress": null,
"locationUri": "",
"locationType": null,
"uniqueId": null,
"uniqueIdType": null,
"address": {
"type": "home",
"postOfficeBox": "",
"street": "",
"city": "",
"state": "",
"countryOrRegion": "",
"postalCode": ""
},
"coordinates": {
"altitude": null,
"latitude": null,
"longitude": null,
"accuracy": null,
"altitudeAccuracy": null
}
},
"start": {
"dateTime": "2018-04-30T13:00:00.0000000Z",
"timeZone": "UTC"
},
"end": {
"dateTime": "2018-04-30T13:30:00.0000000Z",
"timeZone": "UTC"
},
"serviceLocation": {
"displayName": "Customer location (987 Third Avenue, Buffalo, NY 98052, USA)",
"locationEmailAddress": null,
"locationUri": "",
"locationType": null,
"uniqueId": null,
"uniqueIdType": null,
"address": {
"type": "home",
"postOfficeBox": "",
"street": "",
"city": "",
"state": "",
"countryOrRegion": "",
"postalCode": ""
},
"coordinates": {
"altitude": null,
"latitude": null,
"longitude": null,
"accuracy": null,
"altitudeAccuracy": null
}
},
"reminders": [],
"invoiceDate": {
"dateTime": "2018-04-30T13:30:00.0000000Z",
"timeZone": "UTC"
}
},
{
"id": "AAMkADKnAAA=",
"selfServiceAppointmentId": "00000000-0000-0000-0000-000000000000",
"customerId": "7ed53fa5-9ef2-4f2f-975b-27447440bc09",
"customerName": "Jordan Miller",
"customerEmailAddress": "jordanm#contoso.com",
"customerPhone": "213-555-0199",
"customerNotes": null,
"serviceId": "57da6774-a087-4d69-b0e6-6fb82c339976",
"serviceName": "Catered bento",
"duration": "PT30M",
"preBuffer": "PT5M",
"postBuffer": "PT10M",
"priceType": "fixedPrice",
"price": 10,
"serviceNotes": null,
"optOutOfCustomerEmail": false,
"staffMemberIds": [],
"invoiceAmount": 10,
"invoiceId": "1001",
"invoiceStatus": "open",
"invoiceUrl": "theInvoiceUrl",
"customerLocation": {
"displayName": "Customer",
"locationEmailAddress": null,
"locationUri": "",
"locationType": null,
"uniqueId": null,
"uniqueIdType": null,
"address": {
"type": "home",
"postOfficeBox": "",
"street": "",
"city": "",
"state": "",
"countryOrRegion": "",
"postalCode": ""
},
"coordinates": {
"altitude": null,
"latitude": null,
"longitude": null,
"accuracy": null,
"altitudeAccuracy": null
}
},
"start": {
"dateTime": "2018-05-01T12:00:00.0000000Z",
"timeZone": "UTC"
},
"end": {
"dateTime": "2018-05-01T12:30:00.0000000Z",
"timeZone": "UTC"
},
"serviceLocation": {
"displayName": "Customer location (123 First Avenue, Buffalo, NY 98052, USA)",
"locationEmailAddress": null,
"locationUri": "",
"locationType": null,
"uniqueId": null,
"uniqueIdType": null,
"address": {
"type": "home",
"postOfficeBox": "",
"street": "",
"city": "",
"state": "",
"countryOrRegion": "",
"postalCode": ""
},
"coordinates": {
"altitude": null,
"latitude": null,
"longitude": null,
"accuracy": null,
"altitudeAccuracy": null
}
},
"reminders": [],
"invoiceDate": {
"dateTime": "2018-05-01T12:30:00.0000000Z",
"timeZone": "UTC"
}
}
]
}
And this is what im getting for the start and end date time:
start:
dateTime: "0001-01-01T00:00:00.0000000Z"
timeZone: "Etc/UTC"
end:
dateTime: "0001-01-01T00:00:00.0000000Z"
timeZone: "Etc/UTC"
I dont know what i'm doing wrong, i'd appreciate any help.
So for some reason using this URL:
GET /bookingBusinesses/{id}/calendarView?start={start-value}&end={end-value}
did end up giving me the exact results i was looking with correct time and everything the list appointments url was giving me.
I guess that's why this is still in BETA

How do I use Object.entries(...).forEach.every?

I'm filtering a list using a const queryModifier = {price: "lessThan", weight: "greaterThan"}
const queryKeys = keys: {
price: '1000',
weight: '1000'
}
const list = [
{
"clientOrderNumber": "N / A",
"companyName": "Test Company",
"createdAt": "2019-11-05 10:48:18",
"createdBy": "test#test.com",
"deliveryDate": "2019-11-08 10:46:37",
"driver": "",
"dropOff": "Kögel Trailer GmbH & Co. KG, Am Kögel-Werk, Burtenbach, Germany",
"height": 0,
"isPreparingTrailer": false,
"isSmsSent": false,
"isTrailerReady": false,
"key": "7e249529-d089-47bb-b0ad-470f850dd8cf",
"notes": "",
"orderId": "",
"pickUp": "Altenberge, Germany",
"price": 500,
"quantity": 1,
"trailer": "einzeln",
"vehicle": "Sattel",
"vehicleClass": "engl. Anschlüsse",
"vehicleId": "505123",
"vehicleReadyDate": "2019-11-05 10:47:57",
"weight": 0
},
{
"additionalPrices": 0,
"clientOrderNumber": "N / A",
"companyName": "Test Company",
"createdAt": "2019-10-14 16:32:12",
"createdBy": "test#test.com",
"deliveryDate": "2019-10-19 16:26:35",
"driver": "",
"dropOff": "Marville-Moutiers-Brûlé, France",
"height": 600,
"isPreparingTrailer": false,
"isSmsSent": false,
"isTrailerReady": false,
"key": "9b7f57fd-f95e-4038-b120-a0301fdf3f31",
"notes": "",
"orderId": "",
"pickUp": "Altenberge, Germany",
"price": 0,
"quantity": 1,
"trailer": "2er Pack",
"vehicle": "Anhänger",
"vehicleClass": "50",
"vehicleId": "123",
"vehicleReadyDate": "2019-10-16 16:31:26",
"weight": 12000
},
{
"clientOrderNumber": "N / A",
"companyName": "Test Company",
"createdAt": "2019-10-14 16:25:54",
"createdBy": "test#test.com",
"deliveryDate": "2019-10-19 16:24:13",
"driver": "",
"dropOff": "Vendenheim, France",
"height": 0,
"isPreparingTrailer": false,
"isSmsSent": false,
"isTrailerReady": false,
"key": "7e4f233f-695b-40eb-a0ca-fd78f3fa43cd",
"notes": "",
"orderId": "",
"pickUp": "Altenberge, Germany",
"price": 793,
"quantity": 1,
"trailer": "einzeln",
"vehicle": "Sattel",
"vehicleClass": "Standard",
"vehicleId": "3340731",
"vehicleReadyDate": "2019-10-15 16:24:58",
"weight": 0
},
{
"clientOrderNumber": "N / A",
"companyName": "Test Company",
"createdAt": "2019-09-26 18:32:18",
"createdBy": "test#test.com",
"deliveryDate": "2019-09-20 18:31:45",
"driver": "Michal Kucharski",
"dropOff": "Logroño, Spain",
"height": 0,
"isPreparingTrailer": false,
"isSmsSent": false,
"isTrailerReady": false,
"key": "388113f5-3927-4fe3-80d5-f2fcf1c7cedd",
"notes": "",
"orderId": "",
"pickUp": "16671 Butano Place, Fontana, CA, USA",
"price": 0,
"quantity": 1,
"trailer": "2er Pack",
"vehicle": "Sattel",
"vehicleClass": "Standard",
"vehicleId": "efgefg",
"vehicleReadyDate": "2019-09-27 18:32:08",
"weight": 0
},
{
"additionalPrices": 0,
"clientOrderNumber": "N / A",
"companyName": "Test Company",
"createdAt": "2019-09-06 22:57:55",
"createdBy": "test#test.com",
"deliveryDate": "2019-09-07 22:57:03",
"driver": "Eugeniusz Galinski",
"dropOff": "12345 Lamplight Village Avenue, Austin, TX, USA",
"height": 32,
"isPreparingTrailer": false,
"isSmsSent": false,
"isTrailerReady": false,
"key": "ac3cf14e-b43b-45e4-9168-ad4997b6415d",
"notes": "Nzube I am adding notes here",
"pickUp": "16671 Butano Place, Fontana, CA, USA",
"price": 100,
"quantity": 3,
"trailer": "einzeln",
"vehicle": "Sattel",
"vehicleClass": "Mega",
"vehicleId": "123",
"vehicleReadyDate": "2019-09-26 22:57:36",
"weight": 12
},
{
"additionalPrices": 0,
"clientOrderNumber": "N / A",
"companyName": "Test Company",
"createdAt": "2019-09-06 22:46:25",
"createdBy": "test#test.com",
"deliveryDate": "2019-09-06 22:45:45",
"driver": "Michal Kucharski",
"dropOff": "QEW, Niagara Falls, ON, Canada",
"height": 67,
"isPreparingTrailer": false,
"isSmsSent": false,
"isTrailerReady": false,
"key": "d0ec3b82-2279-4d11-8e35-a9307713ae5a",
"notes": "This is coming along",
"pickUp": "Avenida Callao 1234, Buenos Aires, Argentina",
"price": 100,
"quantity": 1,
"trailer": "2er Pack",
"vehicle": "Sattel",
"vehicleClass": "Mega",
"vehicleId": "123",
"vehicleReadyDate": "2019-09-25 22:45:57",
"weight": 12
},
{
"additionalPrices": 0,
"clientOrderNumber": "N / A",
"companyName": "Test Company",
"createdAt": "2019-09-04 18:06:18",
"createdBy": "test#test.com",
"deliveryDate": "2019-09-05 18:05:51",
"driver": "Chibuzo ilogu",
"dropOff": "Asda Park Royal Superstore, Western Road, London, UK",
"height": 453,
"isPreparingTrailer": true,
"isSmsSent": true,
"isTrailerReady": true,
"key": "96ee9410-4d70-4bbc-8016-5d7c9e5ecec1",
"notes": "ewriupoi ",
"pickUp": "Avenida Juan Bautista Alberdi 1233, Buenos Aires, Argentina",
"price": 234,
"quantity": 1,
"trailer": "3er Pack",
"vehicle": "Anhänger",
"vehicleClass": "50",
"vehicleId": "543",
"vehicleReadyDate": "2019-09-21 18:06:03",
"weight": 453
},
{
"additionalPrices": 0,
"companyName": "Test Company",
"completeDate": "2019-09-04 18:02:27",
"createdAt": "2019-09-04 18:01:30",
"createdBy": "test#test.com",
"deliveryDate": "2019-09-04 18:01:09",
"driver": "Chibuzo ilogu",
"dropOff": "La Cabaña 123, Las Condes, Chile",
"height": 123,
"isPreparingTrailer": false,
"isSmsSent": true,
"isTrailerReady": true,
"key": "bcd50f43-0644-49a7-8bdc-009a4572341b",
"notes": "qewqe",
"pickUp": "La Cabaña 123, Las Condes, Chile",
"price": 123,
"trailer": "einzeln",
"vehicle": "Sattel",
"vehicleClass": "Standard",
"vehicleId": "123",
"vehicleReadyDate": "2019-10-02 18:01:19",
"weight": 123
}
];
export const handleFilterModifier = (value, compareValue, modifier) => {
if (modifier === 'lessThan') {
return value > compareValue;
}
if (modifier === 'equals') {
return value === compareValue;
}
if (modifier === 'greaterThan') {
return value < compareValue;
}
return null;
};
const resultList = list.filter(
item => Object.entries(queryModifiers).every(([filterKey, filterVal]) => {
const compareValue = item[filterKey];
const value = Object.values(queryKeys);
const result = handleFilterModifier(
parseFloat(value),
compareValue,
filterVal
);
return result;
})
);
This operation fails when either of the queryModifiers has "equals" in its value pair. Anything else returns the actual true result. I don't understand why it fails on "equals".
I feel like there should be a forEach somewhere but I don't know where to put it and maybe there's something wrong with the code. I need help figuring it out.
I think you should replace this
const queryKeys = keys: {
price: '1000',
weight: '1000'
}
with
const queryKeys = {
price: '1000',
weight: '1000'
}
and replace this
const value = Object.values(queryKeys);
with
const value = queryKeys[filterKey];

JSON hierarchy, how to get an element?

$("#loginsubmit").live("click", function() {
var request = new Request();
request.service = "http://88.80.223.163:8080/lumiin-service/lumiin/control/eventmap/1" ;
RequestHandler(request,displayData);
});
function displayData(data) {
//alert(data.contents.ownerId);
var cont = data.contents;
$("#mono").html(''+cont.id);
}
I am using the above code snippet to get the id, which works fine...How do I get the firstName?
Object:
{
"id": 1,
"eventId": {
"URL": "web",
"location": "web",
"url": "web",
"id": 54,
"type": {
"name": "Meeting",
"id": 1,
"isDeleted": "N",
"description": "Meeting"
},
"abteilung": {
"id": 165,
"code": "web123",
"isDeleted": null,
"domainId": 0,
"parentId": 164,
"description": null
},
"eventName": "Tanvi",
"place": "web",
"startDate": 1335830400000,
"endDate": 1337558400000,
"prospectId": null,
"person": "web",
"isDeleted": "N",
"countryId": {
"name": "CH",
"id": 1,
"isDeleted": "N",
"description": "Switzerland"
},
"followUp": null,
"budget": 0,
"description": "web"
},
"ownerId": {
"id": 67,
"firstName": "web123",
"localOrg": null,
"industryTypeId": null,
"memeber": false,
"profileType": "Manager",
"emailId": "web123",
"abteilung": {
"id": 165,
"code": "web123",
"isDeleted": null,
"domainId": 0,
"parentId": 164,
"description": null
},
"userCode": "web123",
"authenticatedAccess": -1,
"uuid": null,
"lastName": "web123",
"isDeleted": "N",
"passWord": "web123",
"fullName": "web123,web123",
"status": 0
},
"prospectId": {
"id": 303,
"firstName": "web123",
"emailId": "web123#gg.com",
"ownerId": {
"id": 67,
"firstName": "web123",
"localOrg": null,
"industryTypeId": null,
"memeber": false,
"profileType": "Manager",
"emailId": "web123",
"abteilung": {
"id": 165,
"code": "web123",
"isDeleted": null,
"domainId": 0,
"parentId": 164,
"description": null
},
"userCode": "web123",
"authenticatedAccess": -1,
"uuid": null,
"lastName": "web123",
"isDeleted": "N",
"passWord": "web123",
"fullName": "web123,web123",
"status": 0
},
"abteilung": {
"id": 165,
"code": "web123",
"isDeleted": null,
"domainId": 0,
"parentId": 164,
"description": null
},
"startDate": 1335744000000,
"endDate": 1337904000000,
"statusId": {
"name": "New",
"id": 1,
"isDeleted": "N",
"description": "New"
},
"company": "company",
"lastName": "web123",
"isDeleted": "N",
"yearofBirth": null,
"annualRevenue": 0,
"nationalityId": {
"name": "CH",
"id": 1,
"isDeleted": "N",
"description": "Switzerland"
},
"titleId": {
"name": "Mr",
"id": 1,
"isDeleted": "N",
"description": "Mr"
},
"maritalstatusId": null,
"residencyId": null,
"languageId": null,
"priorityId": {
"name": "Low",
"id": 1,
"isDeleted": "N",
"description": "Low"
},
"genderId": {
"name": "Male",
"id": 1,
"isDeleted": "N",
"description": "Male"
}
},
"isDeleted": "N"
}
The firstName is a property of the prospectId object you can read it in this way:
var firstName = data.prospectId.firstName;
var lastName = data.prospectId.lastName;
Fiddle

Categories