database basically working
This commit is contained in:
29
server/db/model/title.js
Normal file
29
server/db/model/title.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export default class Title {
|
||||
prefix = `TITLE`
|
||||
indices = null
|
||||
|
||||
constructor(indices) {
|
||||
this.indices = indices
|
||||
}
|
||||
|
||||
schema = z.object({
|
||||
id: z.number(),
|
||||
name: z.string()
|
||||
})
|
||||
|
||||
save(newTitle) {
|
||||
let id = `HY-${this.entries.length+1}`
|
||||
if(this.validate(id, newTitle)) {
|
||||
try {
|
||||
global.db.add(id, newTitle)
|
||||
} catch(e) {
|
||||
console.error(e)
|
||||
throw e
|
||||
}
|
||||
} else {
|
||||
throw new global.ServerError(400, "Invalid Member Data!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user