How to get the last createdAt item with TypeORM - postman

Hi friends I need help with this query that I want to make to return only the last 'Case' by 'User'.
On my PostMan request I have my service that returns all the cases that the user have made.
users.services.ts
async findCasesbyUserId(id: number) {
return await this.usersRepository.findOne(id, { relations: ['cases']})
}
users.controller.ts
#Get('/findCase/:id')
async findCasesByUserId(#Param('id', ParseIntPipe) id: number,) {
return this.usersService.findCasesbyUserId(id)
}
When I made my GET request to 'http://localhost:3000/users/findCase/3'. This is the result that I get.
The user with id=3 have the cases with the id=1, id=2, id=3
So I want only to return only the case with the id=3 because is the last created case. I need a way to get the last case by the field createdAt or another way could be great for me.
Im using NestJs with TypeORM for thew querys to my PostgreSQL DB.
{
"id": 3,
"createdAt": "1617983079621",
"updatedAt": "1617983079621",
"name": "John",
"lastname": "Doe",
"email": "jdoe#email.com",
"username": "JohnDoe",
"password": "**************",
"role": "Admin",
"isActive": true,
"document": "12345",
"address": "Test",
"phone": "12345",
"cases": [
{
"id": 1,
"createdAt": "1618504530817",
"updatedAt": "1618504530817",
"message": "Test Case 1",
},
{
"id": 2,
"createdAt": "1618504530817",
"updatedAt": "1618504530817",
"message": "Test Case 1",
}, {
"id": 3,
"createdAt": "1618546146772",
"updatedAt": "1618546146772",
"message": "Test Case 1",
},
]
}

Related

Can I get all active ARB subscription in a single API call

Current I'm exporting all ARB data by calling API to get all active ARB ids then go through each ARB id to get info stored in each ID. But this process is too long and it makes lots of requests. Is there any way so that I can get all active ARB ids data in one request like that of any database?
https://developer.authorize.net/api/reference/index.html#recurring-billing-get-a-list-of-subscriptions
This function gives only small amount data while I need complete data stored in a profile like this one: https://developer.authorize.net/api/reference/index.html#recurring-billing-get-subscription
But this function only works for single ID.
New Answer
No. The ARBGetSubscriptionListRequest only returns a limited amount of information. If you want detailed information you would need to call ARBGetSubscriptionListRequest and then loop through the results and make an API call for each subscription to get the more granular data.
Due to the potentially large amount of results, you probably should store the results in a database and then have a bunch of scheduled scripts make the subsequent API calls.
Old Answer
Yes. You can call ARBGetSubscriptionListRequest.
Request:
{
"ARBGetSubscriptionListRequest": {
"merchantAuthentication": {
"name": "5KP3u95bQpv",
"transactionKey": "346HZ32z3fP4hTG2"
},
"refId": "123456",
"searchType": "subscriptionActive",
"sorting": {
"orderBy": "id",
"orderDescending": "false"
},
"paging": {
"limit": "1000",
"offset": "1"
}
}
}
Response:
{
"totalNumInResultSet": 1273,
"totalNumInResultSetSpecified": true,
"subscriptionDetails": [
{
"id": 100188,
"name": "subscription",
"status": "canceled",
"createTimeStampUTC": "2004-04-28T23:59:47.33",
"firstName": "Joe",
"lastName": "Tester",
"totalOccurrences": 12,
"pastOccurrences": 6,
"paymentMethod": "creditCard",
"accountNumber": "XXXX5454",
"invoice": "42820041325496571",
"amount": 10,
"currencyCode": "USD"
},
{
"id": 100222,
"name": "",
"status": "canceled",
"createTimeStampUTC": "2004-10-22T21:00:15.503",
"firstName": "asdf",
"lastName": "asdf",
"totalOccurrences": 12,
"pastOccurrences": 0,
"paymentMethod": "creditCard",
"accountNumber": "XXXX1111",
"invoice": "",
"amount": 1,
"currencyCode": "USD"
},
{
"id": 100223,
"name": "",
"status": "canceled",
"createTimeStampUTC": "2004-10-22T21:01:27.69",
"firstName": "asdf",
"lastName": "asdf",
"totalOccurrences": 12,
"pastOccurrences": 1,
"paymentMethod": "eCheck",
"accountNumber": "XXXX3888",
"invoice": "",
"amount": 10,
"currencyCode": "USD"
}
],
"refId": "123456",
"messages": {
"resultCode": "Ok",
"message": [
{
"code": "I00001",
"text": "Successful."
}
]
}
}

