mirror of
https://github.com/filecoin-project/slate.git
synced 2024-11-23 05:54:49 +03:00
serializer: adds a serialize for subscriptions for @martinalong to evaluate
This commit is contained in:
parent
8039d31192
commit
76c9e5e10e
@ -1,3 +1,5 @@
|
||||
import DB from "~/node_common/database";
|
||||
|
||||
export const user = (entity) => {
|
||||
return {
|
||||
type: "USER",
|
||||
@ -24,3 +26,48 @@ export const slate = (entity) => {
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const doSubscriptions = async ({ users, slates, subscriptions }) => {
|
||||
subscriptions.forEach((each) => {
|
||||
if (each.target_user_id) {
|
||||
users.push(each.target_user_id);
|
||||
}
|
||||
|
||||
if (each.target_slate_id) {
|
||||
slates.push(each.target_slate_id);
|
||||
}
|
||||
});
|
||||
|
||||
const userEntities = await DB.select("id", "username", "data")
|
||||
.from("users")
|
||||
.whereIn("id", users);
|
||||
|
||||
const slateEntities = await DB.select("id", "slatename", "data")
|
||||
.from("slates")
|
||||
.whereIn("id", slates);
|
||||
|
||||
const sanitized = subscriptions.map((data) => {
|
||||
let u = null;
|
||||
let o = null;
|
||||
let s = null;
|
||||
|
||||
if (data.target_user_id) {
|
||||
u = userEntities.find((e) => data.target_user_id === e.id);
|
||||
u = user(u);
|
||||
}
|
||||
|
||||
if (data.owner_user_id) {
|
||||
o = userEntities.find((e) => data.owner_user_id === e.id);
|
||||
o = user(o);
|
||||
}
|
||||
|
||||
if (data.target_slate_id) {
|
||||
s = slateEntities.find((e) => data.target_slate_id === e.id);
|
||||
s = slate(s);
|
||||
}
|
||||
|
||||
return { ...data, user: u, owner: o, slate: s };
|
||||
});
|
||||
|
||||
return JSON.parse(JSON.stringify(sanitized));
|
||||
};
|
||||
|
@ -2,6 +2,7 @@ import * as Utilities from "~/node_common/utilities";
|
||||
import * as Data from "~/node_common/data";
|
||||
import * as Powergate from "~/node_common/powergate";
|
||||
import * as Constants from "~/node_common/constants";
|
||||
import * as Serializers from "~/common/serializers";
|
||||
|
||||
export const getById = async ({ id }) => {
|
||||
const user = await Data.getUserById({
|
||||
@ -20,6 +21,13 @@ export const getById = async ({ id }) => {
|
||||
const slates = await Data.getSlatesByUserId({ userId: id });
|
||||
const keys = await Data.getAPIKeysByUserId({ userId: id });
|
||||
const subscriptions = await Data.getSubscriptionsByUserId({ userId: id });
|
||||
|
||||
const serializedSubscriptions = await Serializers.doSubscriptions({
|
||||
users: [id],
|
||||
slates: [],
|
||||
subscriptions,
|
||||
});
|
||||
|
||||
const activity = await Data.getActivityForUserId({ userId: id });
|
||||
const trusted = await Data.getTrustedRelationshipsByUserId({ userId: id });
|
||||
const pendingTrusted = await Data.getPendingTrustedRelationshipsByUserId({
|
||||
@ -56,7 +64,7 @@ export const getById = async ({ id }) => {
|
||||
status: null,
|
||||
addrsList: null,
|
||||
info: null,
|
||||
subscriptions,
|
||||
subscriptions: serializedSubscriptions,
|
||||
activity,
|
||||
trusted,
|
||||
pendingTrusted,
|
||||
|
@ -105,8 +105,6 @@ export default class IntegrationPage extends React.Component {
|
||||
};
|
||||
|
||||
render() {
|
||||
console.log(this.state.viewer);
|
||||
|
||||
return (
|
||||
<div css={STYLES_ROW}>
|
||||
<div css={STYLES_COLUMN}>
|
||||
|
Loading…
Reference in New Issue
Block a user