how to get the users/me relation in strapi v4 - javascript

i'va added a relation my user but when i try to query it i can see it even with the populate deep plug in
when i add a normal field, there is no problem but the relation is impossible to see.
here is the user table in the dashboard :
here is the query i'm doing:
http://localhost:1337/api/users/me?populate=deep
end the response i get :
{
"id": 1,
"username": "testAdmin",
"email": "testadmin#gmail.com",
"provider": "local",
"confirmed": true,
"blocked": false,
"createdAt": "2023-01-27T20:38:35.624Z",
"updatedAt": "2023-01-28T17:07:51.151Z",
"test": "test"
}
i've seen the same issue in a github repo but it's fair old and i've not seen any update
any idea ?

Related

Pull a full object from one value

I'm working on a ticket system, and I want to make a close ticket system, that will remove the ticket from the user, so I have my mongo array looking like this
{
"tickets": [{
"id": "cxZgqey2",
"subject": "fdgfdgdfgfdgfd",
"message": "gfdgfdgfdgdfg",
"ownerEmail": "soenmtherhg#gmail.com"
},
{
"id": "r4r-CnIC",
"subject": "dfdsfdsfsdfdsfdsf",
"message": "dsfdsfdfsdfdsfdsfdsfdsf",
"ownerEmail": "soenmtherhg#gmail.com"
}
]}
and I wanted to remove the entire object using only the id, how would I do this? (Using the npm module (not mongoose))
You can use the filter function in arrays and delete it passing the relevant id for that and also you can check loadash.

Limit length array-type of property in Loopback 4 query?

I've been trying this new framework Loopback 4 and its awesome but I dont know to which point is flexible,I'm having the following model on the database:
{
"id": "string",
"lastUpdate": "2020-10-01T18:10:46.306Z",
"name": "string",
"logo": "string",
"data": [
{}
]
}
And what I'm trying there is to make a query that returns me the data, but as is an array, it has a lot of data and I would like to paginate it, so I thought on limiting the query. I've achieved a query to look like the following:
{
"offset": 0,
"limit": 10,
"skip": 0,
"where": {
"name": {"eq":"BengalaSpain"}
},
"fields": {
"data": true
}
}
I'm trying to limit the data property to 10, but of course, this dosnt affects the property itself, just the wrapper object around it. Is there any way to achieve what im trying?
Thanks in advance guys!
LoopBack 4 filters apply at a Repository level as these constraints are passed to the ORM datasource connectors to be converted into their respective native queries (e.g. TOP 10 for SQL Server).
A possible solution is to link the data field into a Relation. Relations essentially create nested Repositories (e.g. hasManyRepository), hence are able to meet the requirement of isolating data into its own Repository.
To quickly create a relation, remove the property from the Model and re-create it using lb4 relation command.
From there, it would be possible to take advantage of the now-enabled InclusionResolver and write use query:
{
"where": {
"name": {"eq":"BengalaSpain"}
},
"fields": {
"data": true
},
"include": [
{
"relation": "<relation name here>",
"scope": {
"limit": 10
}
}
]
}
A side-effect is the separation of data into its own table. However, this should be done irregardless due to database normalization.

How to handle dispute event in webhook?

