refactoring controller responses (in progress)

This commit is contained in:
Mikayla Dobson
2022-12-12 20:07:09 -06:00
parent 362cf752d0
commit d2b06ced7a
6 changed files with 83 additions and 44 deletions

View File

@@ -0,0 +1,17 @@
import { CtlResponse } from "./types";
export default class ControllerResponse<T> implements CtlResponse<T> {
ok: boolean
code: number
data: T | T[] | string
constructor(ok: boolean, code: number, data: T | T[] | string) {
this.ok = ok
this.code = code
this.data = data
}
send() {
return { ok: this.ok, code: this.code, data: this.data }
}
}

5
server/util/types.ts Normal file
View File

@@ -0,0 +1,5 @@
export interface CtlResponse<T> {
ok: boolean
code: number
data: T | T[] | string
}