Created
March 23, 2021 18:44
-
-
Save contrasting/306c94c7ee851e9c12815b2bcf48bdc3 to your computer and use it in GitHub Desktop.
function to get user, but feels superfluous
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| exports.getProfile = functions | |
| .region(REGION) | |
| .https.onCall(async (data, context) => { | |
| await init(context); | |
| // let sampleData = "userId"; | |
| if (typeof(data) !== "string") throw new functions.https.HttpsError("invalid-argument"); | |
| let me = await User.findOne({ _id: context.auth.uid }).select(selectOn).lean(); | |
| // if can't find own profile | |
| if (!me) throw new functions.https.HttpsError("not-found"); | |
| // if i'm the one you're looking for | |
| if (data == context.auth.uid) { | |
| return util.transformUserObj(me, me.location.coordinates); | |
| } | |
| let user = await User.findOne({ _id: data }).select(selectOn).lean(); | |
| // can't find the one you're looking for | |
| if (!user) throw new functions.https.HttpsError("not-found"); | |
| return util.transformUserObj(user, me.location.coordinates); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment