2022-05-05 07:08:42 +00:00
|
|
|
import { Controller, Post, UseGuards, Get, ForbiddenException, Body } from '@nestjs/common';
|
2021-12-07 13:25:41 +00:00
|
|
|
import { LibraryAppCreationService } from '@services/library_app_creation.service';
|
2022-05-05 07:08:42 +00:00
|
|
|
import { User } from 'src/decorators/user.decorator';
|
2021-12-07 13:25:41 +00:00
|
|
|
import { App } from 'src/entities/app.entity';
|
|
|
|
|
import { AppsAbilityFactory } from 'src/modules/casl/abilities/apps-ability.factory';
|
|
|
|
|
import { JwtAuthGuard } from '../../src/modules/auth/jwt-auth.guard';
|
|
|
|
|
import { TemplateAppManifests } from '../../templates';
|
|
|
|
|
|
|
|
|
|
@Controller('library_apps')
|
|
|
|
|
export class LibraryAppsController {
|
|
|
|
|
constructor(
|
|
|
|
|
private libraryAppCreationService: LibraryAppCreationService,
|
|
|
|
|
private appsAbilityFactory: AppsAbilityFactory
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
@Post()
|
|
|
|
|
@UseGuards(JwtAuthGuard)
|
2022-05-05 07:08:42 +00:00
|
|
|
async create(@User() user, @Body('identifier') identifier) {
|
|
|
|
|
const ability = await this.appsAbilityFactory.appsActions(user);
|
2021-12-07 13:25:41 +00:00
|
|
|
|
|
|
|
|
if (!ability.can('createApp', App)) {
|
|
|
|
|
throw new ForbiddenException('You do not have permissions to perform this action');
|
|
|
|
|
}
|
2023-10-12 06:26:29 +00:00
|
|
|
const result = await this.libraryAppCreationService.perform(user, identifier);
|
|
|
|
|
return result;
|
2021-12-07 13:25:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get()
|
|
|
|
|
@UseGuards(JwtAuthGuard)
|
2022-05-05 07:08:42 +00:00
|
|
|
async index() {
|
2021-12-07 13:25:41 +00:00
|
|
|
return { template_app_manifests: TemplateAppManifests };
|
|
|
|
|
}
|
|
|
|
|
}
|