2020-07-21 14:36:50 +03:00
|
|
|
import * as Utilities from "~/node_common/utilities";
|
|
|
|
import * as Data from "~/node_common/data";
|
|
|
|
|
|
|
|
import PG from "~/node_common/powergate";
|
|
|
|
|
2020-07-22 13:51:40 +03:00
|
|
|
export const getViewer = async ({ id }) => {
|
|
|
|
const user = await Data.getUserById({
|
|
|
|
id,
|
2020-07-21 14:36:50 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (user.error) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-07-22 10:41:29 +03:00
|
|
|
let data = null;
|
2020-07-21 14:36:50 +03:00
|
|
|
|
2020-07-22 10:41:29 +03:00
|
|
|
// NOTE(jim): Essential for getting the right Powergate data for a user.
|
|
|
|
try {
|
|
|
|
PG.setToken(user.data.tokens.pg);
|
|
|
|
|
|
|
|
data = {
|
|
|
|
id: user.id,
|
|
|
|
data: { photo: user.data.photo },
|
|
|
|
settings: {
|
|
|
|
deals_auto_approve: user.data.settings_deals_auto_approve,
|
|
|
|
},
|
|
|
|
username: user.username,
|
|
|
|
library: user.data.library,
|
|
|
|
peersList: null,
|
|
|
|
messageList: null,
|
|
|
|
status: null,
|
|
|
|
addrsList: null,
|
|
|
|
info: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
const updates = await Utilities.refresh({ PG });
|
|
|
|
const updatesWithToken = await Utilities.refreshWithToken({
|
|
|
|
PG,
|
|
|
|
});
|
|
|
|
|
|
|
|
data = await Utilities.updateStateData(data, {
|
|
|
|
...updates,
|
|
|
|
...updatesWithToken,
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
return null;
|
|
|
|
}
|
2020-07-21 14:36:50 +03:00
|
|
|
|
|
|
|
return data;
|
|
|
|
};
|