-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
54 lines (44 loc) · 1.11 KB
/
index.ts
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { Body, Controller, Get, Injectable, Module, Param, Post, createApp } from './lib';
class LoginDto {
username: string;
password: string;
}
@Injectable()
class UserRepository {
async findOne(id: string) {
return { userId: id };
}
}
@Injectable()
class AuthService {
constructor(private readonly userRepository: UserRepository) {}
async login({ username }: LoginDto) {
return `login successful for ${username}`;
}
async findUser(id: string) {
return this.userRepository.findOne(id);
}
}
@Controller('auth')
class AuthController {
constructor(private readonly authService: AuthService) {}
@Post('/login')
login(@Body() loginData: LoginDto) {
console.log({ loginData });
return this.authService.login(loginData);
}
@Get('/profile/:id')
async profile(@Param('id') id: string) {
const user = await this.authService.findUser(id);
return `user: ${user.userId}`;
}
}
@Module({
controllers: [AuthController],
providers: [AuthService],
})
class AppModule {}
const app = createApp(AppModule);
app.listen(3001, () => {
console.log('listening on port 3001');
});