-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
253 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { Exclude } from 'class-transformer'; | ||
import { PickType } from '@nestjs/swagger'; | ||
import { ReportCreatableInterface } from '@concepta/ts-common'; | ||
import { PickType } from '@nestjs/swagger'; | ||
import { Exclude } from 'class-transformer'; | ||
import { ReportDto } from './report.dto'; | ||
|
||
/** | ||
* Report Create DTO | ||
*/ | ||
@Exclude() | ||
export class ReportCreateDto | ||
extends PickType(ReportDto, ['serviceKey', 'name'] as const) | ||
extends PickType(ReportDto, ['serviceKey', 'name', 'status'] as const) | ||
implements ReportCreatableInterface {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Exclude } from 'class-transformer'; | ||
import { IntersectionType, PartialType, PickType } from '@nestjs/swagger'; | ||
import { ReportCreatableInterface } from '@concepta/ts-common'; | ||
import { ReportDto } from './report.dto'; | ||
import { ReportUpdatableInterface } from '@concepta/ts-common/src/report/interfaces/report-updatable.interface'; | ||
|
||
/** | ||
* Report Update DTO | ||
*/ | ||
@Exclude() | ||
export class ReportUpdateDto | ||
extends IntersectionType( | ||
PickType(ReportDto, ['status', 'file'] as const), | ||
PartialType(PickType(ReportDto, ['errorMessage'] as const)) | ||
) | ||
implements ReportUpdatableInterface {} |
17 changes: 17 additions & 0 deletions
17
packages/nestjs-report/src/exceptions/report-download-url-missing.exception.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { HttpStatus } from '@nestjs/common'; | ||
import { | ||
RuntimeException, | ||
RuntimeExceptionOptions, | ||
} from '@concepta/nestjs-exception'; | ||
|
||
export class ReportDownloadUrlMissingException extends RuntimeException { | ||
constructor(options?: RuntimeExceptionOptions) { | ||
super({ | ||
message: 'Error trying to generate signed download url', | ||
httpStatus: HttpStatus.BAD_REQUEST, | ||
...options, | ||
}); | ||
|
||
this.errorCode = 'REPORT_DOWNLOAD_URL_ERROR'; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/nestjs-report/src/exceptions/report-name-missing.exception.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { HttpStatus } from '@nestjs/common'; | ||
import { | ||
RuntimeException, | ||
RuntimeExceptionOptions, | ||
} from '@concepta/nestjs-exception'; | ||
|
||
export class ReportnameMissingException extends RuntimeException { | ||
constructor(options?: RuntimeExceptionOptions) { | ||
super({ | ||
message: 'Reportname is missing.', | ||
httpStatus: HttpStatus.BAD_REQUEST, | ||
...options, | ||
}); | ||
|
||
this.errorCode = 'REPORTNAME_MISSING_ERROR'; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/nestjs-report/src/exceptions/report-service-key-missing.exception.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { HttpStatus } from '@nestjs/common'; | ||
import { | ||
RuntimeException, | ||
RuntimeExceptionOptions, | ||
} from '@concepta/nestjs-exception'; | ||
|
||
export class ReportServiceKeyMissingException extends RuntimeException { | ||
constructor(options?: RuntimeExceptionOptions) { | ||
super({ | ||
message: 'Service key is missing.', | ||
httpStatus: HttpStatus.BAD_REQUEST, | ||
...options, | ||
}); | ||
|
||
this.errorCode = 'SERVICE_KEY_MISSING_ERROR'; | ||
} | ||
} |
7 changes: 3 additions & 4 deletions
7
packages/nestjs-report/src/interfaces/report-generator-result.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import { ReportInterface } from '@concepta/ts-common'; | ||
import { ReportUpdatableInterface } from '@concepta/ts-common/src/report/interfaces/report-updatable.interface'; | ||
import { ReferenceIdInterface } from '@concepta/ts-core'; | ||
|
||
export interface ReportGeneratorResultInterface | ||
extends Pick<ReportInterface, 'id' | 'status' | 'file'>, | ||
Partial<Pick<ReportInterface, 'errorMessage'>> {} | ||
export interface ReportGeneratorResultInterface extends ReportUpdatableInterface, ReferenceIdInterface {} |
12 changes: 12 additions & 0 deletions
12
packages/nestjs-report/src/interfaces/report-lookup-service.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ReportCreatableInterface, ReportInterface } from '@concepta/ts-common'; | ||
import { LookupIdInterface, ReferenceId, ReferenceIdInterface } from '@concepta/ts-core'; | ||
import { QueryOptionsInterface } from '@concepta/typeorm-common'; | ||
|
||
export interface ReportLookupServiceInterface | ||
extends LookupIdInterface<ReferenceId, ReportInterface, QueryOptionsInterface> { | ||
getUniqueReport( | ||
org: Pick<ReportCreatableInterface, 'serviceKey' | 'name'>, | ||
queryOptions?: QueryOptionsInterface, | ||
): Promise<ReportInterface | null>; | ||
getWithFile(report: ReferenceIdInterface, queryOptions?: QueryOptionsInterface): Promise<ReportInterface | null>; | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/nestjs-report/src/interfaces/report-mutate-service.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { ReportCreatableInterface } from '@concepta/ts-common'; | ||
import { CreateOneInterface, ReferenceIdInterface, UpdateOneInterface } from '@concepta/ts-core'; | ||
import { ReportEntityInterface } from './report-entity.interface'; | ||
import { ReportUpdatableInterface } from '@concepta/ts-common/src/report/interfaces/report-updatable.interface'; | ||
|
||
export interface ReportMutateServiceInterface | ||
extends CreateOneInterface<ReportCreatableInterface, ReportEntityInterface>, | ||
UpdateOneInterface< | ||
ReportUpdatableInterface & ReferenceIdInterface, | ||
ReportEntityInterface | ||
> {} |
3 changes: 3 additions & 0 deletions
3
packages/nestjs-report/src/interfaces/report-status.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { ReportInterface } from '@concepta/ts-common'; | ||
|
||
export interface ReportStatusInterface extends Pick<ReportInterface, 'status'> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
packages/nestjs-report/src/services/report-lookup.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { InjectDynamicRepository } from '@concepta/nestjs-typeorm-ext'; | ||
import { LookupService, QueryOptionsInterface } from '@concepta/typeorm-common'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { Repository } from 'typeorm'; | ||
|
||
import { REPORT_MODULE_REPORT_ENTITY_KEY } from '../report.constants'; | ||
import { ReportEntityInterface } from '../interfaces/report-entity.interface'; | ||
import { ReportLookupServiceInterface } from '../interfaces/report-lookup-service.interface'; | ||
import { ReportInterface } from '@concepta/ts-common'; | ||
import { ReportServiceKeyMissingException } from '../exceptions/report-service-key-missing.exception'; | ||
import { ReportnameMissingException } from '../exceptions/report-name-missing.exception'; | ||
import { ReferenceIdInterface } from '@concepta/ts-core'; | ||
import { ReportQueryException } from '../exceptions/report-query.exception'; | ||
|
||
/** | ||
* Report lookup service | ||
*/ | ||
@Injectable() | ||
export class ReportLookupService | ||
extends LookupService<ReportEntityInterface> | ||
implements ReportLookupServiceInterface | ||
{ | ||
constructor( | ||
@InjectDynamicRepository(REPORT_MODULE_REPORT_ENTITY_KEY) | ||
repo: Repository<ReportEntityInterface>, | ||
) { | ||
super(repo); | ||
} | ||
async getUniqueReport( | ||
report: Pick<ReportInterface, 'serviceKey' | 'name'>, | ||
queryOptions?: QueryOptionsInterface, | ||
) { | ||
if (!report.serviceKey) { | ||
throw new ReportServiceKeyMissingException(); | ||
} | ||
if (!report.name) { | ||
throw new ReportnameMissingException(); | ||
} | ||
return this.findOne( | ||
{ | ||
where: { | ||
serviceKey: report.serviceKey, | ||
name: report.name, | ||
}, | ||
}, | ||
queryOptions, | ||
); | ||
} | ||
|
||
async getWithFile( | ||
report: ReferenceIdInterface, | ||
queryOptions?: QueryOptionsInterface, | ||
) { | ||
try { | ||
return this.findOne({ | ||
where: { | ||
id: report.id, | ||
}, | ||
relations: ['file'], | ||
}, | ||
queryOptions, | ||
); | ||
} catch (originalError) { | ||
throw new ReportQueryException({ originalError }); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
packages/nestjs-report/src/services/report-mutate.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { InjectDynamicRepository } from '@concepta/nestjs-typeorm-ext'; | ||
import { ReportCreatableInterface } from '@concepta/ts-common'; | ||
import { MutateService } from '@concepta/typeorm-common'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { Repository } from 'typeorm'; | ||
import { ReportEntityInterface } from '../interfaces/report-entity.interface'; | ||
|
||
import { ReportUpdatableInterface } from '@concepta/ts-common/src/report/interfaces/report-updatable.interface'; | ||
import { ReportCreateDto } from '../dto/report-create.dto'; | ||
import { ReportUpdateDto } from '../dto/report-update.dto'; | ||
import { ReportMutateServiceInterface } from '../interfaces/report-mutate-service.interface'; | ||
import { REPORT_MODULE_REPORT_ENTITY_KEY } from '../report.constants'; | ||
|
||
/** | ||
* Report mutate service | ||
*/ | ||
@Injectable() | ||
export class ReportMutateService | ||
extends MutateService< | ||
ReportEntityInterface, | ||
ReportCreatableInterface, | ||
ReportUpdatableInterface | ||
> | ||
implements ReportMutateServiceInterface | ||
{ | ||
protected createDto = ReportCreateDto; | ||
protected updateDto = ReportUpdateDto; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param repo - instance of the report repo | ||
*/ | ||
constructor( | ||
@InjectDynamicRepository(REPORT_MODULE_REPORT_ENTITY_KEY) | ||
repo: Repository<ReportEntityInterface>, | ||
) { | ||
super(repo); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.