ToolJet/server/src/services/library_app_creation.service.ts
Akshay 5b30aa2007
Chore: Setup pipeline (#1539)
* github actions for PR and push to develop branch

* test workflow

* move to workflows folder

* add setup node action

* modify build

* specify npm version

* config unit test

* specify host postgres

* specify container to run on

* add postgresql dependency

* add specify ws adapter for test

* add e2e test

* fix linting

* only log errors on tests

* update eslint config

* fix linting

* run e2e test in silent mode

* fix library app spec

* dont send email on test env

* fix org scope

* mock env vars

* remove reset modules

* force colors

* explicitly close db connection

* add eslint rule for floating promises

* update workflow

* fix floating promise

* fix lint

* update workflow

* run on all push and pulls

* update lint check files

* simplify workflow

* increase js heap size on env

* separate lint and build

Co-authored-by: arpitnath <arpitnath42@gmail.com>
2021-12-10 08:43:05 +05:30

30 lines
1,019 B
TypeScript

import { BadRequestException, Injectable } from '@nestjs/common';
import { App } from '../entities/app.entity';
import { User } from '../entities/user.entity';
import { AppImportExportService } from './app_import_export.service';
import { readFileSync } from 'fs';
import { Logger } from 'nestjs-pino';
@Injectable()
export class LibraryAppCreationService {
constructor(private readonly appImportExportService: AppImportExportService, private readonly logger: Logger) {}
async perform(currentUser: User, identifier: string): Promise<App> {
const newApp = await this.appImportExportService.import(currentUser, this.findAppDefinition(identifier));
return newApp;
}
findAppDefinition(identifier: string) {
let appDefinition: object;
try {
appDefinition = JSON.parse(readFileSync(`templates/${identifier}/definition.json`, 'utf-8'));
} catch (err) {
this.logger.error(err);
throw new BadRequestException('App definition not found');
}
return appDefinition;
}
}