slate/node_common/data/methods/get-user-by-twitter-id.js
2021-06-08 15:53:30 -07:00

28 lines
771 B
JavaScript

import * as Serializers from "~/node_common/serializers";
import { runQuery } from "~/node_common/data/utilities";
//NOTE(toast): should only be used for checking if an email is taken
//ALWAYS sanitize it before sending result to frontend
export default async ({ twitterId }) => {
return await runQuery({
label: "GET_USER_BY_TWITTER_ID",
queryFn: async (DB) => {
let query = await DB.select("*").from("users").where({ twitterId: twitterId }).first();
if (!query || query.error) {
return null;
}
query = Serializers.sanitizeUser(query);
return JSON.parse(JSON.stringify(query));
},
errorFn: async (e) => {
return {
error: true,
decorator: "GET_USER_BY_TWITTER_ID",
};
},
});
};