Foursquare API Lists -> ListItems -> ?Venues? - api

Via the foursquare API and documentation, i'm trying to extract venues from lists.
I'm hitting getting a list response, which has listItems, which is suppose to be "count and items of list items on this list."
What the API responds with is just the count.
{
id: "510ae78ae4b0607cd8d8504f"
name: "Brunchn'"
description: ""
user: {
id: "157255"
firstName: "Jon"
lastName: "Doe"
gender: "male"
relationship: "self"
photo: {
prefix: "https://irs3.4sqi.net/img/user/"
suffix: "/POOIJDBXTTRPSB0.jpg"
}
}
editable: true
public: true
collaborative: false
url: "https://foursquare.com/jon_doe/list/brunch"
canonicalUrl: "https://foursquare.com/jon_doe/list/brunch"
createdAt: 1359669130
updatedAt: 1364583099
followers: {
count: 0
}
listItems: {
count: 3
}
}
from the documentation, if i get the item response, I can retrieve the venue, but there doesn't seem to be a connection, or i'm going at this from the wrong API call. Anyone have any suggestions?
The call is https://api.foursquare.com/v2/users/self/lists

Related

How to create or update many-to-many relation in Prisma?

I have the following models, and many-to-many relation between them:
model User {
id String #id #default(cuid())
name String?
email String? #unique
followings Artist[]
}
model Artist {
id String #id #default(cuid())
name String #unique
spotifyId String #unique
followers User[]
}
When a user logs into my app, I retrieve their current followed artists, and need to update my database.
I have managed to select artists data from database (for updating user <-> artist relation), sample data:
const followings = [
{
id: '...',
name: 'MARINA',
spotifyId: '6CwfuxIqcltXDGjfZsMd9A'
},
{
id: '...',
name: 'Dua Lipa',
spotifyId: '6M2wZ9GZgrQXHCFfjv46we'
},
]
Now, this is my user object:
const user = {
id: 'someId',
name: 'someName',
email: 'someEmail'
}
I tried to insert or update user <-> artist relation with this query but I'm getting Bad Request error:
await prisma.user.upsert({
where: {
email: user.email
},
create: {
name: user.name,
email: user.email,
followings: {
connectOrCreate: followings
}
},
update: {
followings: {
connectOrCreate: followings
}
}
})
Please advise what I need to do. Thanks in advance.
P.S. I took the idea of the query from Updating a many-to-many relationship in Prisma post, but it didn't work for me, so please don't mark duplicate.
connectOrCreate should specify where key with id (so Prisma could find this entity) and create key with all required model fields (so Prisma could create it if it not already present), but you just passing an array of models. Change your code to this one:
await prisma.user.upsert({
where: {
email: 'user.email',
},
create: {
name: 'user.name',
email: 'user.email',
followings: {
connectOrCreate: [
{
create: {
name: 'MARINA',
spotifyId: '6CwfuxIqcltXDGjfZsMd9A',
},
where: { id: '...' },
},
],
},
},
update: {
followings: {
connectOrCreate: [
{
create: {
name: 'MARINA',
spotifyId: '6CwfuxIqcltXDGjfZsMd9A',
},
where: { id: '...' },
},
],
},
},
});

What is this mean in GrqphQL Expected type '[OrderCreationNotificationEnum!]

I have a service who provided me api to use and they are using GraphQL.
Everything else seems working fine apart from this section.
I'm using the following query to create an order and it's working fine apart from when I add notifications in there
I'm getting this error
Argument 'notifications' on InputObject 'OrderCreateMutationInput' has an invalid value ({type: {OrderCreationNotificationEnum: {email: true}}}). Expected type '[OrderCreationNotificationEnum!]'
mutation{
orderCreate(input: {
order: {
externalIds:[
{key: "VRPOrderId", value: "abc131"}
]
firstName: "John"
surname: "Doe"
phone: "0405123456"
billingFirstName: "John"
billingSurname: "Doe"
billingEmailAddress: "john#email.com"
address: {
address: "1 Bourke Street"
city: "Melbourne"
country: {
code: "AU"
}
postcode: "3000"
state: {
short: "VIC"
}
}
billingAddress:{
address: "1 Bourke Street"
city: "Melbourne"
country: {
code: "AU"
}
postcode: "3000"
state: {
short: "VIC"
}
}
termsAndConditionsAccepted: true
}
lineItems: [
{
variantId: "VmFyaWFudC00NzMz"
quantity: 1
totalCents: 22500
postageCents: 1000
},
{
variantId: "VmFyaWFudC00NzYy"
quantity: 1
totalCents: 22500
postageCents: 500
}
]
notifications:
{
type: {
OrderCreationNotificationEnum: {
email: true
}
}
}
})
{
order{
id
invoices{
edges{
node{
id
lineItems{
id
quantity
}
}
}
}
}
status
}
}
I am struggling to get the notification working. I'm adding link for the instructions too. Please help.
link to api document
Argument 'notifications' on InputObject 'OrderCreateMutationInput' is an Enum:
enum OrderCreationNotificationEnum {
# Notify the order information via Email
EMAIL
# Notify the order information via SMS
SMS
}
For notifications, you should specify an array of enum values like this:
notifications: [EMAIL, SMS]

Nested Documents in FaunaDB

