-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.controller.ts
52 lines (46 loc) · 1.45 KB
/
app.controller.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
import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common';
import { AppService } from './app.service';
import { HttpService } from '@nestjs/axios';
import { firstValueFrom } from 'rxjs';
import { AuthGuard } from '@nestjs/passport';
import { JwtUser } from './jwt-user.decorator';
@Controller()
export class AppController {
constructor(
private readonly appService: AppService,
private readonly httpService: HttpService,
) {}
@Get('apps')
listApps() {
return this.appService.listApps();
}
@UseGuards(AuthGuard('jwt'))
@Post('sharedDBUpsert')
upsertSharedDb(@Body() body: { appId: string; key: string; value: any }) {
console.log('dfdfdfd');
this.appService.saveSharedDb(body.appId, body.key, body.value);
}
@UseGuards(AuthGuard('jwt'))
@Post('sharedDBList')
listSharedDb(@Body() body: { appId: string }) {
return this.appService.listSharedDb(body.appId);
}
@UseGuards(AuthGuard('jwt'))
@Get('user')
async getUser(@JwtUser() u: { userId: string }) {
const userId = u.userId;
const user = await firstValueFrom(
this.httpService.get(`http://localhost:3000/userdev/${userId}`),
);
return user.data;
}
@UseGuards(AuthGuard('jwt'))
@Get('account')
async getAccount(@JwtUser() u: { userId: string }) {
const userId = u.userId;
const account = await firstValueFrom(
this.httpService.get(`http://localhost:3000/accountdev/${userId}`),
);
return account.data;
}
}