CRUD operations for Posts

- added all CRUD operations for Post model
- add() also creates POST_BY_MEMBER and POST_FROM_NETWORK edges
- delete() also deletes associated edges
- delete() currently does not reallocate node/edge indices after deleting
- will write the data to the db.json file and global.db.nodes
This commit is contained in:
2026-02-08 22:34:18 -05:00
parent d6520bf007
commit aaf9d56b1b
10 changed files with 342 additions and 35 deletions

View File

@@ -0,0 +1,37 @@
import { z } from 'zod'
export default class POST_BY_MEMBER {
prefix = "POST_BY_MEMBER"
indices = null
constructor(indices) {
this.indices = indices
}
schema = z.object({
id: z.number(),
type: z.string(),
from: z.string(),
to: z.string(),
created: z.string()
})
.strict()
getAuthorId(postId) {
for (let i = this.indices[0]; i < this.indices[1]; i++) {
if (global.db.edges[i].from === postId) {
return Number(global.db.edges[i].to.split("-")[1]);
}
}
}
getByMember(stringID) {
let result = []
for(let i = this.indices[0]; i < this.indices[1]; i++) {
if(global.db.edges[i].from === stringID) {
result.push(global.db.edges[i])
}
}
return result
}
}

View File

@@ -0,0 +1,29 @@
import { z } from 'zod'
export default class POST_FROM_NETWORK {
prefix = "POST_FROM_NETWORK"
indices = null
constructor(indices) {
this.indices = indices
}
schema = z.object({
id: z.number(),
type: z.string(),
from: z.string(),
to: z.string(),
created: z.string()
})
.strict()
getByNetwork(id) {
let result = []
for(let i = this.indices[0]; i < this.indices[1]; i++) {
if(global.db.edges[i].to === `${global.db.networks.prefix}-${id}`) {
result.push(global.db.edges[i])
}
}
return result
}
}