getting organizations from the backend

This commit is contained in:
metacryst
2026-01-11 04:53:55 -06:00
parent 13cdff7a5f
commit 434ecac47a
7 changed files with 47 additions and 29 deletions

View File

@@ -37,9 +37,14 @@ export default class AuthHandler {
const email = payload.email;
const user = db.members.getByEmail(email);
const userOrgs = db.edges.getByFrom(db.members.prefix + "-" + user.id)
res.send({ email: user.email, name: user.firstName + " " + user.lastName });
} catch (err) {
let connections = db.MEMBER_IN_NETWORK.getByFrom(db.members.prefix + "-" + user.id)
let userOrgs = connections.map((v) => {
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" });
}
}

View File

@@ -18,7 +18,6 @@ export default class Database {
let eValues = Object.values(edgeModels)
for(let i = 0; i < eValues.length; i++) {
let key = eValues[i].constructor.name
key = key.toLowerCase() + "s"
this[key] = eValues[i]
}
this.loadData()
@@ -127,7 +126,7 @@ export default class Database {
let indices = model.indices
if(i >= indices[0] && i < indices[1]) {
let prefix = model.prefix
data.nodes[prefix + "-" + entry.id] = entry
data.edges[prefix + "-" + entry.id] = entry
}
}
}

View 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
}
}

View File

@@ -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
}
}

View File

@@ -5,7 +5,7 @@ import Payment from "./payment.js"
import Post from "./forum/post.js"
import Conversation from "./dms/conversation.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 = {
"MEMBER" : [0, 0], // [id, startIndex, nextEmptyIndex
@@ -32,5 +32,5 @@ export let nodeModels = {
}
export let edgeModels = {
MEMBER_IN_NETWORK: new MemberInNetwork(eIndices.MEMBER_IN_NETWORK)
MEMBER_IN_NETWORK: new MEMBER_IN_NETWORK(eIndices.MEMBER_IN_NETWORK)
}

View File

@@ -16,6 +16,11 @@ export default class Network {
})
.strict()
get(id) {
let index = this.indices[0] + (id - 1)
return global.db.nodes[index]
}
save(n) {
let id = `${this.prefix}-${n.id}`
let result = this.schema.safeParse(n)
@@ -39,8 +44,4 @@ export default class Network {
}
this.save(toSave)
}
get(id) {
return this.entries[this.ids[`${this.prefix}-${id}`]]
}
}

View File

@@ -17,7 +17,9 @@ class Sidebar extends Shadow {
.onAppear(async () => {
if(!window.profile) {
window.profile = await this.fetchProfile()
this.rerender()
if(profile) {
this.rerender()
}
}
})
}