Skip to content

Instantly share code, notes, and snippets.

@codyzu
Created September 6, 2019 09:33
Show Gist options
  • Save codyzu/8a8c86c66bc88fff6b065b648ecad028 to your computer and use it in GitHub Desktop.
Save codyzu/8a8c86c66bc88fff6b065b648ecad028 to your computer and use it in GitHub Desktop.
const getUserFromDatabase = memoize(async ctx => {
const {
req: {
headers: {Authorization: userCred},
},
} = ctx;
const user = await db.getUserByCredential(userCred);
return user;
});
const sendMessageToUser = memoize(async ctx => {
const {username} = await getUserFromDatabase(ctx);
await messaging.sendToUser(username, 'hello');
});
const replyOk = memoize(async ctx => {
const {username} = await getUserFromDatabase(ctx);
const {res} = ctx;
res.status(200).send('done');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment