Skip to content

Commit 86e819d

Browse files
committed
chore: update example.
1 parent dad5457 commit 86e819d

File tree

15 files changed

+107
-266
lines changed

15 files changed

+107
-266
lines changed

.gitignore

Lines changed: 8 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,20 @@
1-
# Created by https://www.gitignore.io/api/node
2-
# Edit at https://www.gitignore.io/?templates=node
3-
4-
lib
5-
package-lock.json
61
__snapshots__
7-
8-
### Node ###
9-
# Logs
10-
logs
11-
*.log
12-
npm-debug.log*
13-
yarn-debug.log*
14-
yarn-error.log*
15-
lerna-debug.log*
16-
17-
# Diagnostic reports (https://nodejs.org/api/report.html)
18-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
19-
20-
# Runtime data
21-
pids
22-
*.pid
23-
*.seed
24-
*.pid.lock
25-
26-
# Directory for instrumented libs generated by jscoverage/JSCover
27-
lib-cov
28-
29-
# Coverage directory used by tools like istanbul
2+
lib
3+
dist
304
coverage
31-
32-
# nyc test coverage
33-
.nyc_output
34-
35-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
36-
.grunt
37-
38-
# Bower dependency directory (https://bower.io/)
39-
bower_components
40-
41-
# node-waf configuration
42-
.lock-wscript
43-
44-
# Compiled binary addons (https://nodejs.org/api/addons.html)
45-
build/Release
46-
47-
# Dependency directories
48-
node_modules/
49-
jspm_packages/
50-
51-
# TypeScript v1 declaration files
52-
typings/
53-
54-
# Optional npm cache directory
55-
.npm
56-
57-
# Optional eslint cache
58-
.eslintcache
59-
60-
# Optional REPL history
61-
.node_repl_history
62-
63-
# Output of 'npm pack'
64-
*.tgz
65-
66-
# Yarn Integrity file
67-
.yarn-integrity
68-
69-
# dotenv environment variables file
70-
.env
71-
.env.test
72-
73-
# parcel-bundler cache (https://parceljs.org/)
74-
.cache
75-
76-
# next.js build output
77-
.next
78-
79-
# nuxt.js build output
80-
.nuxt
81-
82-
# vuepress build output
83-
.vuepress/dist
84-
85-
# Serverless directories
86-
.serverless/
87-
88-
# FuseBox cache
89-
.fusebox/
90-
91-
# DynamoDB Local files
92-
.dynamodb/
93-
94-
# End of https://www.gitignore.io/api/node
5+
node_modules
6+
npm-debug.log*
7+
lerna-debug.log
8+
yarn-error.log
9+
package-lock.json
9510

9611
.DS_Store
9712
.cache
9813
.vscode
9914
.idea
10015
.env
10116

17+
*.mpassword
10218
*.bak
10319
*.tem
10420
*.temp

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
Basic Example
2-
---
2+
===
33

