2023-07-11 04:40:03 +00:00
|
|
|
import { Controller, Get, Query, UseGuards } from '@nestjs/common';
|
2023-04-06 12:22:28 +00:00
|
|
|
import { decamelizeKeys } from 'humps';
|
|
|
|
|
import { JwtAuthGuard } from '../modules/auth/jwt-auth.guard';
|
|
|
|
|
import { ForbiddenException } from '@nestjs/common';
|
|
|
|
|
import { User } from 'src/decorators/user.decorator';
|
|
|
|
|
import { AppEnvironmentService } from '@services/app_environments.service';
|
|
|
|
|
import { GlobalDataSourceAbilityFactory } from 'src/modules/casl/abilities/global-datasource-ability.factory';
|
|
|
|
|
import { DataSource } from 'src/entities/data_source.entity';
|
|
|
|
|
|
|
|
|
|
@Controller('app-environments')
|
|
|
|
|
export class AppEnvironmentsController {
|
|
|
|
|
constructor(
|
|
|
|
|
private appEnvironmentServices: AppEnvironmentService,
|
|
|
|
|
private globalDataSourcesAbilityFactory: GlobalDataSourceAbilityFactory
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
|
|
|
@Get()
|
2023-07-11 04:40:03 +00:00
|
|
|
async index(@User() user, @Query('app_id') appId: string) {
|
2023-04-06 12:22:28 +00:00
|
|
|
const ability = await this.globalDataSourcesAbilityFactory.globalDataSourceActions(user);
|
|
|
|
|
const { organizationId } = user;
|
|
|
|
|
|
|
|
|
|
if (!ability.can('fetchEnvironments', DataSource)) {
|
|
|
|
|
throw new ForbiddenException('You do not have permissions to perform this action');
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-11 04:40:03 +00:00
|
|
|
const environments = await this.appEnvironmentServices.getAll(organizationId, null, appId);
|
2023-04-06 12:22:28 +00:00
|
|
|
return decamelizeKeys({ environments });
|
|
|
|
|
}
|
2023-07-11 04:40:03 +00:00
|
|
|
|
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
|
|
|
@Get('versions')
|
|
|
|
|
async getVersions(@User() user, @Query('app_id') appId: string) {
|
|
|
|
|
const appVersions = await this.appEnvironmentServices.getVersionsByEnvironment(user?.organizationId, appId);
|
2023-07-24 11:05:09 +00:00
|
|
|
return { appVersions };
|
2023-07-11 04:40:03 +00:00
|
|
|
}
|
2023-04-06 12:22:28 +00:00
|
|
|
}
|