@arkstack/driver-express 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +79 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -0
- package/stubs/controller.api.resource.stub +96 -0
- package/stubs/controller.api.stub +92 -0
- package/stubs/controller.model.stub +125 -0
- package/stubs/controller.stub +11 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ErrorRequestHandler, Express, Handler } from "express";
|
|
2
|
+
import { ArkstackKitDriver, PromiseOrValue } from "@arkstack/contract";
|
|
3
|
+
|
|
4
|
+
//#region src/index.d.ts
|
|
5
|
+
interface ExpressDriverOptions {
|
|
6
|
+
bindRouter: (app: Express) => PromiseOrValue<void>;
|
|
7
|
+
errorHandler?: ErrorRequestHandler | Handler;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The ExpressDriver class implements the ArkstackKitDriver
|
|
11
|
+
* contract for the Express framework.
|
|
12
|
+
*/
|
|
13
|
+
declare class ExpressDriver extends ArkstackKitDriver<Express, Handler> {
|
|
14
|
+
readonly name = "express";
|
|
15
|
+
private readonly options;
|
|
16
|
+
/**
|
|
17
|
+
* Creates an instance of ExpressDriver.
|
|
18
|
+
*
|
|
19
|
+
* @param options
|
|
20
|
+
*/
|
|
21
|
+
constructor(options: ExpressDriverOptions);
|
|
22
|
+
/**
|
|
23
|
+
* Creates an Express application instance.
|
|
24
|
+
*
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
createApp(): Express;
|
|
28
|
+
/**
|
|
29
|
+
* Mounts static assets from the specified public path to the Express application.
|
|
30
|
+
*
|
|
31
|
+
* @param app
|
|
32
|
+
* @param publicPath
|
|
33
|
+
*/
|
|
34
|
+
mountPublicAssets(app: Express, publicPath: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Binds the router to the Express application using the provided bindRouter function.
|
|
37
|
+
*
|
|
38
|
+
* @param app
|
|
39
|
+
*/
|
|
40
|
+
bindRouter(app: Express): PromiseOrValue<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Applies middleware to the Express application.
|
|
43
|
+
*
|
|
44
|
+
* @param app
|
|
45
|
+
* @param middleware
|
|
46
|
+
*/
|
|
47
|
+
applyMiddleware(app: Express, middleware: Handler): void;
|
|
48
|
+
/**
|
|
49
|
+
* Registers an error handler middleware to the Express
|
|
50
|
+
* application if provided in the options.
|
|
51
|
+
*
|
|
52
|
+
* @param app
|
|
53
|
+
*/
|
|
54
|
+
registerErrorHandler(app: Express): void;
|
|
55
|
+
/**
|
|
56
|
+
* Starts the Express server on the specified port.
|
|
57
|
+
*
|
|
58
|
+
* @param app
|
|
59
|
+
* @param port
|
|
60
|
+
*/
|
|
61
|
+
start(app: Express, port: number): void;
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
export { ExpressDriver, ExpressDriverOptions };
|
|
65
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import { ArkstackKitDriver } from "@arkstack/contract";
|
|
3
|
+
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
/**
|
|
6
|
+
* The ExpressDriver class implements the ArkstackKitDriver
|
|
7
|
+
* contract for the Express framework.
|
|
8
|
+
*/
|
|
9
|
+
var ExpressDriver = class extends ArkstackKitDriver {
|
|
10
|
+
name = "express";
|
|
11
|
+
options;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of ExpressDriver.
|
|
14
|
+
*
|
|
15
|
+
* @param options
|
|
16
|
+
*/
|
|
17
|
+
constructor(options) {
|
|
18
|
+
super();
|
|
19
|
+
this.options = options;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Creates an Express application instance.
|
|
23
|
+
*
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
createApp() {
|
|
27
|
+
return express();
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Mounts static assets from the specified public path to the Express application.
|
|
31
|
+
*
|
|
32
|
+
* @param app
|
|
33
|
+
* @param publicPath
|
|
34
|
+
*/
|
|
35
|
+
mountPublicAssets(app, publicPath) {
|
|
36
|
+
app.use(express.static(publicPath));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Binds the router to the Express application using the provided bindRouter function.
|
|
40
|
+
*
|
|
41
|
+
* @param app
|
|
42
|
+
*/
|
|
43
|
+
bindRouter(app) {
|
|
44
|
+
return this.options.bindRouter(app);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Applies middleware to the Express application.
|
|
48
|
+
*
|
|
49
|
+
* @param app
|
|
50
|
+
* @param middleware
|
|
51
|
+
*/
|
|
52
|
+
applyMiddleware(app, middleware) {
|
|
53
|
+
app.use(middleware);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Registers an error handler middleware to the Express
|
|
57
|
+
* application if provided in the options.
|
|
58
|
+
*
|
|
59
|
+
* @param app
|
|
60
|
+
*/
|
|
61
|
+
registerErrorHandler(app) {
|
|
62
|
+
if (this.options.errorHandler) app.use(this.options.errorHandler);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Starts the Express server on the specified port.
|
|
66
|
+
*
|
|
67
|
+
* @param app
|
|
68
|
+
* @param port
|
|
69
|
+
*/
|
|
70
|
+
start(app, port) {
|
|
71
|
+
app.listen(port, () => {
|
|
72
|
+
console.log(`Server is running on http://localhost:${port}`);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
export { ExpressDriver };
|
|
79
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import express, { type ErrorRequestHandler, type Express, type Handler } from \"express\";\n\nimport { ArkstackKitDriver, PromiseOrValue } from \"@arkstack/contract\";\n\nexport interface ExpressDriverOptions {\n bindRouter: (app: Express) => PromiseOrValue<void>;\n errorHandler?: ErrorRequestHandler | Handler;\n}\n\n/**\n * The ExpressDriver class implements the ArkstackKitDriver \n * contract for the Express framework.\n */\nexport class ExpressDriver extends ArkstackKitDriver<Express, Handler> {\n readonly name = \"express\";\n private readonly options: ExpressDriverOptions;\n\n /**\n * Creates an instance of ExpressDriver.\n * \n * @param options \n */\n constructor(options: ExpressDriverOptions) {\n super();\n this.options = options;\n }\n\n /**\n * Creates an Express application instance.\n * \n * @returns \n */\n createApp (): Express {\n return express();\n }\n\n /**\n * Mounts static assets from the specified public path to the Express application.\n * \n * @param app \n * @param publicPath \n */\n mountPublicAssets (app: Express, publicPath: string): void {\n app.use(express.static(publicPath));\n }\n\n /**\n * Binds the router to the Express application using the provided bindRouter function.\n * \n * @param app \n */\n bindRouter (app: Express): PromiseOrValue<void> {\n return this.options.bindRouter(app);\n }\n\n /**\n * Applies middleware to the Express application.\n * \n * @param app \n * @param middleware \n */\n applyMiddleware (app: Express, middleware: Handler): void {\n app.use(middleware);\n }\n\n /**\n * Registers an error handler middleware to the Express \n * application if provided in the options.\n * \n * @param app \n */\n registerErrorHandler (app: Express): void {\n if (this.options.errorHandler) {\n app.use(this.options.errorHandler as ErrorRequestHandler);\n }\n }\n\n /**\n * Starts the Express server on the specified port.\n * \n * @param app \n * @param port \n */\n start (app: Express, port: number): void {\n app.listen(port, () => {\n console.log(`Server is running on http://localhost:${port}`);\n });\n }\n}\n"],"mappings":";;;;;;;;AAaA,IAAa,gBAAb,cAAmC,kBAAoC;CACnE,AAAS,OAAO;CAChB,AAAiB;;;;;;CAOjB,YAAY,SAA+B;AACvC,SAAO;AACP,OAAK,UAAU;;;;;;;CAQnB,YAAsB;AAClB,SAAO,SAAS;;;;;;;;CASpB,kBAAmB,KAAc,YAA0B;AACvD,MAAI,IAAI,QAAQ,OAAO,WAAW,CAAC;;;;;;;CAQvC,WAAY,KAAoC;AAC5C,SAAO,KAAK,QAAQ,WAAW,IAAI;;;;;;;;CASvC,gBAAiB,KAAc,YAA2B;AACtD,MAAI,IAAI,WAAW;;;;;;;;CASvB,qBAAsB,KAAoB;AACtC,MAAI,KAAK,QAAQ,aACb,KAAI,IAAI,KAAK,QAAQ,aAAoC;;;;;;;;CAUjE,MAAO,KAAc,MAAoB;AACrC,MAAI,OAAO,YAAY;AACnB,WAAQ,IAAI,yCAAyC,OAAO;IAC9D"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arkstack/driver-express",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Express driver package for Arkstack providing Express-specific implementations of core Arkstack features such as routing, middleware, and database integration.",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/arkstack-hq/arkstack.git",
|
|
9
|
+
"directory": "packages/driver-express"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"express",
|
|
13
|
+
"driver",
|
|
14
|
+
"integration",
|
|
15
|
+
"routing",
|
|
16
|
+
"middleware",
|
|
17
|
+
"database",
|
|
18
|
+
"arkstack",
|
|
19
|
+
"http",
|
|
20
|
+
"server",
|
|
21
|
+
"rest",
|
|
22
|
+
"api",
|
|
23
|
+
"framework"
|
|
24
|
+
],
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"stubs"
|
|
28
|
+
],
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"exports": {
|
|
33
|
+
".": "./dist/index.js",
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@arkstack/contract": "^0.1.1"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"express": "^5.2.1"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/express": "^5.0.6"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsdown",
|
|
47
|
+
"version:patch": "pnpm version patch --no-git-tag-version"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import BaseController from '@controllers/BaseController'
|
|
2
|
+
import { HttpContext } from 'clear-router/types/express'
|
|
3
|
+
import {{ResourceName}} from '@app/http/resources/{{ResourceName}}'
|
|
4
|
+
import {{CollectionResourceName}} from '@app/http/resources/{{CollectionResourceName}}'
|
|
5
|
+
|
|
6
|
+
import { Resource, ResourceCollection } from 'resora';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* {{ControllerName}}
|
|
10
|
+
*/
|
|
11
|
+
export default class extends BaseController {
|
|
12
|
+
/**
|
|
13
|
+
* Get all resources
|
|
14
|
+
*
|
|
15
|
+
* @param req
|
|
16
|
+
* @param res
|
|
17
|
+
*/
|
|
18
|
+
index = async ({ res }: HttpContext) => {
|
|
19
|
+
return await new ResourceCollection( { data: [] }, res)
|
|
20
|
+
.additional({
|
|
21
|
+
status: 'success',
|
|
22
|
+
message: 'OK',
|
|
23
|
+
code: 200,
|
|
24
|
+
})
|
|
25
|
+
.response()
|
|
26
|
+
.setStatusCode(200);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Get a specific resource
|
|
31
|
+
*
|
|
32
|
+
* @param req
|
|
33
|
+
* @param res
|
|
34
|
+
*/
|
|
35
|
+
show = async ({ res }: HttpContext) => {
|
|
36
|
+
return new Resource({ data: {} }, res)
|
|
37
|
+
.additional({
|
|
38
|
+
status: 'success',
|
|
39
|
+
message: 'OK',
|
|
40
|
+
code: 200,
|
|
41
|
+
})
|
|
42
|
+
.response()
|
|
43
|
+
.setStatusCode(200);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Create a resource
|
|
48
|
+
*
|
|
49
|
+
* @param req
|
|
50
|
+
* @param res
|
|
51
|
+
*/
|
|
52
|
+
create = async ({ res }: HttpContext) => {
|
|
53
|
+
return new Resource({ data: {} }, res)
|
|
54
|
+
.additional({
|
|
55
|
+
status: 'success',
|
|
56
|
+
message: 'New {{Name}} created successfully',
|
|
57
|
+
code: 201,
|
|
58
|
+
})
|
|
59
|
+
.response()
|
|
60
|
+
.setStatusCode(201);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Update a specific resource
|
|
65
|
+
*
|
|
66
|
+
* @param req
|
|
67
|
+
* @param res
|
|
68
|
+
*/
|
|
69
|
+
update = async ({ res }: HttpContext) => {
|
|
70
|
+
return new Resource({ data: {} }, res)
|
|
71
|
+
.additional({
|
|
72
|
+
status: 'success',
|
|
73
|
+
message: '{{Name}} updated successfully',
|
|
74
|
+
code: 202,
|
|
75
|
+
})
|
|
76
|
+
.response()
|
|
77
|
+
.setStatusCode(202);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Delete a specific resource
|
|
82
|
+
*
|
|
83
|
+
* @param req
|
|
84
|
+
* @param res
|
|
85
|
+
*/
|
|
86
|
+
destroy = async ({ res }: HttpContext) => {
|
|
87
|
+
return new Resource({ data: {} }, res)
|
|
88
|
+
.additional({
|
|
89
|
+
status: 'success',
|
|
90
|
+
message: '{{Name}} deleted successfully',
|
|
91
|
+
code: 202,
|
|
92
|
+
})
|
|
93
|
+
.response()
|
|
94
|
+
.setStatusCode(202);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import BaseController from '@controllers/BaseController';
|
|
2
|
+
import { HttpContext } from 'clear-router/types/express'
|
|
3
|
+
import { Resource, ResourceCollection } from "resora";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* {{ControllerName}}
|
|
7
|
+
*/
|
|
8
|
+
export default class extends BaseController {
|
|
9
|
+
/**
|
|
10
|
+
* Get all resources
|
|
11
|
+
*
|
|
12
|
+
* @param req
|
|
13
|
+
* @param res
|
|
14
|
+
*/
|
|
15
|
+
index = async ({ res }: HttpContext) => {
|
|
16
|
+
return new ResourceCollection({ data: [] }, res)
|
|
17
|
+
.additional({
|
|
18
|
+
status: "success",
|
|
19
|
+
message: "OK",
|
|
20
|
+
code: 200,
|
|
21
|
+
})
|
|
22
|
+
.response()
|
|
23
|
+
.setStatusCode(200);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Get a specific resource
|
|
28
|
+
*
|
|
29
|
+
* @param req
|
|
30
|
+
* @param res
|
|
31
|
+
*/
|
|
32
|
+
show = async ({ res }: HttpContext) => {
|
|
33
|
+
return new Resource({ data: {} }, res)
|
|
34
|
+
.additional({
|
|
35
|
+
status: "success",
|
|
36
|
+
message: "OK",
|
|
37
|
+
code: 200,
|
|
38
|
+
})
|
|
39
|
+
.response()
|
|
40
|
+
.setStatusCode(200);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Create a resource
|
|
45
|
+
*
|
|
46
|
+
* @param req
|
|
47
|
+
* @param res
|
|
48
|
+
*/
|
|
49
|
+
create = async ({ res }: HttpContext) => {
|
|
50
|
+
return new Resource({ data: {} }, res)
|
|
51
|
+
.additional({
|
|
52
|
+
status: "success",
|
|
53
|
+
message: "New {{Name}} created successfully",
|
|
54
|
+
code: 201,
|
|
55
|
+
})
|
|
56
|
+
.response()
|
|
57
|
+
.setStatusCode(201);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Update a specific resource
|
|
62
|
+
*
|
|
63
|
+
* @param req
|
|
64
|
+
* @param res
|
|
65
|
+
*/
|
|
66
|
+
update = async ({ res }: HttpContext) => {
|
|
67
|
+
return new Resource({ data: {} }, res)
|
|
68
|
+
.additional({
|
|
69
|
+
status: "success",
|
|
70
|
+
message: "{{Name}} updated successfully",
|
|
71
|
+
code: 202,
|
|
72
|
+
})
|
|
73
|
+
.response()
|
|
74
|
+
.setStatusCode(202);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Delete a specific resource
|
|
79
|
+
*
|
|
80
|
+
* @param res
|
|
81
|
+
*/
|
|
82
|
+
destroy = async ({ res }: HttpContext) => {
|
|
83
|
+
return new Resource({ data: {} }, res)
|
|
84
|
+
.additional({
|
|
85
|
+
status: "success",
|
|
86
|
+
message: "{{Name}} deleted successfully",
|
|
87
|
+
code: 202,
|
|
88
|
+
})
|
|
89
|
+
.response()
|
|
90
|
+
.setStatusCode(202);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import BaseController from '@controllers/BaseController';
|
|
2
|
+
import { HttpContext } from 'clear-router/types/express'
|
|
3
|
+
import { Resource, ResourceCollection } from "resora";
|
|
4
|
+
import { prisma } from '@core/DB';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* {{ControllerName}}
|
|
8
|
+
*/
|
|
9
|
+
export default class extends BaseController {
|
|
10
|
+
/**
|
|
11
|
+
* Get all resource from the database
|
|
12
|
+
*
|
|
13
|
+
* @param req
|
|
14
|
+
* @param res
|
|
15
|
+
*/
|
|
16
|
+
index = async ({ res }: HttpContext) => {
|
|
17
|
+
return new ResourceCollection({
|
|
18
|
+
data: await prisma.{{ModelName}}.findMany(
|
|
19
|
+
{ orderBy: { id: 'asc' } }
|
|
20
|
+
),
|
|
21
|
+
}, res)
|
|
22
|
+
.additional({
|
|
23
|
+
status: 'success',
|
|
24
|
+
message: 'OK',
|
|
25
|
+
code: 200,
|
|
26
|
+
})
|
|
27
|
+
.response()
|
|
28
|
+
.setStatusCode(200);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Get a specific resource from the database
|
|
33
|
+
*
|
|
34
|
+
* @param req
|
|
35
|
+
* @param res
|
|
36
|
+
*/
|
|
37
|
+
show = async ({ req, res }: HttpContext) => {
|
|
38
|
+
return new Resource({
|
|
39
|
+
data: await prisma.{{ModelName}}.findFirst(
|
|
40
|
+
{ where: { id: String(req.params.id) } }
|
|
41
|
+
),
|
|
42
|
+
}, res)
|
|
43
|
+
.additional({
|
|
44
|
+
status: 'success',
|
|
45
|
+
message: 'OK',
|
|
46
|
+
code: 200,
|
|
47
|
+
})
|
|
48
|
+
.response()
|
|
49
|
+
.setStatusCode(200);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Create a new resource in the database
|
|
54
|
+
*
|
|
55
|
+
* The calling route must recieve a multer.RequestHandler instance
|
|
56
|
+
*
|
|
57
|
+
* @example router.post('/{{ModelName}}s', upload.none(), new AdminController().create);
|
|
58
|
+
*
|
|
59
|
+
* @param req
|
|
60
|
+
* @param res
|
|
61
|
+
*/
|
|
62
|
+
create = async ({ req, res }: HttpContext) => {
|
|
63
|
+
const data = await prisma.{{ModelName}}.create({
|
|
64
|
+
data: req.body,
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
return new Resource({
|
|
68
|
+
data: data,
|
|
69
|
+
}, res)
|
|
70
|
+
.additional({
|
|
71
|
+
status: 'success',
|
|
72
|
+
message: 'New {{ModelName}} created successfully',
|
|
73
|
+
code: 201,
|
|
74
|
+
})
|
|
75
|
+
.response()
|
|
76
|
+
.setStatusCode(201);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Update a specific resource in the database
|
|
81
|
+
*
|
|
82
|
+
* @param req
|
|
83
|
+
* @param res
|
|
84
|
+
*/
|
|
85
|
+
update = async ({ req, res }: HttpContext) => {
|
|
86
|
+
const data = await prisma.{{ModelName}}.update({
|
|
87
|
+
where: { id: String(req.params.id) },
|
|
88
|
+
data: req.body(),
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
return new Resource({
|
|
92
|
+
data,
|
|
93
|
+
}, res)
|
|
94
|
+
.additional({
|
|
95
|
+
status: 'success',
|
|
96
|
+
message: '{{ModelName}} updated successfully',
|
|
97
|
+
code: 202,
|
|
98
|
+
})
|
|
99
|
+
.response()
|
|
100
|
+
.setStatusCode(202);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Delete a specific resource from the database
|
|
105
|
+
*
|
|
106
|
+
* @param req
|
|
107
|
+
* @param res
|
|
108
|
+
*/
|
|
109
|
+
destroy = async ({ req, res }: HttpContext) => {
|
|
110
|
+
await prisma.{{ModelName}}.delete(
|
|
111
|
+
{ where: { id: String(req.params.id) } }
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
return new Resource({
|
|
115
|
+
data: {},
|
|
116
|
+
}, res)
|
|
117
|
+
.additional({
|
|
118
|
+
status: 'success',
|
|
119
|
+
message: '{{ModelName}} deleted successfully',
|
|
120
|
+
code: 202,
|
|
121
|
+
})
|
|
122
|
+
.response()
|
|
123
|
+
.setStatusCode(202);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import BaseController from '@controllers/BaseController';
|
|
2
|
+
import { HttpContext } from 'clear-router/types/express'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* {{ControllerName}}
|
|
6
|
+
*/
|
|
7
|
+
export default class extends BaseController {
|
|
8
|
+
index = async ({ res }: HttpContext) => {
|
|
9
|
+
res.send('<p>Hello!</p>')
|
|
10
|
+
}
|
|
11
|
+
}
|