Skip to content

Commit

Permalink
Merge pull request #4 from conceptadev/tnramalho-feature/report-module
Browse files Browse the repository at this point in the history
report module adjustments
  • Loading branch information
tnramalho authored Sep 16, 2024
2 parents 7bab55a + 9265450 commit 3f10b32
Show file tree
Hide file tree
Showing 25 changed files with 165 additions and 154 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FileSqliteEntity } from '@concepta/nestjs-file';
import { Entity, OneToOne } from 'typeorm';
import { FileSqliteEntity } from '@concepta/nestjs-file';
import { ReportEntityFixture } from '../report/report-entity.fixture';
import { ReportEntityInterface } from '../../interfaces/report-entity.interface';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { Inject } from '@nestjs/common';
import { ReportInterface, ReportStatusEnum } from '@concepta/ts-common';
import { FileService } from '@concepta/nestjs-file';
import { ReportStatusEnum } from '@concepta/ts-common';
import { ReportEntityInterface } from '../interfaces/report-entity.interface';
import { ReportGeneratorResultInterface } from '../interfaces/report-generator-result.interface';
import { ReportGeneratorServiceInterface } from '../interfaces/report-generator-service.interface';
import {
AWS_KEY_FIXTURE,
REPORT_SHORT_DELAY_KEY_FIXTURE,
} from './constants.fixture';
import { Inject } from '@nestjs/common';
import { delay } from '../utils/delay.util';

export class MyReportGeneratorShortDelayService
Expand All @@ -22,13 +21,13 @@ export class MyReportGeneratorShortDelayService

generateTimeout: number = 100;

