2021-07-10 14:07:47 +00:00
|
|
|
import { Controller, Get, Post, Query, Request, UseGuards } from '@nestjs/common';
|
2021-07-11 05:39:55 +00:00
|
|
|
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,
|
2021-07-11 05:53:05 +00:00
|
|
|
current_page: parseInt(page || 0)
|
2021-07-10 13:54:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const response = {
|
|
|
|
|
meta,
|
|
|
|
|
apps
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return decamelizeKeys(response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|