Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise(async (resolve, reject) => {
Loading.show({
message: "Loading profile..."
});
try {
const {
// @ts-ignore
data: { getLoyalty: loyaltyData }
} = await API.graphql(graphqlOperation(getLoyalty));
const loyalty = new Loyalty(loyaltyData);
commit("SET_LOYALTY", loyalty);
Loading.hide();
resolve();
} catch (err) {
Loading.hide();
reject(err);
}
});
}
async function fetchPosts(dispatch) {
try {
const postData = await API.graphql(graphqlOperation(listPosts))
dispatch({
type: 'fetchPostsSuccess',
posts: postData.data.listPosts.items
})
} catch (err) {
console.log('error fetching posts...: ', err)
dispatch({
type: 'fetchPostsError',
})
}
}
async handleSubmit(event) {
event.preventDefault();
event.stopPropagation();
const message = {
"message":this.state.value
}
await API.graphql(graphqlOperation(sendMessage, message));
}
const restaurant = {
name,
description,
city,
clientId: CLIENTID
}
const restaurants = [...state.restaurants, restaurant]
dispatch({
type: 'set',
restaurants
})
try {
await API.graphql(graphqlOperation(createRestaurant, {
input: restaurant
}))
console.log('restaurant created!')
} catch (err) {
console.log('error creating restaurant...', err)
}
}
async componentDidMount(){
//Create subscription for real-time points balance update
this.subscription = API.graphql(graphqlOperation(subscribeToPoints)).subscribe({
next: (event) => {
console.log("Subscription: "+event.value.data);
this.setState({points: event.value.data.subscribeToPoints.points});
}
});
}
const { name, description, city } = state
const restaurant = {
name,
description,
city,
clientId: CLIENTID
}
const updatedRestaurantArray = [...state.restaurants, restaurant]
dispatch({
type: 'set',
restaurants: updatedRestaurantArray
})
try {
await API.graphql(graphqlOperation(createRestaurant, {
input: restaurant
}))
console.log('item created!')
} catch (err) {
console.log('error creating restaurant...', err)
}
}
updateSettings = async (input, type) => {
try {
await API.graphql(graphqlOperation(createSettings, { input }))
console.log(`${type} successfully updated...`)
} catch (err) {
if (err.errors[0].message.includes('The conditional request failed')) {
console.log(`${type} already set.... Updating ${type}.`)
try {
await API.graphql(graphqlOperation(updateSettings, { input }))
console.log(`${type} successfully updated...`)
} catch (err) {
console.log(`error updating ${type}: `, err)
}
}
}
}
updateTheme = theme => {
async function fetchTalks(dispatch) {
try {
getFromStorage(dispatch)
const talkData = await API.graphql(graphqlOperation(listTalks))
console.log('talkData: ', talkData)
const talks = talkData.data.listTalks.items
setToStorage(talks)
dispatch({ type: 'set', talks })
} catch (error) {
console.log('error:', error)
dispatch({ type: 'error', error })
}
}
const go = async () => {
const result = await API.graphql(
graphqlOperation(queries.queryByOwner, {
owner: user.attributes.sub,
sortDirection: 'DESC',
limit: 10
})
)
setpastQueries(result.data.queryByOwner)
}
go()