Querying data on S3 Object

Trying to query data on json file using S3-Select
{
"groups_id":
{
"307225":
{
"created_at": "2015-02-10T17:24:15-08:00",
"updated_at": "2017-09-06T17:25:22-07:00",
"name": "Company 1",
"company": true,
"contact_name": "User 1",
"email": "",
"phone_number": "",
"address": "",
"website": "",
"notes": "Testing",
"id": "307225"
},
"1058565":
{
"created_at": "2017-04-02T23:44:10-07:00",
"updated_at": "2017-07-18T17:39:21-07:00",
"name": "Company 3",
"company": true,
"contact_name": "User 1",
"email": "",
"phone_number": "",
"address": "",
"website": "",
"notes": null,
"id": "1058565"
}
}
}
Can someone help to get the desired output using s3 select, based on the condition as WHERE contact_name='User 1'.
{"id": "307225", "name": "Company 1"},
{"id": "1058565","name": "Company 3"}
below are the queries we had tried,
Select s.groups_id['307225'].id from s3object s
Select s.groups_id['1058565'].id from s3object s
in the above queries, we had hardcoded the group_id and we are able to fetch below
{
"id": "1058565"
}
but in our case groupid is dynamic so i am not understanding. how to handle that?

How to fetch API data as this. props?

I am trying to fetch data from API in react component as
{this.props.buyer && this.props.buyer[0].phone_number[0].number} - it's throwing error
Cannot read property 'number' of undefined
{this.props.buyer && this.props.buyer[0].name} - it's working fine
This is the API data
Orders: {
buyer:
},
}
[
{
"id": 2,
"name": "Qi Xiang",
"type": "Consignee",
"address": {
"id": 2,
"type": "shipping",
"street": "China China",
"city": "Beijing",
"postal_code": "34343",
"province": "23232",
"country": "CN"
},
"email": null,
"phone_number": {
"number": "323232",
"type": "Phone"
},
"id_image_url": "/api/files/24e49645-df42-4984-a
}
]
},
}
Your phonenumber is not array. You must use this:
this.props.buyer[0].phone_number.number

multiple relations using same model type in ember data

I have an account model that has the following:
export default Model.extend({
primaryStaff: belongsTo('staff'),
secondaryStaff: belongsTo('staff')
});
primaryStaff maps to the primaryStaffId key on the account model and secondaryStaff maps to secondaryStaffId. Is there a way to allow these to both point to the staff model?
Not having any luck. Thanks!
Update:
I'm using the JSON API Adapter -- here's a sample payload:
{
"data": {
"type": "account",
"id": "17",
"attributes": {
"businessId": 1,
"userId": 22,
"scopes": [
"customer",
"customer-22"
],
"keyCode": null,
"lockboxCode": null,
"notes": null,
"active": false,
"createdAt": "2017-01-31T20:13:39.465Z",
"updatedAt": "2017-02-20T03:49:17.308Z",
},
"relationships": {
"business": {
"data": {
"type": "business",
"id": "1"
}
},
"customer": {
"data": {
"type": "customer",
"id": "22"
}
},
"secondaryStaff": {
"data": null
},
"primaryStaff": {
"data": {
"type": "staff",
"id": "1"
}
}
}
}
}
You need to modify application (or model) serializer.
Please take a look at this twiddle

Is the referral (fb_action_ids) value, stored within the activity made by a user on a timeline app?

I'm testing a timeline app I just made.
I'm using Graph API Explorer for testing.
I tested the next URL:
https://graph.facebook.com/10150691128476714
where 10150691128476714 is the id of the activity I made through my app.
It returns the next values:
{
"id": "10150691128476714",
"from": {
"name": "Moisés Briseño Estrello",
"id": "719621713"
},
"start_time": "2012-04-26T07:22:00+0000",
"end_time": "2012-04-26T07:22:00+0000",
"publish_time": "2012-04-26T07:22:00+0000",
"application": {
"name": "appname",
"namespace": "appname",
"id": "367747679937600"
},
"data": {
"objectname": {
"id": "10150825002710211",
"url": "https://young-planet-1642.herokuapp.com/AMLO.html",
"type": "appname:objectname",
"title": "TItle"
}
},
"type": "appname:actionname",
"likes": {
"count": 0,
"can_like": true,
"user_likes": false
},
"comments": {
"count": 0,
"can_comment": true
}
}
I wonder if the referral (fb_action_ids) value is also stored in here or where I can find it?
Thanks in advance :)
ID of the action is the fb_action_ids value, i.e. fb_action_ids = 10150691128476714.