I'm a amateur php developer. I accepts stripe payments in my php website as one-time payments. I've integrated it correctly according to stripe website docs. (https://stripe.com/docs/payments/checkout/one-time#create-checkout-session). I'm getting checkout.session.created event from stripe webhook and I store it in my database as a completed payment. ( Advise me if I'm doing wrong ). This is the sample event data that stripe triggers as checkout.session.completed event.
{
"id": "evt_123",
"object": "event",
"api_version": "2019-03-14",
"created": 1561420781,
"data": {
"object": {
"id": "cs_test_123",
"object": "checkout.session",
"billing_address_collection": null,
"cancel_url": "https://example.com/cancel",
"client_reference_id": null,
"customer": "cus_123",
"customer_email": null,
"display_items": [],
"mode": "setup",
"setup_intent": "seti_1123",
"submit_type": null,
"subscription": null,
"success_url": "https://example.com/success"
}
},
"livemode": false,
"pending_webhooks": 1,
"request": {
"id": null,
"idempotency_key": null
},
"type": "checkout.session.completed"
}
But I need to handle webhook events for disputes. If a paid user opens dispute, I need to know it. How stripe notifies me it via webhook ? If stripe notifies me, How do I find parent payment ?. Sorry for my bad English.
webbhook is a url provided by you to stripe, on which stripe will be sending data, just like how you send data from a form to your site.
You should follow stripe docs for it, https://stripe.com/docs/payments/handling-payment-events and https://stripe.com/docs/webhooks
You should ideally edit your original post to include the 'answer' you added yesterday - and remove that answer - as Stackoverflow isn't the same as a forum
The Dispute object contains a Payment Intent ID and you can list / 'retrieve' the Checkout Session for that Payment Intent ID, so that's how you get it.

Extend built-in User model to support more properties and behaviors in loopback

I want a model to represent a profile in my loopback app. But, the built-in User model found in loopback only have the following properties
username
password
realm
emailVerified
What is the best way to extend the built-in User model in order to insert more properties like phone number, profile picture, and the likes?
It was better if you have added your code for better answer according to your question but you can check this site which talks about customizing the built-in user model and also this. I hope this answers your question.
Create a new model common/models/user.json
{
"name": "user",
"base": "User",
"idInjection": true,
"properties": {
"firstName"{
"type":"string",
"required":true
}
}
"restrictResetPasswordTokenScope": true,
"emailVerificationRequired": true,
"validations": [],
"relations": {},
"acls": [
{
"principalType": "ROLE",
"principalId": "$everyone",
"accessType": "READ",
"permission": "ALLOW"
}
],
"methods": []
}
Add this to model-config.json
"user":
"dataSource": "yourDataSource"
}
Hope this works for you

Facebook Graph API - get page feed + full event info?

Is it possible to, in 1 request, get the feed of a page but with the full event info?
As it is now, if a shared event is posted, you only get back the link to that event, no picture or title:
{
"id": "xxx",
"from": {
"category": "Community",
"name": "xxx",
"id": "xxx"
},
"story": "xxx shared xxx's event.",
"link": "https://www.facebook.com/events/xxx/",
"actions": [
{
"name": "Comment",
"link": "https://www.facebook.com/xxx/posts/xxx"
},
{
"name": "Like",
"link": "https://www.facebook.com/xxx/posts/xxx"
}
],
"privacy": {
"value": ""
},
"type": "link",
"status_type": "shared_story",
"application": {
"name": "Links",
"id": "xxx"
},
"created_time": "2013-06-19T10:05:50+0000",
"updated_time": "2013-06-19T10:05:50+0000",
"likes": {
"data": [
{
"name": "xxx",
"id": "xxx"
}
],
"count": 1
}
}
If I understand correctly, you need to retrieve the events but you want to do it all at once with the feed because you want to retrieve the information on the feed anyway.
Before doing that, you must know that the feed doesn't contain all the events.... Once created, a link to the event is automatically shared on the page feed. It is only a reference, which can then be hidden. The event won't be displayed on the feed anymore even if it still exists.
Requesting two different objects at the same time
So, the feed doesn't have the events information and the events and posts (feed) are stored on 2 different tables. Therefore, you need to get the events independently from the feed:
The feed /PAGE_ID/feed
The events /PAGE_ID/events
And, as you wanted, Graph API allows you to do this in only one request:
/PAGE_ID?fields=feed,events
Additional fields
Note that either feed or events accept the limit and fields parameters. For example, events can be specified by:
events.limit(100).fields(location,name,owner,description,updated_time,venue)
Possible fields are given in the doc.
There is no way to get the "full info" at once. You will have to specify each field in the request. So, don't get the "full info", but just the information you really need.
There is a post from Facebook addressing this scenario using multi-queries and FQL (Facebook Query Language). This will allow you to make multiple FQL calls in one request.
https://developers.facebook.com/docs/technical-guides/fql/#multi

Categories

Resources