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

Report handler #31

Merged
merged 15 commits into from
Sep 27, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat(api): adjustment of samples model in respect to the test-entry l…
…ibrary
zelzhan committed Aug 25, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 39df40d3f8f3398536cb29c9edc0a5dfac34718c
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Module } from '@nestjs/common';

import { SamplesController } from './samples.controller'
import { SamplesController } from './samples.controller';
import { SamplesService } from './services/samples.service';
import { ApiImplementationDatabaseModule } from '@new-sample-platform/api-implementation/database';

@Module({
imports: [ApiImplementationDatabaseModule],
controllers: [SamplesController],
providers: [SamplesService],
exports: [],
14 changes: 12 additions & 2 deletions libs/api-implementation/samples/src/lib/samples.controller.ts
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import {
Post,
UseInterceptors,
UploadedFile,
Get,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { SamplesService } from './services/samples.service';
@@ -17,8 +18,17 @@ export class SamplesController {
try {
this.service.writeToBucket(file);
} catch (error) {
return 'Error while writing the file to the bucket'
return 'Error while writing the file to the bucket';
}
return 200;
}

@Get()
getAllSampleNames() {
try {
return this.service.getAllSampleNames();
} catch (error) {
return 'Error while fetching sample names';
}
return 200
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Injectable } from '@nestjs/common';
import { writeFileSync } from 'fs';
import { AppConfig } from '../../../../../../config';
import { SampleModel } from '../../../../models/samples/sample.models';

@Injectable()
export class SamplesService {
async writeToBucket(file) {
@@ -9,10 +11,29 @@ export class SamplesService {
AppConfig.PATH_TO_MOUNTED_BUCKET + file.originalname,
file.buffer
);
await this.addSampleToDB(file.originalname);
} catch (error) {
console.error(`Error occured while writing the file to the bucket`);
// tslint:disable-next-line: no-console
console.debug(error.stack);
throw error;
}
}

async getAllSampleNames() {
try {
return await SampleModel.find({});
} catch (error) {
console.error('Error occured while fetching the sample names');
// tslint:disable-next-line: no-console
console.debug(error.stack);
throw error;
}
}

private async addSampleToDB(filename: string) {
await SampleModel.create({
filename: filename,
});
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export class TestEntryDTO {
category: string;
command: string;
sample: string;
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import { Injectable } from '@nestjs/common';
import { TestEntryModel } from '../../../../models/regression-tests/test-entry.models';
import { TestEntryModel } from '../../../../models/test-entries/test-entry.models';

@Injectable()
export class TestEntryService {
async getAll() {
return await TestEntryModel.find({});
try {
} catch (error) {
console.error('Error while fetching the test entries');
// tslint:disable-next-line: no-console
console.debug(error.stack);
return await TestEntryModel.find({});
}
}

async create(category: string, new_command: string, files: Buffer[]) {
async create(
category: string,
new_command: string,
sample: string,
files: Buffer[]
) {
try {
return await TestEntryModel.create({
command: new_command,
category: category,
sample: sample,
correctFiles: files,
});
} catch (error) {
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ export class TestEntryController {
return await this.service.create(
testEntryDTO.category,
testEntryDTO.command,
testEntryDTO.sample,
files
);
} catch (error) {