database basically working
This commit is contained in:
47
server/db/model/payment.js
Normal file
47
server/db/model/payment.js
Normal file
@@ -0,0 +1,47 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export default class Payment {
|
||||
prefix = "PAYMENT"
|
||||
indices = null
|
||||
|
||||
constructor(indices) {
|
||||
this.indices = indices
|
||||
}
|
||||
|
||||
schema = z.object({
|
||||
id: z.number(),
|
||||
name: z.string(),
|
||||
email: z.string(),
|
||||
time: z.string(),
|
||||
amount: z.number(),
|
||||
product: z.string(),
|
||||
})
|
||||
|
||||
save(payment) {
|
||||
let id = `${this.prefix}-${payment.id}`
|
||||
let result = this.schema.safeParse(payment)
|
||||
if(result.success) {
|
||||
try {
|
||||
super.add(id, payment)
|
||||
} catch(e) {
|
||||
console.error(e)
|
||||
throw e
|
||||
}
|
||||
} else {
|
||||
console.error(result.error)
|
||||
throw new global.ServerError(400, "Invalid Member Data!");
|
||||
}
|
||||
}
|
||||
|
||||
add(paymentObj) {
|
||||
let toSave = {
|
||||
id: this.entries.length+1,
|
||||
...paymentObj
|
||||
}
|
||||
this.save(toSave)
|
||||
}
|
||||
|
||||
get(id) {
|
||||
return this.entries[this.ids[`${this.prefix}-${id}`]]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user