I've searched the internet and StackOverflow, but I cannot find the answer or even the question.
I have two collections, artisan and users. I want my query to return all reports and indicate if the specified user has that report as a favorite in their array.
I'm finding hard to remove the other result for the next data that is set in the first result.
i would love to receive some help on how to get the correct value from the aggregate statement.
if you look so closely, you will see that "_id": "5f21f998fe054d2cf0b7f787" is showing 3 times, but the correct one is the one with "user_id": "5f21f998fe054d2cf0b7f787" of artisan. That is the same for others also
Here below is the code and the result i was getting
Thanks
User.aggregate([
{
$lookup: {
from: Artisan.collection.name,
localField: "user._id",
foreignField: "artisan.user_id",
as: "artisan"
}
},
{$unwind: '$artisan'}
])
.then((result) => {
res.json(result);
}, (err) => next(err))
.catch((err) => next(err));```
\\Here is the result
[
{
"_id": "5f21f998fe054d2cf0b7f787",
"email_verified": null,
"sex": "male",
"phone_no": 2348117741341,
"address": "10 Oweh Street",
"area": "",
"city": "Lagos",
"state": "Lagos",
"country": "",
"job_type": "great work",
"status": "",
"login_key": "",
"login_valid_till": null,
"firstname": "Johnson",
"othername": "Ayobami",
"lastname": "Eniola",
"email": "ekundayoolumide#gmail.com",
"password": "$2b$10$BlfwHzVgZ4kWYfG6Ia4x.Oj6cdVG24Cwl3R9FZQ9lK/1LoUg.WbAi",
"user_type": "artisan",
"createdAt": "2020-07-29T22:35:04.601Z",
"updatedAt": "2020-07-29T22:35:04.601Z",
"__v": 0,
"artisan": {
"_id": "5f21f998fe054d2cf0b7f788",
"date_of_birth": null,
"duration": "",
"payment_status": "",
"payment_type": "",
"user_id": "5f21f998fe054d2cf0b7f787",
"createdAt": "2020-07-29T22:35:04.645Z",
"updatedAt": "2020-07-29T22:35:04.645Z",
"__v": 0
}
},
{
"_id": "5f21f998fe054d2cf0b7f787",
"email_verified": null,
"sex": "male",
"phone_no": 2348117741341,
"address": "10 Oweh Street",
"area": "",
"city": "Lagos",
"state": "Lagos",
"country": "",
"job_type": "great work",
"status": "",
"login_key": "",
"login_valid_till": null,
"firstname": "Johnson",
"othername": "Ayobami",
"lastname": "Eniola",
"email": "ekundayoolumide#gmail.com",
"password": "$2b$10$BlfwHzVgZ4kWYfG6Ia4x.Oj6cdVG24Cwl3R9FZQ9lK/1LoUg.WbAi",
"user_type": "artisan",
"createdAt": "2020-07-29T22:35:04.601Z",
"updatedAt": "2020-07-29T22:35:04.601Z",
"__v": 0,
"artisan": {
"_id": "5f21fa632fc70100d0339194",
"date_of_birth": null,
"duration": "4 years",
"payment_status": "",
"payment_type": "",
"user_id": "5f21fa632fc70100d0339193",
"createdAt": "2020-07-29T22:38:27.998Z",
"updatedAt": "2020-07-29T22:42:22.601Z",
"__v": 0
}
},
{
"_id": "5f21f998fe054d2cf0b7f787",
"email_verified": null,
"sex": "male",
"phone_no": 2348117741341,
"address": "10 Oweh Street",
"area": "",
"city": "Lagos",
"state": "Lagos",
"country": "",
"job_type": "great work",
"status": "",
"login_key": "",
"login_valid_till": null,
"firstname": "Johnson",
"othername": "Ayobami",
"lastname": "Eniola",
"email": "ekundayoolumide#gmail.com",
"password": "$2b$10$BlfwHzVgZ4kWYfG6Ia4x.Oj6cdVG24Cwl3R9FZQ9lK/1LoUg.WbAi",
"user_type": "artisan",
"createdAt": "2020-07-29T22:35:04.601Z",
"updatedAt": "2020-07-29T22:35:04.601Z",
"__v": 0,
"artisan": {
"_id": "5f227b0433105d3a3864547e",
"date_of_birth": null,
"duration": "",
"payment_status": "",
"payment_type": "",
"user_id": "5f227b0433105d3a3864547d",
"createdAt": "2020-07-30T07:47:16.269Z",
"updatedAt": "2020-07-30T07:47:16.269Z",
"__v": 0
}
},
{
"_id": "5f21fa632fc70100d0339193",
"email_verified": null,
"sex": "male",
"phone_no": 2348117741341,
"address": "10 Oweh Street",
"area": "",
"city": "Lagos",
"state": "Lagos",
"country": "",
"job_type": "great work",
"status": "",
"login_key": "",
"login_valid_till": null,
"firstname": "Johnson",
"othername": "Akinmade",
"lastname": "Eniola",
"email": "ekundayoolumide1#gmail.com",
"password": "john1234",
"user_type": "artisan",
"createdAt": "2020-07-29T22:38:27.957Z",
"updatedAt": "2020-07-29T22:42:22.454Z",
"__v": 0,
"artisan": {
"_id": "5f21f998fe054d2cf0b7f788",
"date_of_birth": null,
"duration": "",
"payment_status": "",
"payment_type": "",
"user_id": "5f21f998fe054d2cf0b7f787",
"createdAt": "2020-07-29T22:35:04.645Z",
"updatedAt": "2020-07-29T22:35:04.645Z",
"__v": 0
}
},
{
"_id": "5f21fa632fc70100d0339193",
"email_verified": null,
"sex": "male",
"phone_no": 2348117741341,
"address": "10 Oweh Street",
"area": "",
"city": "Lagos",
"state": "Lagos",
"country": "",
"job_type": "great work",
"status": "",
"login_key": "",
"login_valid_till": null,
"firstname": "Johnson",
"othername": "Akinmade",
"lastname": "Eniola",
"email": "ekundayoolumide1#gmail.com",
"password": "john1234",
"user_type": "artisan",
"createdAt": "2020-07-29T22:38:27.957Z",
"updatedAt": "2020-07-29T22:42:22.454Z",
"__v": 0,
"artisan": {
"_id": "5f21fa632fc70100d0339194",
"date_of_birth": null,
"duration": "4 years",
"payment_status": "",
"payment_type": "",
"user_id": "5f21fa632fc70100d0339193",
"createdAt": "2020-07-29T22:38:27.998Z",
"updatedAt": "2020-07-29T22:42:22.601Z",
"__v": 0
}
},
{
"_id": "5f21fa632fc70100d0339193",
"email_verified": null,
"sex": "male",
"phone_no": 2348117741341,
"address": "10 Oweh Street",
"area": "",
"city": "Lagos",
"state": "Lagos",
"country": "",
"job_type": "great work",
"status": "",
"login_key": "",
"login_valid_till": null,
"firstname": "Johnson",
"othername": "Akinmade",
"lastname": "Eniola",
"email": "ekundayoolumide1#gmail.com",
"password": "john1234",
"user_type": "artisan",
"createdAt": "2020-07-29T22:38:27.957Z",
"updatedAt": "2020-07-29T22:42:22.454Z",
"__v": 0,
"artisan": {
"_id": "5f227b0433105d3a3864547e",
"date_of_birth": null,
"duration": "",
"payment_status": "",
"payment_type": "",
"user_id": "5f227b0433105d3a3864547d",
"createdAt": "2020-07-30T07:47:16.269Z",
"updatedAt": "2020-07-30T07:47:16.269Z",
"__v": 0
}
},
{
"_id": "5f227b0433105d3a3864547d",
"email_verified": null,
"sex": "male",
"phone_no": 2348117741341,
"address": "10 Oweh Street",
"area": "",
"city": "Lagos",
"state": "Lagos",
"country": "",
"job_type": "great work",
"status": "",
"login_key": "",
"login_valid_till": null,
"firstname": "Johnson",
"othername": "Akinmade",
"lastname": "Eniola",
"email": "ekundayoolumide2#gmail.com",
"password": "$2b$10$jg/nKNpg/RkDA.KFG/flFuy8fwfamLdgCD7MNk16rprDiwoWTKcse",
"user_type": "artisan",
"createdAt": "2020-07-30T07:47:16.234Z",
"updatedAt": "2020-07-30T07:47:16.234Z",
"__v": 0,
"artisan": {
"_id": "5f21f998fe054d2cf0b7f788",
"date_of_birth": null,
"duration": "",
"payment_status": "",
"payment_type": "",
"user_id": "5f21f998fe054d2cf0b7f787",
"createdAt": "2020-07-29T22:35:04.645Z",
"updatedAt": "2020-07-29T22:35:04.645Z",
"__v": 0
}
},
{
"_id": "5f227b0433105d3a3864547d",
"email_verified": null,
"sex": "male",
"phone_no": 2348117741341,
"address": "10 Oweh Street",
"area": "",
"city": "Lagos",
"state": "Lagos",
"country": "",
"job_type": "great work",
"status": "",
"login_key": "",
"login_valid_till": null,
"firstname": "Johnson",
"othername": "Akinmade",
"lastname": "Eniola",
"email": "ekundayoolumide2#gmail.com",
"password": "$2b$10$jg/nKNpg/RkDA.KFG/flFuy8fwfamLdgCD7MNk16rprDiwoWTKcse",
"user_type": "artisan",
"createdAt": "2020-07-30T07:47:16.234Z",
"updatedAt": "2020-07-30T07:47:16.234Z",
"__v": 0,
"artisan": {
"_id": "5f21fa632fc70100d0339194",
"date_of_birth": null,
"duration": "4 years",
"payment_status": "",
"payment_type": "",
"user_id": "5f21fa632fc70100d0339193",
"createdAt": "2020-07-29T22:38:27.998Z",
"updatedAt": "2020-07-29T22:42:22.601Z",
"__v": 0
}
},
{
"_id": "5f227b0433105d3a3864547d",
"email_verified": null,
"sex": "male",
"phone_no": 2348117741341,
"address": "10 Oweh Street",
"area": "",
"city": "Lagos",
"state": "Lagos",
"country": "",
"job_type": "great work",
"status": "",
"login_key": "",
"login_valid_till": null,
"firstname": "Johnson",
"othername": "Akinmade",
"lastname": "Eniola",
"email": "ekundayoolumide2#gmail.com",
"password": "$2b$10$jg/nKNpg/RkDA.KFG/flFuy8fwfamLdgCD7MNk16rprDiwoWTKcse",
"user_type": "artisan",
"createdAt": "2020-07-30T07:47:16.234Z",
"updatedAt": "2020-07-30T07:47:16.234Z",
"__v": 0,
"artisan": {
"_id": "5f227b0433105d3a3864547e",
"date_of_birth": null,
"duration": "",
"payment_status": "",
"payment_type": "",
"user_id": "5f227b0433105d3a3864547d",
"createdAt": "2020-07-30T07:47:16.269Z",
"updatedAt": "2020-07-30T07:47:16.269Z",
"__v": 0
}
}
]
Right now you have:
$lookup: {
from: Artisan.collection.name,
localField: "user._id",
foreignField: "artisan.user_id",
as: "artisan"
}
After looking at your results, the documents from the User collection don't have a field named user._id, they just have an _id field. Similarly with your Artisan collection there isn't a field named artist.user_id, there's just a user_id field. Change the localField and foreignField values to only have the name of the fields as they appear in the respective documents.
It should look something like this:
$lookup: {
from: Artisan.collection.name,
localField: "_id",
foreignField: "user_id",
as: "artisan"
}
The response i am getting is below Which i need to convert the input JSON Format to other JSON structure and send the response back. I am struck how to get the data from the JSOn and construct the new JSON format
{
"totalSize": 1,
"done": true,
"records": [{
"attributes": {
"type": "test123",
"url": "/services/data/testapp"
},
"Id": "8373837",
"Name": "6294",
"Application": "9932932932",
"contact": {
"attributes": {
"type": "testcon",
"url": "/services/data/testappsss"
},
"Name": "testName",
"FirstName": "test",
"LastName": "name",
"MailingStreet": null,
"MailingCity": null,
"unemail": "testname#test,.co",
"MailingState": null,
"MailingCountry": null,
"MailingPostalCode": null,
"stuId": "328237832"
},
"currentusbss": "83277832873278",
"currentsu": {
"attributes": {
"type": "testsub",
"url": "/services/data/v44.0jsjsj"
},
"price": 2,
"Name": "SUB-20426"
},
"bal": 234,
"startdate": "2020-02-03",
"enddate": "2020-05-03"
}]
}
I need to convert above JSON format to below JSON format and send it using set-body method in out-bond policies
{
"info": {
"studentName": "testName",
"studentFirstName": "test",
"studentMiddleName": "",
"studentLastName": "Name",
"studentEmail": "testname#test,.co",
"role": "STUDENT",
"billingCountryCode": "US",
"systemId": "XX",
"stuId": "328237832"
},
"address": {
"address1": "1234 Grove St",
"address2": "",
"city": "Tempe",
"countryCode": "US",
"countryDescription": "UNITED STATES",
"stateCode": "AZ",
"stateDescription": "Arizona",
"postalCode": "45235",
"foreignState": "Arizona",
"region": "Domestic",
"phoneNumber": ""
},
"account": {
"institutionId": "1",
"paymentPlan": "N",
"currencyDesc": "United States Dollars",
"currencyType": "USD",
"bal": 234,
"daysLate":"18",
"opportunityId": "9932932932",
"studentParameterName": null,
"studentParameterValue": null
},
"studentTerms": [
{
"startdate": "2020-02-03",
"enddate": "2020-05-03",
"Name": "SUB-20426",
"description": "XQYember 03, 2020 "
}
]
}
You can use Liquid Template for this case:
Using Liquid Templates in Azure API Management
Using Liquid templates with set body
Or you create a new body in the outbound-section with a new JObject
I have implemented the preference API and I am getting the response which I have attached. Now I am confused about how to get refund with this response or is it possible or not. Can you please suggest some API related to the refund policy?
Thanks for the cooperation in advance.
The response which I am getting:
{
"processing_modes": [],
"metadata": {},
"binary_mode": false,
"payment_methods": {
"excluded_payment_methods": [
{
"id": ""
}
],
"excluded_payment_types": [
{
"id": ""
}
],
"installments": null,
"default_payment_method_id": null,
"default_installments": null
},
"collector_id": 472389951,
"operation_type": "regular_payment",
"items": [
{
"id": "",
"picture_url": "",
"title": "Mojito",
"description": "Cheesy 8",
"category_id": "Blah Blah",
"currency_id": "ARS",
"quantity": 11,
"unit_price": 456
}
],
"payer": {
"name": "",
"surname": "",
"email": "pappu#testuser.com",
"date_created": "",
"phone": {
"area_code": "",
"number": ""
},
"identification": {
"type": "",
"number": ""
},
"address": {
"street_name": "",
"street_number": null,
"zip_code": ""
}
},
"back_urls": {
"success": "http://eb7b02b9.ngrok.io/notification/ipn",
"pending": "http://eb7b02b9.ngrok.io/notification/ipn",
"failure": "http://eb7b02b9.ngrok.io/notification/ipn"
},
"auto_return": "",
"client_id": "3767495422255439",
"marketplace": "NONE",
"marketplace_fee": 0,
"shipments": {
"receiver_address": {
"zip_code": "",
"street_number": null,
"street_name": "",
"floor": "",
"apartment": ""
}
},
"notification_url": "http://fd7842f1.ngrok.io/notification/ipn",
"external_reference": "",
"additional_info": "",
"expires": false,
"expiration_date_from": null,
"expiration_date_to": null,
"date_created": "2019-10-03T03:35:03.228-04:00",
"id": "472389951-fdfcf414-18b7-44b3-afd5-5d3cd73fbfc2",
"init_point": "https://www.mercadopago.com.ar/checkout/v1/redirect?pref_id=472389951-fdfcf414-18b7-44b3-afd5-5d3cd73fbfc2",
"sandbox_init_point": "https://sandbox.mercadopago.com.ar/checkout/v1/redirect?pref_id=472389951-fdfcf414-18b7-44b3-afd5-5d3cd73fbfc2"
}
Okay I am setting up Partial Payments via the Authorize.net API in order to enable multiple cards to be used to cover a single balance/charge.
I'm assuming thier Partial Auth feature covers my use case, but in testing, there is an issue I can show you using the API live console here: https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-credit-card
Go to the link above and authorize partial payments with the request I edited below and you will notice when you press submit you get a splitTenderId:
{
"createTransactionRequest": {
"merchantAuthentication": {
"name": "5KP3u95bQpv",
"transactionKey": "346HZ32z3fP4hTG2"
},
"refId": "123456",
"transactionRequest": {
"transactionType": "authCaptureTransaction",
"amount": "462.25",
"payment": {
"creditCard": {
"cardNumber": "5424000000000015",
"expirationDate": "2020-12",
"cardCode": "999"
}
},
"lineItems": {
"lineItem": {
"itemId": "1",
"name": "vase",
"description": "Cannes logo",
"quantity": "18",
"unitPrice": "45.00"
}
},
"tax": {
"amount": "4.26",
"name": "level2 tax name",
"description": "level2 tax"
},
"duty": {
"amount": "8.55",
"name": "duty name",
"description": "duty description"
},
"shipping": {
"amount": "4.26",
"name": "level2 tax name",
"description": "level2 tax"
},
"poNumber": "456654",
"customer": {
"id": "99999456654"
},
"billTo": {
"firstName": "Ellen",
"lastName": "Johnson",
"company": "Souveniropolis",
"address": "14 Main Street",
"city": "Pecan Springs",
"state": "TX",
"zip": "44628",
"country": "USA"
},
"shipTo": {
"firstName": "China",
"lastName": "Bayles",
"company": "Thyme for Tea",
"address": "12 Main Street",
"city": "Pecan Springs",
"state": "TX",
"zip": "44628",
"country": "USA"
},
"customerIP": "192.168.1.1",
"transactionSettings": {
"setting": [
{
"settingName": "emailCustomer",
"settingValue": "true"
}, {
"settingName": "allowPartialAuth",
"settingValue": "true"
},
]
},
"userFields": {
"userField": [
{
"name": "MerchantDefinedFieldName1",
"value": "MerchantDefinedFieldValue1"
},
{
"name": "favorite_color",
"value": "blue"
}
]
}
}
}
}
This is only successful because the amount is 462.25 as the docs say to use for testing, if I use any other (real) amount the splitTenderId is not there.
Here is a new example request, you can post this again on the link above:
{
"createTransactionRequest": {
"merchantAuthentication": {
"name": "5KP3u95bQpv",
"transactionKey": "346HZ32z3fP4hTG2"
},
"refId": "123456",
"transactionRequest": {
"transactionType": "authCaptureTransaction",
"amount": "462",
"payment": {
"creditCard": {
"cardNumber": "5424000000000015",
"expirationDate": "2020-12",
"cardCode": "999"
}
},
"lineItems": {
"lineItem": {
"itemId": "1",
"name": "vase",
"description": "Cannes logo",
"quantity": "18",
"unitPrice": "45.00"
}
},
"tax": {
"amount": "4.26",
"name": "level2 tax name",
"description": "level2 tax"
},
"duty": {
"amount": "8.55",
"name": "duty name",
"description": "duty description"
},
"shipping": {
"amount": "4.26",
"name": "level2 tax name",
"description": "level2 tax"
},
"poNumber": "456654",
"customer": {
"id": "99999456654"
},
"billTo": {
"firstName": "Ellen",
"lastName": "Johnson",
"company": "Souveniropolis",
"address": "14 Main Street",
"city": "Pecan Springs",
"state": "TX",
"zip": "44628",
"country": "USA"
},
"shipTo": {
"firstName": "China",
"lastName": "Bayles",
"company": "Thyme for Tea",
"address": "12 Main Street",
"city": "Pecan Springs",
"state": "TX",
"zip": "44628",
"country": "USA"
},
"customerIP": "192.168.1.1",
"transactionSettings": {
"setting": [
{
"settingName": "emailCustomer",
"settingValue": "true"
}, {
"settingName": "allowPartialAuth",
"settingValue": "true"
},
]
},
"userFields": {
"userField": [
{
"name": "MerchantDefinedFieldName1",
"value": "MerchantDefinedFieldValue1"
},
{
"name": "favorite_color",
"value": "blue"
}
]
}
}
}
}
And with the 462 amount entered this is no longer a partial auth payment and I no longer get a splitTenderId.
Can someone please help me figure out what is going on?