Skip to content
This repository was archived by the owner on Jun 16, 2021. It is now read-only.

Sample upload #13

Merged
merged 5 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 69 additions & 27 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@
"apps/sample-platform/tsconfig.app.json",
"apps/sample-platform/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**",
"!apps/sample-platform/**"
]
"exclude": ["**/node_modules/**", "!apps/sample-platform/**"]
}
},
"test": {
Expand Down Expand Up @@ -122,13 +119,8 @@
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"apps/sample-platform-e2e/tsconfig.e2e.json"
],
"exclude": [
"**/node_modules/**",
"!apps/sample-platform-e2e/**"
]
"tsConfig": ["apps/sample-platform-e2e/tsconfig.e2e.json"],
"exclude": ["**/node_modules/**", "!apps/sample-platform-e2e/**"]
}
}
}
Expand All @@ -146,9 +138,7 @@
"outputPath": "dist/apps/api",
"main": "apps/api/src/main.ts",
"tsConfig": "apps/api/tsconfig.app.json",
"assets": [
"apps/api/src/assets"
]
"assets": ["apps/api/src/assets"]
},
"configurations": {
"production": {
Expand Down Expand Up @@ -177,10 +167,7 @@
"apps/api/tsconfig.app.json",
"apps/api/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**",
"!apps/api/**"
]
"exclude": ["**/node_modules/**", "!apps/api/**"]
}
},
"test": {
Expand Down Expand Up @@ -320,10 +307,7 @@
"libs/testing/tsconfig.lib.json",
"libs/testing/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**",
"!libs/testing/**"
]
"exclude": ["**/node_modules/**", "!libs/testing/**"]
}
},
"test": {
Expand Down Expand Up @@ -380,10 +364,7 @@
"libs/api-implementation/xml/tsconfig.lib.json",
"libs/api-implementation/xml/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**",
"!libs/api-implementation/xml/**"
]
"exclude": ["**/node_modules/**", "!libs/api-implementation/xml/**"]
}
},
"test": {
Expand Down Expand Up @@ -488,6 +469,67 @@
"style": "scss"
}
}
},
"api-implementation-samples": {
"root": "libs/api-implementation/samples",
"sourceRoot": "libs/api-implementation/samples/src",
"projectType": "library",
"schematics": {},
"architect": {
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"libs/api-implementation/samples/tsconfig.lib.json",
"libs/api-implementation/samples/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**",
"!libs/api-implementation/samples/**"
]
}
},
"test": {
"builder": "@nrwl/jest:jest",
"options": {
"jestConfig": "libs/api-implementation/samples/jest.config.js",
"tsConfig": "libs/api-implementation/samples/tsconfig.spec.json",
"passWithNoTests": true
}
}
}
},
"frontend-samples": {
"projectType": "library",
"root": "libs/frontend/samples",
"sourceRoot": "libs/frontend/samples/src",
"prefix": "new-sample-platform",
"architect": {
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"libs/frontend/samples/tsconfig.lib.json",
"libs/frontend/samples/tsconfig.spec.json"
],
"exclude": ["**/node_modules/**", "!libs/frontend/samples/**"]
}
},
"test": {
"builder": "@nrwl/jest:jest",
"options": {
"jestConfig": "libs/frontend/samples/jest.config.js",
"tsConfig": "libs/frontend/samples/tsconfig.spec.json",
"passWithNoTests": true,
"setupFile": "libs/frontend/samples/src/test-setup.ts"
}
}
},
"schematics": {
"@nrwl/angular:component": {
"style": "scss"
}
}
}
},
"cli": {
Expand All @@ -504,4 +546,4 @@
}
},
"defaultProject": "sample-platform"
}
}
12 changes: 9 additions & 3 deletions apps/api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ import { Module } from '@nestjs/common';

import { AppController } from './app.controller';
import { VMOrchestrationModule } from '../../../../libs/api-implementation/orchestration/src';
import { ApiImplementationRegressionTestsModule } from '../../../../libs/api-implementation/regression-tests/src'
import { ApiImplementationDatabaseModule } from '../../../../libs/api-implementation/database/src'
import { ApiImplementationRegressionTestsModule } from '@new-sample-platform/api-implementation/regression-tests';
import { ApiImplementationDatabaseModule } from '@new-sample-platform/api-implementation/database';
import { ApiImplementationSamplesModule } from '@new-sample-platform/api-implementation/samples'

