ToolJet/server/src/controllers/apps.controller.ts

46 lines
1 KiB
TypeScript
Raw Normal View History

2021-07-10 14:07:47 +00:00
import { Controller, Get, Post, Query, Request, UseGuards } from '@nestjs/common';
import { JwtAuthGuard } from 'src/modules/auth/jwt-auth.guard';
2021-07-11 05:41:45 +00:00
import { AppsService } from '../services/apps.service';
2021-07-10 13:54:32 +00:00
import { decamelizeKeys } from 'humps';
@Controller('apps')
export class AppsController {
constructor(
private appsService: AppsService
) { }
2021-07-10 14:07:47 +00:00
@UseGuards(JwtAuthGuard)
@Post()
async create(@Request() req) {
const params = req.body;
const app = await this.appsService.create(req.user);
return decamelizeKeys(app);
}
2021-07-10 13:54:32 +00:00
@UseGuards(JwtAuthGuard)
@Get()
async index(@Request() req, @Query() query) {
const page = req.query.page;
const apps = await this.appsService.all(req.user, page);
const totalCount = await this.appsService.count(req.user);
const meta = {
total_pages: Math.round(totalCount/10),
total_count: totalCount,
current_page: page || 0
}
const response = {
meta,
apps
}
return decamelizeKeys(response);
}
}