-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcrudWrapper.ts
More file actions
32 lines (28 loc) · 1.1 KB
/
crudWrapper.ts
File metadata and controls
32 lines (28 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { TableClient } from '@azure/data-tables';
import { AzureFunction, Context, HttpRequest } from '@azure/functions';
export default function crud(get: AzureFunction, post: AzureFunction, put: AzureFunction, del: AzureFunction, domain: string) {
return async function (context: Context, req: HttpRequest, ...args: any[]): Promise<void> {
const tableClient = TableClient.fromConnectionString(process.env.AzureWebJobsStorage, domain);
await tableClient.createTable();
args.push(tableClient);
switch (req.method) {
case "GET":
await get(context, req, ...args);
break;
case "POST":
await post(context, req, ...args);
break;
case "PUT":
await put(context, req, ...args);
break;
case "DELETE":
await del(context, req, ...args);
break;
default:
context.res = {
status: 405,
body: "Method not allowed"
};
}
};
}