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

@@ -63,6 +63,39 @@ export default class Database {
}
}
deleteNode(prefix, id) {
try {
let model = nodeModels[prefix]
if(model) {
this.nodes[model.indices[0] + (id - 1)] = 0
} else {
throw new Error("Type does not exist for node: " + id)
}
} catch(e) {
throw e
}
}
editNode(prefix, id, toEdit) {
try {
let model = nodeModels[prefix]
if(model) {
let schema = model.schema
let result = schema.safeParse(toEdit)
if(result.success) {
this.nodes[model.indices[0] + (id - 1)] = toEdit
} else {
console.error(result.error)
throw new global.ServerError(400, "Invalid Data!");
}
} else {
throw new Error("Type does not exist for node: " + prefix)
}
} catch(e) {
throw e
}
}
addEdge(prefix, edge) {
try {
let type = prefix
@@ -83,7 +116,22 @@ export default class Database {
throw new global.ServerError(400, "Invalid Data!");
}
} else {
throw new Error("Type does not exist for edge: " + id)
throw new Error("Type does not exist for edge: " + prefix)
}
} catch(e) {
throw e
}
}
deleteEdge(prefix, id) {
try {
let model = edgeModels[prefix]
if(model) {
console.log(model.indices[0] + (id - 1))
this.edges[model.indices[0] + (id - 1)] = 0
console.log(this.edges[model.indices[0] + (id - 1)])
} else {
throw new Error("Type does not exist for edge: " + prefix)
}
} catch(e) {
throw e