I am just starting Fauna and FQL. How do we add a nested document inside another document using the online shell?
This is what I have so far
users: [
{
userID: "from google",
userName: "from signup form",
userEmail: "from signup form form",
profileimgurl: "maybe from google",
accessCode: 12345,
role: "main or secondary. customer will automatically become main."
},
{
userID: "from google",
userName: "from signup form",
userEmail: "from signup form form",
profileimgurl: "maybe from google",
accessCode: 12345,
role: "main or secondary. customer will automatically become main."
}
]
Fauna stores data in schemaless Documents, so you can embed arrays or other objects within the Document's data. For example, from the shell:
Create(
Collection("users"),
{
data: {
name: "Paul",
email: "paul#paul.com
address: {
country: "United States",
},
tags: ["pinball", "camping"]
}
}
)
Depending on how you need to read and update your documents, it may be appropriate to save data in a separate collection and maintain relationships with References.
Create(
Collection("public_profiles"),
{
data: {
name: "Paul",
tags: ["pinball", "camping"]
}
}
)
{
ref: Ref(Collection("public_profiles"), "307924242117165124"),
ts: 1629918291110000,
data: { name: "Paul", tags: ["pinball", "camping"] }
}
Update(
Ref(Collection("users"), "307924248572638574"),
{
data: {
tags: null,
profile: Ref(Collection("public_profiles"), "307924242117165124")
}
}
)
The Docs have a Social Graph example that demonstrates how to create and query relationships.

how to join collections in faunadb?

I want to get nested ref's value within the query I'm executing, but by default response is returning the ref of other collection. consider this minimum example; here are user and coin models, within "users" and "coins" collections
user { // ref: 123456
name: foo
location: bar
}
coin { // ref: 124457
amount: 5457
awardedTo: Ref(Collection("users"), "123456")
}
when I run this query
q.Get(q.Ref(q.Collection("coins"), "124457"))
the response is something like this:
{
data: {
amount: 5457,
awardedTo: #ref: {id: "123456", collection: {…}}
},
ref: #ref: {id: "124457", collection: {…}},
ts: 1622547855525255
}
But how is it possible to get nested user's value in the same query to have a response like this:
{
data: {
amount: 5457,
awardedTo: {
name: foo,
location: bar
}
},
ref: #ref: {id: "124457", collection: {…}},
ts: 1622547855525255
}
I have read Join's documentation but it wasn't helpful in this case, and also tried this way, but it didn't work either:
q.Let({
coin: q.Get(q.Ref(q.Collection("coins"), '124457'))
},
q.Union(
q.Get(q.Select(["data","awaredTo"], q.Var("coin"))),
q.Var("coins")
)
)
you can use this FQL:
Let(
{
coin: Select(['data'],Get(Ref(Collection("coin"), "1"))),
user: Select(['data'],Get(Select(['awardedTo'],Var('coin'))))
},
Merge(Var('coin'),{awardedTo:Var('user')})
)
It retrieves data from coin, extracts the user ref and merge all together.
Luigi

Keystone.js nested categories

I am trying to implement nested categories for Post model.
What I have:
Post.add({
title: { type: String, required: true },
state: { type: Types.Select, options: 'draft, published, archived', default: 'draft', index: true },
author: { type: Types.Relationship, ref: 'User', index: true },
publishedDate: { type: Types.Date, index: true, dependsOn: { state: 'published' } },
content: {
extended: { type: Types.Html, wysiwyg: true, height: 300 },
},
categories: { type: Types.Relationship, ref: 'PostCategory', index: true }
});
And category
PostCategory.add({
name: { type: String, required: true },
subCategories: { type: Types.TextArray }
});
Now I can add a list of subcategories to each category.
What I can't do is to display subcategories while creating a post. Also if I change category I need to load sub categories related to selected category.
My plan was to achieve that with watch functionality but it seems only works on save.
Another thing I was thinking about was to add subcategories as relationship, see ref:
categories: { type: Types.Relationship, ref: 'PostCategory.subCategories', index: true }
But it isn't working as well.
So, if anybody has any ideas how to achieve that, please share.
Thanks.
P.S. Don't hesitate to ask any additional information.
I created nested categories by creating a new model 'PostSubCategory' that allows the user to assign the parent category to the child category when they create the child category:
var keystone = require('keystone');
var Types = keystone.Field.Types;
/**
* PostSubCategory Model
* ==================
*/
var PostSubCategory = new keystone.List('PostSubCategory', {
autokey: { from: 'name', path: 'key', unique: true },
});
PostSubCategory.add({
name: {
type: String,
required: true
},
parentCategory: {
type: Types.Relationship,
ref: 'PostCategory',
required: true,
initial: true
}
});
PostSubCategory.relationship({ ref: 'Post', path: 'subcategories' });
PostSubCategory.register();
Then in my Post.js, I add a field to choose a subcategory with a filter on that field to only select from subcategories that are children of the parent category selected:
subcategory: {
type: Types.Relationship,
ref: 'PostSubCategory',
many: false,
filters: { parentCategory: ':categories' }
}
I'm not sure how well this would work for deeper nesting, and I do have an issue in the edit Post admin ui where changing the parent category for a post doesn't update the available subcategories to choose from until you save and refresh. But it got me far enough along for getting parent/child categories to work.