Skip to content

Instantly share code, notes, and snippets.

@contrasting
Created March 23, 2021 18:44
Show Gist options
  • Select an option

  • Save contrasting/306c94c7ee851e9c12815b2bcf48bdc3 to your computer and use it in GitHub Desktop.

Select an option

Save contrasting/306c94c7ee851e9c12815b2bcf48bdc3 to your computer and use it in GitHub Desktop.
function to get user, but feels superfluous
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