async getDownloadUrl(report: ReportEntityInterface): Promise<string> {
async getDownloadUrl(report: ReportInterface): Promise<string> {
const file = await this.fileService.fetch({ id: report.id });
return file.downloadUrl || '';
}

async generate(
report: ReportEntityInterface,
report: ReportInterface,
): Promise<ReportGeneratorResultInterface> {
const file = await this.fileService.push({
fileName: report.name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Inject } from '@nestjs/common';
import { ReportInterface, ReportStatusEnum } from '@concepta/ts-common';
import { FileService } from '@concepta/nestjs-file';
import { ReportStatusEnum } from '@concepta/ts-common';
import { ReportEntityInterface } from '../interfaces/report-entity.interface';
import { ReportGeneratorResultInterface } from '../interfaces/report-generator-result.interface';
import { ReportGeneratorServiceInterface } from '../interfaces/report-generator-service.interface';
import { AWS_KEY_FIXTURE, REPORT_KEY_FIXTURE } from './constants.fixture';
import { Inject } from '@nestjs/common';

export class MyReportGeneratorService
implements ReportGeneratorServiceInterface
Expand All @@ -17,14 +16,14 @@ export class MyReportGeneratorService
KEY: string = REPORT_KEY_FIXTURE;
generateTimeout: number = 60000;

async getDownloadUrl(report: ReportEntityInterface): Promise<string> {
async getDownloadUrl(report: ReportInterface): Promise<string> {
if (!report?.file?.id) return '';
const file = await this.fileService.fetch({ id: report.file.id });
return file.downloadUrl || '';
}

async generate(
report: ReportEntityInterface,
report: ReportInterface,
): Promise<ReportGeneratorResultInterface> {
const file = await this.fileService.push({
fileName: report.name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FileEntityInterface } from '@concepta/nestjs-file';
import { Entity, JoinColumn, OneToOne } from 'typeorm';
import { FileEntityInterface } from '@concepta/nestjs-file';
import { ReportSqliteEntity } from '../../entities/report-sqlite.entity';
import { FileEntityFixture } from '../file/file-entity.fixture';

Expand Down
14 changes: 5 additions & 9 deletions packages/nestjs-report/src/dto/report.dto.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import { CommonEntityDto, ReferenceIdDto } from '@concepta/nestjs-common';
import { ReportStatusEnum } from '@concepta/ts-common';
import { ReferenceIdInterface } from '@concepta/ts-core';
import { ApiProperty } from '@nestjs/swagger';
import { Exclude, Expose, Type } from 'class-transformer';
import { IsEnum, IsOptional, IsString, ValidateNested } from 'class-validator';
import { ReportEntityInterface } from '../interfaces/report-entity.interface';
import { ApiProperty } from '@nestjs/swagger';
import { ReferenceIdInterface } from '@concepta/ts-core';
import { ReportInterface, ReportStatusEnum } from '@concepta/ts-common';
import { CommonEntityDto, ReferenceIdDto } from '@concepta/nestjs-common';

/**
* Report DTO
*/
@Exclude()
export class ReportDto
extends CommonEntityDto
implements ReportEntityInterface
{
export class ReportDto extends CommonEntityDto implements ReportInterface {
/**
* Storage provider key
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Column, Entity, Unique } from 'typeorm';
import { ReportStatusEnum } from '@concepta/ts-common';
import { ReferenceIdInterface } from '@concepta/ts-core';
import { CommonPostgresEntity } from '@concepta/typeorm-common';
import { Column, Entity, Unique } from 'typeorm';
import { ReportEntityInterface } from '../interfaces/report-entity.interface';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Column, Entity, Unique } from 'typeorm';
import { ReportStatusEnum } from '@concepta/ts-common';
import { ReferenceIdInterface } from '@concepta/ts-core';
import { CommonSqliteEntity } from '@concepta/typeorm-common';
import { Column, Entity, Unique } from 'typeorm';
import { ReportEntityInterface } from '../interfaces/report-entity.interface';

/**
Expand Down
8 changes: 0 additions & 8 deletions packages/nestjs-report/src/enum/report-status.enum.ts

This file was deleted.

16 changes: 7 additions & 9 deletions packages/nestjs-report/src/exceptions/report-create.exception.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { HttpStatus } from '@nestjs/common';
import { RuntimeException } from '@concepta/nestjs-exception';
import {
RuntimeException,
RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';

export class ReportCreateException extends RuntimeException {
constructor(
message = 'Error while trying to create a report',
originalError: unknown,
) {
constructor(options?: RuntimeExceptionOptions) {
super({
message,
originalError,
httpStatus: HttpStatus.INTERNAL_SERVER_ERROR,
message: 'Error while trying to create a report',
...options,
});

this.errorCode = 'REPORT_CREATE_ERROR';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { HttpStatus } from '@nestjs/common';
import { RuntimeException } from '@concepta/nestjs-exception';
import {
RuntimeException,
RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';

export class ReportDuplicateEntryException extends RuntimeException {
context: RuntimeException['context'] & {
Expand All @@ -10,14 +13,13 @@ export class ReportDuplicateEntryException extends RuntimeException {
constructor(
serviceKey: string,
reportName: string,
originalError?: unknown,
message = 'Duplicate entry detected for service %s with report %s',
options?: RuntimeExceptionOptions,
) {
super({
message,
messageParams: [serviceKey, reportName],
message: 'Duplicate entry detected for service %s with report %s',
httpStatus: HttpStatus.CONFLICT,
originalError,
messageParams: [serviceKey, reportName],
...options,
});

this.errorCode = 'REPORT_DUPLICATE_ENTRY_ERROR';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import { HttpStatus } from '@nestjs/common';
import { RuntimeException } from '@concepta/nestjs-exception';
import {
RuntimeException,
RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';

export class ReportGeneratorServiceNotFoundException extends RuntimeException {
context: RuntimeException['context'] & {
generatorServiceName: string;
};

constructor(
assignmentName: string,
message = 'Report generator service %s was not registered to be used.',
) {
constructor(generatorServiceName: string, options?: RuntimeExceptionOptions) {
super({
message,
messageParams: [assignmentName],
message: 'Report generator service %s was not registered to be used.',
messageParams: [generatorServiceName],
httpStatus: HttpStatus.NOT_FOUND,
...options,
});

this.errorCode = 'REPORT_GENERATOR_SERVICE_NOT_FOUND_ERROR';

this.context = {
...super.context,
generatorServiceName: assignmentName,
generatorServiceName,
};
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { HttpStatus } from '@nestjs/common';
import { RuntimeException } from '@concepta/nestjs-exception';
import {
RuntimeException,
RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';

export class ReportIdMissingException extends RuntimeException {
constructor(message = 'Report id is missing.') {
constructor(options?: RuntimeExceptionOptions) {
super({
message,
message: 'Report id is missing.',
httpStatus: HttpStatus.BAD_REQUEST,
...options,
});

this.errorCode = 'REPORT_ID_MISSING_ERROR';
Expand Down
14 changes: 7 additions & 7 deletions packages/nestjs-report/src/exceptions/report-query.exception.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { HttpStatus } from '@nestjs/common';
import { RuntimeException } from '@concepta/nestjs-exception';
import {
RuntimeException,
RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';

export class ReportQueryException extends RuntimeException {
constructor(
message = 'Error while trying to do a query to report',
originalError?: unknown,
) {
constructor(options?: RuntimeExceptionOptions) {
super({
message,
originalError,
message: 'Error while trying to do a query to report',
httpStatus: HttpStatus.INTERNAL_SERVER_ERROR,
...options,
});

this.errorCode = 'REPORT_QUERY_ERROR';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { HttpStatus } from '@nestjs/common';
import { RuntimeException } from '@concepta/nestjs-exception';
import {
RuntimeException,
RuntimeExceptionOptions,
} from '@concepta/nestjs-exception';

export class ReportTimeoutException extends RuntimeException {
constructor(message = 'Report generation timed out.') {
constructor(options?: RuntimeExceptionOptions) {
super({
message,
message: 'Report generation timed out.',
httpStatus: HttpStatus.INTERNAL_SERVER_ERROR,
...options,
});

this.errorCode = 'REPORT_GENERATION_TIMEOUT';
Expand Down
2 changes: 2 additions & 0 deletions packages/nestjs-report/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ export { ReportService } from './services/report.service';

export { ReportDto } from './dto/report.dto';
export { ReportCreateDto } from './dto/report-create.dto';

export { DoneCallback } from './report.types';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ReportEntityInterface } from './report-entity.interface';
import { ReportInterface } from '@concepta/ts-common';

export interface ReportGeneratorResultInterface
extends Pick<ReportEntityInterface, 'id' | 'status' | 'file'>,
Partial<Pick<ReportEntityInterface, 'errorMessage'>> {}
extends Pick<ReportInterface, 'id' | 'status' | 'file'>,
Partial<Pick<ReportInterface, 'errorMessage'>> {}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { ReportEntityInterface } from './report-entity.interface';
import { DoneCallback } from '../report.types';
import { ReportCreateDto } from '../dto/report-create.dto';
import { ReportInterface } from '@concepta/ts-common';

export interface ReportServiceInterface {
generate(report: ReportCreateDto): Promise<ReportEntityInterface>;
fetch(
report: Pick<ReportEntityInterface, 'id'>,
): Promise<ReportEntityInterface>;
generate(report: ReportCreateDto): Promise<ReportInterface>;
fetch(report: Pick<ReportInterface, 'id'>): Promise<ReportInterface>;
done: DoneCallback;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { ReportEntityInterface } from './report-entity.interface';
import { ReportInterface } from '@concepta/ts-common';
import { ReportGeneratorResultInterface } from './report-generator-result.interface';
import { ReportGeneratorServiceInterface } from './report-generator-service.interface';

export interface ReportStrategyServiceInterface {
generate(
report: ReportEntityInterface,
): Promise<ReportGeneratorResultInterface>;
getDownloadUrl(report: ReportEntityInterface): Promise<string>;
resolveGeneratorService(
report: ReportEntityInterface,
): ReportGeneratorServiceInterface;
generate(report: ReportInterface): Promise<ReportGeneratorResultInterface>;
getDownloadUrl(report: ReportInterface): Promise<string>;
}
10 changes: 5 additions & 5 deletions packages/nestjs-report/src/report.module.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { Repository } from 'typeorm';
import { DynamicModule, ModuleMetadata } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { ReportStatusEnum } from '@concepta/ts-common';
import { FileModule } from '@concepta/nestjs-file';
import {
getDynamicRepositoryToken,
getEntityRepositoryToken,
TypeOrmExtModule,
} from '@concepta/nestjs-typeorm-ext';
import { DynamicModule, ModuleMetadata } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { Repository } from 'typeorm';

import { ReportService } from './services/report.service';

import { REPORT_MODULE_REPORT_ENTITY_KEY } from './report.constants';

import { ReportEntityInterface } from './interfaces/report-entity.interface';

import { FileModule } from '@concepta/nestjs-file';
import { ReportStatusEnum } from '@concepta/ts-common';
import { AwsStorageService } from './__fixtures__/aws-storage.service';
import {
REPORT_KEY_FIXTURE,
Expand Down
Loading

0 comments on commit 3f10b32

Please sign in to comment.