Hey guys, I have this helper function and I’m trying to get specific fields of the user but It seems not working. I’ve tried different ways, deleting the fields I don’t want or even returning another object with the fields I want. Both ways are not working. The first way I still get all fields and the second I get only 2/3 fields of the 9/10 (Weird behavior).
async function getUser(username, wholeObject = false, userId,userAddress = null) {
let userQuery = new Moralis.Query("User");
logger.info(`username: ${username}`);
logger.info(`byDwriterId: ${userId}`);
userId && userQuery.equalTo("objectId", userId);
username && userQuery.equalTo("username", username);
userAddress && userQuery.equalTo("ethAddress", userAddress);
let result = await userQuery.first({
useMasterKey: true,
});
logger.info(`result [getUser] -> ${JSON.stringify(result)}`);
if (!result) {
return {};
}
if (wholeObject) {
return result;
}
delete result["ACL"];
delete result["className"];
delete result["__type"];
delete result["authData"];
return result;
// Consider this return the second option mentioned on the topic that is not working too
return {
id: result.id,
username: result.username,
verified: result.verified,
image: result.profilePic,
displayName: result.displayName,
bio: result.bio,
address: {
blockchain: "ethereum",
value: result.ethAddress,
},
social_media: {
twitter: result.twitter,
instagram: result.instagram,
discord: result.discord,
},
updated_at: result.updateAt,
created_at: result.createdAt,
};
}