getting organizations from the backend
This commit is contained in:
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 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)
|
||||
}
|
||||
@@ -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}`]]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user