imp
This commit is contained in:
parent
a1715aa117
commit
228c204255
@ -1,17 +1,46 @@
|
|||||||
|
import { Request, Response } from 'express';
|
||||||
|
import { KnexCrudOptions } from './KnexCrudOptions';
|
||||||
import { CrudHandler } from './CrudHandler';
|
import { CrudHandler } from './CrudHandler';
|
||||||
|
|
||||||
export class KnexCrudHandler implements CrudHandler {
|
export class KnexCrudHandler implements CrudHandler {
|
||||||
protected table: string;
|
protected table: string;
|
||||||
protected columns: Array<string>;
|
protected columns: Array<string>;
|
||||||
protected options: Record<string, unknown>;
|
protected options: KnexCrudOptions;
|
||||||
|
|
||||||
public constructor (
|
public constructor (
|
||||||
table: string,
|
table: string,
|
||||||
columns: Array<string>,
|
columns: Array<string>,
|
||||||
options: Record<string, unknown> = {}
|
options: KnexCrudOptions = {}
|
||||||
) {
|
) {
|
||||||
this.table = table;
|
this.table = table;
|
||||||
this.columns = columns;
|
this.columns = columns;
|
||||||
this.options = options;
|
this.options = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private call_auth (auth?: Function, req: Request, res: Response): boolean {
|
||||||
|
if (typeof auth === 'undefined')
|
||||||
|
return true;
|
||||||
|
|
||||||
|
const promise = new Promise ((resolve) => {
|
||||||
|
const result = auth (req, res, resolve);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async create (req: Request, res: Response): Promise<void> {
|
||||||
|
if (typeof req.body === 'undefined')
|
||||||
|
throw new Error ('request body is undefined. is body-parser running?');
|
||||||
|
const data = JSON.parse (req.body);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async read (req: Request, res: Response): Promise<void> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public async update (req: Request, res: Response): Promise<void> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public async delete (req: Request, res: Response): Promise<void> {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
25
lib/KnexCrudOptions.ts
Normal file
25
lib/KnexCrudOptions.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { Request, Response } from 'express';
|
||||||
|
|
||||||
|
type Authentication = {
|
||||||
|
(req: Request, res: Response, next: Function);
|
||||||
|
(req: Request, res: Response): boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
type Authorization = {
|
||||||
|
(req: Request, res: Response, next: Function);
|
||||||
|
(req: Request, res: Response): boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class KnexCrudOptions {
|
||||||
|
public create_authentication?: Authentication;
|
||||||
|
public read_authentication?: Authentication;
|
||||||
|
public update_authentication?: Authentication;
|
||||||
|
public delete_authentication?: Authentication;
|
||||||
|
|
||||||
|
public create_authorization?: Authorization;
|
||||||
|
public read_authorization?: Authorization;
|
||||||
|
public update_authorization?: Authorization;
|
||||||
|
public delete_authorization?: Authorization;
|
||||||
|
|
||||||
|
public optional_columns?: Array<string>;
|
||||||
|
}
|
Reference in New Issue
Block a user