mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 09:28:31 +00:00
57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
import { Controller, Get, Param, Post, Query, Request, UseGuards } from '@nestjs/common';
|
|
import { JwtAuthGuard } from 'src/modules/auth/jwt-auth.guard';
|
|
import { AppsService } from '../services/apps.service';
|
|
import { decamelizeKeys } from 'humps';
|
|
|
|
@Controller('apps')
|
|
export class AppsController {
|
|
|
|
constructor(
|
|
private appsService: AppsService
|
|
) { }
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
@Post()
|
|
async create(@Request() req) {
|
|
const params = req.body;
|
|
|
|
const app = await this.appsService.create(req.user);
|
|
return decamelizeKeys(app);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
@Get(':id')
|
|
async show(@Request() req, @Param() params) {
|
|
|
|
const app = await this.appsService.find(params.id);
|
|
let response = decamelizeKeys(app);
|
|
|
|
response['definition'] = app['definition'];
|
|
|
|
return response;
|
|
}
|
|
|
|
@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: parseInt(page || 0)
|
|
}
|
|
|
|
const response = {
|
|
meta,
|
|
apps
|
|
}
|
|
|
|
return decamelizeKeys(response);
|
|
}
|
|
|
|
}
|