@Module({
imports: [VMOrchestrationModule, ApiImplementationRegressionTestsModule, ApiImplementationDatabaseModule],
imports: [
VMOrchestrationModule,
ApiImplementationRegressionTestsModule,
ApiImplementationDatabaseModule,
ApiImplementationSamplesModule
],
controllers: [AppController],
providers: [],
})
Expand Down
10 changes: 6 additions & 4 deletions apps/sample-platform/proxy.conf.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"/api": {
"target": "http://localhost:3333",
"secure": false
"/api/*": {
"target": "http://localhost:3333",
"secure": false,
"changeOrigin": true,
"logLevel": "debug"
}
}
}
2 changes: 2 additions & 0 deletions apps/sample-platform/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { FlexLayoutModule } from '@angular/flex-layout';
import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http';
import { RoutingModule } from './routing.module';
Expand All @@ -15,6 +16,7 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
@NgModule({
declarations: [AppComponent],
imports: [
FlexLayoutModule,
BrowserModule,
HttpClientModule,
RoutingModule,
Expand Down
7 changes: 7 additions & 0 deletions apps/sample-platform/src/app/routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ const routes: Routes = [
(mod) => mod.FrontendRegressionTestModule
)
},
{
path: 'samples',
loadChildren: () =>
import('@new-sample-platform/frontend/samples').then(
(mod) => mod.FrontendSamplesModule
)
}
];

@NgModule({
Expand Down
3 changes: 2 additions & 1 deletion config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export enum AppConfig {
GITHUB_API_LINK = "https://api.github.com/",
CCEXTRACTOR_REPO_NAME = "ccextractor",
CCEXTRACTOR_REPO_OWNER = "zelzhan",
MONGO_CONNECTION_STRING = "mongodb://mongo:27017/test"
MONGO_CONNECTION_STRING = "mongodb://mongo:27017/test",
PATH_TO_MOUNTED_BUCKET = "/path/to/bucket/"
}
7 changes: 7 additions & 0 deletions libs/api-implementation/samples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# api-implementation-samples

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `ng test api-implementation-samples` to execute the unit tests via [Jest](https://jestjs.io).
10 changes: 10 additions & 0 deletions libs/api-implementation/samples/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
name: 'api-implementation-samples',
preset: '../../../jest.config.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]sx?$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
coverageDirectory: '../../../coverage/libs/api-implementation/samples',
};
1 change: 1 addition & 0 deletions libs/api-implementation/samples/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/api-implementation-samples.module';
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';

import { SamplesController } from './samples.controller'
import { SamplesService } from './services/samples.service';

@Module({
controllers: [SamplesController],
providers: [SamplesService],
exports: [],
})
export class ApiImplementationSamplesModule {}
24 changes: 24 additions & 0 deletions libs/api-implementation/samples/src/lib/samples.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {
Controller,
Post,
UseInterceptors,
UploadedFile,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { SamplesService } from './services/samples.service';

@Controller('samples')
export class SamplesController {
constructor(private service: SamplesService) {}

@Post('upload')
@UseInterceptors(FileInterceptor('file'))
uploadFile(@UploadedFile() file) {
try {
this.service.writeToBucket(file);
} catch (error) {
return 'Error while writing the file to the bucket'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this handle sending appropriate error code as well?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zelzhan Can you please address my doubt here?

}
return 200
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Injectable } from '@nestjs/common';
import { writeFileSync } from 'fs';
import { AppConfig } from '../../../../../../config';
@Injectable()
export class SamplesService {
async writeToBucket(file) {
try {
writeFileSync(
AppConfig.PATH_TO_MOUNTED_BUCKET + file.originalname,
file.buffer
);
} catch (error) {
console.error(`Error occured while writing the file to the bucket`);
console.debug(error.stack);
throw error;
}
}
}
8 changes: 8 additions & 0 deletions libs/api-implementation/samples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"types": ["node", "jest"],
"target": "es6"
},
"include": ["**/*.ts"]
}
12 changes: 12 additions & 0 deletions libs/api-implementation/samples/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../../../dist/out-tsc",
"declaration": true,
"rootDir": "./src",
"types": ["node"]
},
"exclude": ["**/*.spec.ts"],
"include": ["**/*.ts"]
}
15 changes: 15 additions & 0 deletions libs/api-implementation/samples/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"**/*.spec.ts",
"**/*.spec.tsx",
"**/*.spec.js",
"**/*.spec.jsx",
"**/*.d.ts"
]
}
5 changes: 5 additions & 0 deletions libs/api-implementation/samples/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../../tslint.json",
"linterOptions": { "exclude": ["!**/*"] },
"rules": {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export class ListRegressionTestsComponent implements OnInit {
this.getData().subscribe((data: any) => {
this.dataSource = data
})
console.log(this.dataSource)
}

ngOnInit(): void { }
Expand Down
7 changes: 7 additions & 0 deletions libs/frontend/samples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frontend-samples

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test frontend-samples` to execute the unit tests.
10 changes: 10 additions & 0 deletions libs/frontend/samples/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
name: 'frontend-samples',
preset: '../../../jest.config.js',
coverageDirectory: '../../../coverage/libs/frontend/samples',
snapshotSerializers: [
'jest-preset-angular/build/AngularNoNgAttributesSnapshotSerializer.js',
'jest-preset-angular/build/AngularSnapshotSerializer.js',
'jest-preset-angular/build/HTMLCommentSerializer.js',
],
};
1 change: 1 addition & 0 deletions libs/frontend/samples/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/frontend-samples.module';
Loading