Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
...data,
email: this.newEmail,
newEmail: null
};
}
const updateUser = new Promise((resolve, reject) =>
this.updateAttributes(data, err => {
if (err) {
return reject(err);
}
return resolve();
})
);
return Observable.combineLatest(
createToken,
Observable.fromPromise(updateUser),
req.logIn(this),
accessToken => accessToken
);
};
const getRandomGif = topic => {
const url =
"https://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC&tag=" + topic
const json = fetch(url).then(res => res.json())
return Observable.fromPromise(json)
.map(json => json.data.image_url)
.map(Msg.FetchSucceed)
}
export async function getIncomingFriendRequestsAwaitingReply(user: User): Promise> {
const {id} = user;
return Observable
.fromPromise(cypher(
`MATCH (from:User)-[friendRequest:WANTS_TO_BE_FRIENDS_WITH {${ACTIVE_FRIEND_REQUEST_PROPERTIES}}]->(to:User {id:{id}})
RETURN from, to, friendRequest`,
{id}))
.flatMap(Observable.from)
.map(result => FriendRequest.createFromEntity(result.friendRequest,
User.createFromEntity(result.from),
User.createFromEntity(result.to)))
.toArray()
.toPromise();
}
.flatMap(() => {
const updatePromise = new Promise((resolve, reject) =>
this.updateAttributes(updateConfig, err => {
if (err) {
return reject(err);
}
return resolve();
})
);
return Observable.forkJoin(
Observable.fromPromise(updatePromise),
this.requestAuthEmail(false, newEmail),
(_, message) => message
);
});
} else {
return Observable.defer(() => {
const isOwnUsername = isTheSame(newUsername.toLowerCase(), this.username);
if (isOwnUsername) {
return Observable.of(dedent`
${newUsername} is already associated with this account.
`);
}
return Observable.fromPromise(User.doesExist(newUsername.toLowerCase()));
}).flatMap(boolOrMessage => {
if (typeof boolOrMessage === 'string') {
export async function getAllUsers(): Promise> {
return Observable.fromPromise(cypher("MATCH (user:User) return user"))
.flatMap(Observable.from)
.map(result => result.user)
.map(User.createFromEntity)
.toArray()
.toPromise()
}
export async function isFriends(user1: User, user2: User): Promise {
if (user1.id === user2.id) {
return false;
}
return Observable
.fromPromise(cypher("MATCH (u:User {id:{id1}})-[:IS_FRIENDS_WITH]-(u2:User {id:{id2}}) return count(u);",
{
id1: user1.id,
id2: user2.id
}
))
.map(result => result[0]["count(u)"])
.map(count => count > 0)
.toPromise();
}
export async function createFriendRequest(sender: User, receiver: User): Promise {
await verifyFriendRequestCanBeCreated(sender, receiver);
const createdAt = new Date();
const props = {
id: generateUuid(),
accepted: false,
ignored: false,
declined: false,
createdAt
};
return Observable
.fromPromise(cypher(
`MATCH (from:User {id:{senderId}})
MATCH (to:User {id:{receiverId}})
CREATE (from)-[friendRequest:WANTS_TO_BE_FRIENDS_WITH {${getQueryProps(props)}}]->(to)
RETURN from, to, friendRequest`,
{
senderId: sender.id,
receiverId: receiver.id,
...props
}))
.flatMap(Observable.from)
.map(result => FriendRequest.createFromEntity(result.friendRequest, sender, receiver))
.toPromise();
}
User.prototype.updateMyProfileUI = function updateMyProfileUI(profileUI) {
const newProfileUI = {
...this.profileUI,
...profileUI
};
const profileUIUpdate = new Promise((resolve, reject) =>
this.updateAttribute('profileUI', newProfileUI, err => {
if (err) {
return reject(err);
}
return resolve();
})
);
return Observable.fromPromise(profileUIUpdate).map(
() => dedent`
Your privacy settings have been updated.
`
);
};
export async function getAllUsersConnection(connectionArguments: Object,
orderByProperty: "id"|"createdAt" = "createdAt"): Promise> {
const {first, last, before, after} = connectionArguments;
return Observable
.fromPromise(cypher(getConnectionMatchQuery("User", "user", orderByProperty, connectionArguments)))
.flatMap(Observable.from)
.map(result => result.user)
.map(Animal.createFromEntity)
.toArray()
.toPromise();
}