2021-07-12 14:12:34 +00:00
|
|
|
import { Controller, Get, Param, Post, Patch, Query, Request, UseGuards } from '@nestjs/common';
|
2021-07-14 14:14:35 +00:00
|
|
|
import { JwtAuthGuard } from '../../src/modules/auth/jwt-auth.guard';
|
2021-07-11 08:32:06 +00:00
|
|
|
import { decamelizeKeys } from 'humps';
|
2021-07-14 14:14:35 +00:00
|
|
|
import { DataQueriesService } from '../../src/services/data_queries.service';
|
2021-07-11 08:32:06 +00:00
|
|
|
|
|
|
|
|
@Controller('data_queries')
|
|
|
|
|
export class DataQueriesController {
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private dataQueriesService: DataQueriesService
|
|
|
|
|
) { }
|
|
|
|
|
|
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
|
|
|
@Get()
|
|
|
|
|
async index(@Request() req, @Query() query) {
|
|
|
|
|
|
|
|
|
|
const queries = await this.dataQueriesService.all(req.user, query.app_id);
|
|
|
|
|
let response = decamelizeKeys({ data_queries: queries });
|
|
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-12 14:12:34 +00:00
|
|
|
@UseGuards(JwtAuthGuard)
|
|
|
|
|
@Post()
|
|
|
|
|
async create(@Request() req) {
|
|
|
|
|
const { kind, name, options } = req.body;
|
|
|
|
|
const appId = req.body.app_id;
|
|
|
|
|
const dataSourceId = req.body.data_source_id;
|
|
|
|
|
|
|
|
|
|
const dataQuery = await this.dataQueriesService.create(req.user, name, kind, options, appId, dataSourceId);
|
|
|
|
|
return decamelizeKeys(dataQuery);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
|
|
|
@Patch(':id')
|
|
|
|
|
async update(@Request() req, @Param() params) {
|
|
|
|
|
const { name, options } = req.body;
|
|
|
|
|
const dataQueryId = params.id;
|
|
|
|
|
|
|
|
|
|
const dataQuery = await this.dataQueriesService.update(req.user, dataQueryId, name, options);
|
|
|
|
|
return decamelizeKeys(dataQuery);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-14 14:14:35 +00:00
|
|
|
@UseGuards(JwtAuthGuard)
|
|
|
|
|
@Post(':id/run')
|
|
|
|
|
async runQuery(@Request() req, @Param() params) {
|
|
|
|
|
const dataQueryId = params.id;
|
|
|
|
|
const { options } = req.body;
|
|
|
|
|
|
|
|
|
|
const result = await this.dataQueriesService.runQuery(req.user, dataQueryId, options);
|
|
|
|
|
return decamelizeKeys(result);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-11 08:32:06 +00:00
|
|
|
}
|