Skip to content

Commit 587bde2

Browse files
committed
Octokit service add
1 parent 0f20e32 commit 587bde2

29 files changed

Lines changed: 856 additions & 45 deletions

package-lock.json

Lines changed: 164 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@
1414
"devDependencies": {
1515
"@types/cors": "^2.8.12",
1616
"@types/express": "^4.17.13",
17+
"@types/swagger-ui-express": "^4.1.3",
1718
"ts-node": "^10.9.1",
1819
"ts-node-dev": "^2.0.0",
1920
"typescript": "^4.7.4"
2021
},
2122
"dependencies": {
23+
"@octokit/request-error": "^3.0.1",
2224
"app-root-path": "^3.1.0",
25+
"axios": "^0.27.2",
2326
"cors": "^2.8.5",
2427
"dotenv": "^16.0.1",
2528
"express": "^4.18.1",
26-
"octokit": "^2.0.7"
29+
"octokit": "^2.0.7",
30+
"swagger-ui-express": "^4.5.0"
2731
}
2832
}

src/controllers/auth.controller.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Request } from 'express';
2+
import { BaseHttpController, controller, httpPost, request } from 'inversify-express-utils';
3+
import { ErrorCode } from '../errors/codes';
4+
import { LogicError } from '../errors/logic.error';
5+
import { OctokitService } from '../services/octokit.service';
6+
7+
@controller('/auth')
8+
export class AuthController extends BaseHttpController {
9+
constructor(private octokitService: OctokitService) {
10+
super();
11+
}
12+
13+
@httpPost('/')
14+
async auth(@request() req: Request) {
15+
<<<<<<< HEAD
16+
const { code }: { code: string } = req.body;
17+
=======
18+
const { code } = req.body as { code: string };
19+
>>>>>>> 65814b5 (Dependency Injection support add)
20+
if (!code) {
21+
throw new LogicError(ErrorCode.AuthNo);
22+
}
23+
24+
const response = await this.octokitService.getTokenByCode(code);
25+
if (typeof response === 'string') {
26+
throw new LogicError(ErrorCode.AuthExpired, response);
27+
}
28+
29+
<<<<<<< HEAD
30+
this.json({ accessToken: response }, 200);
31+
=======
32+
return this.json({ accessToken: response }, 200);
33+
>>>>>>> 65814b5 (Dependency Injection support add)
34+
}
35+
}

0 commit comments

Comments
 (0)