4-
Use Express and TypeORM with TypeScript
4+
[TypeNexus](https://www.npmjs.com/package/typenexus) is a great tool for API encapsulation and management. It offers a clean and lightweight way to bundle [TypeORM](https://github.com/typeorm/typeorm) + [Express.js](https://github.com/expressjs/express) functionality, helping you to build applications faster while reducing template code redundancy and type conversion work.
55

66
```bash
77
npm run watch # Listen compile .ts files.
88
npm run build # compile .ts files.
99

10+
npm run dev
1011
npm run start
1112
```

ormconfig.json

Lines changed: 0 additions & 24 deletions
This file was deleted.

package.json

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,37 @@
11
{
2-
"name": "express-typeorm",
2+
"name": "@template/typenexus",
3+
"private": true,
4+
"type": "module",
35
"version": "1.0.0",
4-
"description": "Express TypeORM Example.",
6+
"description": "TypeNexus Example.",
57
"scripts": {
6-
"prepare": "npm run build",
7-
"init": "typeorm migration:create -n Init",
8-
"run": "typeorm migration:run",
9-
"start": "node lib/app.js",
10-
"watch": "npm run watch:ts",
11-
"watch:ts": "tsbb watch & npm run build:types -- --watch",
12-
"build": "npm run build:ts && npm run build:types",
13-
"build:ts": "tsbb build",
14-
"build:types": "tsbb types",
8+
"start": "npm run build && node dist/main.js",
9+
"dev": "nodemon --inspect dist/main.js",
10+
"watch": "tsbb watch",
11+
"build": "tsbb build --bail",
1512
"test": "tsbb test",
16-
"coverage": "tsbb test --coverage"
13+
"coverage": "tsbb test --coverage --bail"
1714
},
1815
"repository": {
1916
"type": "git",
20-
"url": "https://github.com/jaywcjlove/tsbb/tree/master/example/basic"
17+
"url": "https://github.com/jaywcjlove/tsbb/tree/master/example/typenexus"
18+
},
19+
"jest": {
20+
"transformIgnorePatterns": [
21+
"<rootDir>/node_modules/?!(.*)"
22+
]
2123
},
22-
"jest": {},
2324
"keywords": [],
2425
"license": "MIT",
25-
"devDependencies": {
26-
"@types/fs-extra": "^8.0.1",
27-
"tsbb": "^1.4.0"
28-
},
29-
"author": "",
3026
"dependencies": {
31-
"@types/body-parser": "^1.17.1",
32-
"@types/express": "^4.17.2",
33-
"@types/node": "^13.1.2",
34-
"body-parser": "^1.19.0",
35-
"express": "^4.17.1",
36-
"fs-extra": "^8.1.0",
37-
"mysql": "^2.17.1",
38-
"typeorm": "^0.2.22"
27+
"typenexus": "0.3.1"
28+
},
29+
"devDependencies": {
30+
"@types/supertest": "~2.0.12",
31+
"nodemon": "^2.0.20",
32+
"supertest": "^6.3.3",
33+
"supertest-session": "^4.1.0",
34+
"ts-node": "^10.9.1",
35+
"tsbb": "4.1.1"
3936
}
4037
}

src/UserController.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Controller, Get, Authorized } from 'typenexus';
2+
3+
@Controller('/questions')
4+
export class UserController {
5+
@Authorized()
6+
@Get()
7+
public async all(): Promise<any> {
8+
return {
9+
id: 1,
10+
title: 'Question #1',
11+
};
12+
}
13+
}

src/app.ts

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/controller/login.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/entity/User.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/main.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { TypeNexus, Action } from 'typenexus';
2+
import { UserController } from './UserController.js';
3+
4+
(async () => {
5+
const app = new TypeNexus(3002, {
6+
developmentMode: false,
7+
});
8+
9+
app.authorizationChecker = async (action: Action, roles: string[]) => {
10+
return false;
11+
};
12+
13+
app.controllers([UserController]);
14+
await app.start();
15+
})();

src/migration/.gitkeep

Whitespace-only changes.

src/routes.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/subscriber/.gitkeep

Whitespace-only changes.

src/utils/getORMConf.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

test/main.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { TypeNexus, Action } from 'typenexus';
2+
import supertest from 'supertest';
3+
import { UserController } from '../src/UserController';
4+
5+
describe('API request test case', () => {
6+
let app: TypeNexus
7+
beforeAll(() => {
8+
app = new TypeNexus(3002, {
9+
routePrefix: '/api',
10+
developmentMode: false,
11+
});
12+
13+
app.authorizationChecker = async (action: Action, roles: string[]) => {
14+
return false;
15+
}
16+
})
17+
18+
test('GET /api/questions', async () => {
19+
app.controllers([UserController]);
20+
let result = await supertest.agent(app.app)
21+
.get('/api/questions')
22+
.set('Accept', 'application/json')
23+
.set('Content-Type', 'application/json')
24+
.expect('Content-Type', /json/)
25+
.expect(401)
26+
expect(result.body.name).toEqual('AuthorizationRequiredError');
27+
expect(Object.keys(result.body)).toEqual([ 'name', 'message' ]);
28+
});
29+
});

0 commit comments

Comments
 (0)