getting organizations from the backend
This commit is contained in:
@@ -37,9 +37,14 @@ export default class AuthHandler {
|
|||||||
const email = payload.email;
|
const email = payload.email;
|
||||||
|
|
||||||
const user = db.members.getByEmail(email);
|
const user = db.members.getByEmail(email);
|
||||||
const userOrgs = db.edges.getByFrom(db.members.prefix + "-" + user.id)
|
let connections = db.MEMBER_IN_NETWORK.getByFrom(db.members.prefix + "-" + user.id)
|
||||||
res.send({ email: user.email, name: user.firstName + " " + user.lastName });
|
let userOrgs = connections.map((v) => {
|
||||||
} catch (err) {
|
return db.networks.get(v.id)
|
||||||
|
})
|
||||||
|
console.log(userOrgs)
|
||||||
|
res.send({ email: user.email, name: user.firstName + " " + user.lastName, networks: userOrgs});
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Error getting profile: ", e)
|
||||||
res.status(401).send({ error: "Invalid token" });
|
res.status(401).send({ error: "Invalid token" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ export default class Database {
|
|||||||
let eValues = Object.values(edgeModels)
|
let eValues = Object.values(edgeModels)
|
||||||
for(let i = 0; i < eValues.length; i++) {
|
for(let i = 0; i < eValues.length; i++) {
|
||||||
let key = eValues[i].constructor.name
|
let key = eValues[i].constructor.name
|
||||||
key = key.toLowerCase() + "s"
|
|
||||||
this[key] = eValues[i]
|
this[key] = eValues[i]
|
||||||
}
|
}
|
||||||
this.loadData()
|
this.loadData()
|
||||||
@@ -127,7 +126,7 @@ export default class Database {
|
|||||||
let indices = model.indices
|
let indices = model.indices
|
||||||
if(i >= indices[0] && i < indices[1]) {
|
if(i >= indices[0] && i < indices[1]) {
|
||||||
let prefix = model.prefix
|
let prefix = model.prefix
|
||||||
data.nodes[prefix + "-" + entry.id] = entry
|
data.edges[prefix + "-" + entry.id] = entry
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
28
server/db/model/edges/MEMBER_IN_NETWORK.js
Normal file
28
server/db/model/edges/MEMBER_IN_NETWORK.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { z } from 'zod'
|
||||||
|
|
||||||
|
export default class MEMBER_IN_NETWORK {
|
||||||
|
prefix = "MEMBER_IN_NETWORK"
|
||||||
|
indices = null
|
||||||
|
|
||||||
|
constructor(indices) {
|
||||||
|
this.indices = indices
|
||||||
|
}
|
||||||
|
|
||||||
|
schema = z.object({
|
||||||
|
id: z.number(),
|
||||||
|
from: z.string(),
|
||||||
|
to: z.string(),
|
||||||
|
created: z.string()
|
||||||
|
})
|
||||||
|
.strict()
|
||||||
|
|
||||||
|
getByFrom(fromID) {
|
||||||
|
let result = []
|
||||||
|
for(let i = this.indices[0]; i < this.indices[1]; i++) {
|
||||||
|
if(global.db.edges[i].from === fromID) {
|
||||||
|
result.push(global.db.edges[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
import { z } from 'zod'
|
|
||||||
|
|
||||||
export default class MemberInNetwork {
|
|
||||||
schema = z.object({
|
|
||||||
id: z.number(),
|
|
||||||
from: z.string(),
|
|
||||||
to: z.string(),
|
|
||||||
created: z.string()
|
|
||||||
})
|
|
||||||
.strict()
|
|
||||||
|
|
||||||
indices = null
|
|
||||||
|
|
||||||
constructor(indices) {
|
|
||||||
this.indices = indices
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,7 @@ import Payment from "./payment.js"
|
|||||||
import Post from "./forum/post.js"
|
import Post from "./forum/post.js"
|
||||||
import Conversation from "./dms/conversation.js"
|
import Conversation from "./dms/conversation.js"
|
||||||
import DM from "./dms/dm.js"
|
import DM from "./dms/dm.js"
|
||||||
import MemberInNetwork from "./edges/MemberInNetwork.js"
|
import MEMBER_IN_NETWORK from "./edges/MEMBER_IN_NETWORK.js"
|
||||||
|
|
||||||
let nIndices = {
|
let nIndices = {
|
||||||
"MEMBER" : [0, 0], // [id, startIndex, nextEmptyIndex
|
"MEMBER" : [0, 0], // [id, startIndex, nextEmptyIndex
|
||||||
@@ -32,5 +32,5 @@ export let nodeModels = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export let edgeModels = {
|
export let edgeModels = {
|
||||||
MEMBER_IN_NETWORK: new MemberInNetwork(eIndices.MEMBER_IN_NETWORK)
|
MEMBER_IN_NETWORK: new MEMBER_IN_NETWORK(eIndices.MEMBER_IN_NETWORK)
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,11 @@ export default class Network {
|
|||||||
})
|
})
|
||||||
.strict()
|
.strict()
|
||||||
|
|
||||||
|
get(id) {
|
||||||
|
let index = this.indices[0] + (id - 1)
|
||||||
|
return global.db.nodes[index]
|
||||||
|
}
|
||||||
|
|
||||||
save(n) {
|
save(n) {
|
||||||
let id = `${this.prefix}-${n.id}`
|
let id = `${this.prefix}-${n.id}`
|
||||||
let result = this.schema.safeParse(n)
|
let result = this.schema.safeParse(n)
|
||||||
@@ -39,8 +44,4 @@ export default class Network {
|
|||||||
}
|
}
|
||||||
this.save(toSave)
|
this.save(toSave)
|
||||||
}
|
}
|
||||||
|
|
||||||
get(id) {
|
|
||||||
return this.entries[this.ids[`${this.prefix}-${id}`]]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,9 @@ class Sidebar extends Shadow {
|
|||||||
.onAppear(async () => {
|
.onAppear(async () => {
|
||||||
if(!window.profile) {
|
if(!window.profile) {
|
||||||
window.profile = await this.fetchProfile()
|
window.profile = await this.fetchProfile()
|
||||||
this.rerender()
|
if(profile) {
|
||||||
|
this.rerender()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user