-
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.
chore: adjustments on mutate and lookup pattern
- Loading branch information
Showing
17 changed files
with
299 additions
and
84 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
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
16 changes: 7 additions & 9 deletions
16
packages/nestjs-file/src/exceptions/file-create.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
17 changes: 17 additions & 0 deletions
17
packages/nestjs-file/src/exceptions/file-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 FileDownloadUrlMissingException extends RuntimeException { | ||
constructor(options?: RuntimeExceptionOptions) { | ||
super({ | ||
message: 'Error trying to generate signed download url', | ||
httpStatus: HttpStatus.BAD_REQUEST, | ||
...options, | ||
}); | ||
|
||
this.errorCode = 'FILE_DOWNLOAD_URL_ERROR'; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/nestjs-file/src/exceptions/file-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 FilenameMissingException extends RuntimeException { | ||
constructor(options?: RuntimeExceptionOptions) { | ||
super({ | ||
message: 'Filename is missing.', | ||
httpStatus: HttpStatus.BAD_REQUEST, | ||
...options, | ||
}); | ||
|
||
this.errorCode = 'FILENAME_MISSING_ERROR'; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/nestjs-file/src/exceptions/file-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 FileServiceKeyMissingException extends RuntimeException { | ||
constructor(options?: RuntimeExceptionOptions) { | ||
super({ | ||
message: 'Service key is missing.', | ||
httpStatus: HttpStatus.BAD_REQUEST, | ||
...options, | ||
}); | ||
|
||
this.errorCode = 'SERVICE_KEY_MISSING_ERROR'; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/nestjs-file/src/exceptions/file-upload-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 FileUploadUrlMissingException extends RuntimeException { | ||
constructor(options?: RuntimeExceptionOptions) { | ||
super({ | ||
message: 'Error trying to generate signed upload url', | ||
httpStatus: HttpStatus.BAD_REQUEST, | ||
...options, | ||
}); | ||
|
||
this.errorCode = 'FILE_UPLOAD_URL_ERROR'; | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
packages/nestjs-file/src/interfaces/file-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,11 @@ | ||
import { FileCreatableInterface, FileInterface } from '@concepta/ts-common'; | ||
import { LookupIdInterface, ReferenceId } from '@concepta/ts-core'; | ||
import { QueryOptionsInterface } from '@concepta/typeorm-common'; | ||
|
||
export interface FileLookupServiceInterface | ||
extends LookupIdInterface<ReferenceId, FileInterface, QueryOptionsInterface> { | ||
getUniqueFile( | ||
org: Pick<FileCreatableInterface, 'serviceKey' | 'fileName'>, | ||
queryOptions?: QueryOptionsInterface, | ||
): Promise<FileInterface | null>; | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/nestjs-file/src/interfaces/file-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,6 @@ | ||
import { FileCreatableInterface } from '@concepta/ts-common'; | ||
import { CreateOneInterface } from '@concepta/ts-core'; | ||
import { FileEntityInterface } from './file-entity.interface'; | ||
|
||
export interface FileMutateServiceInterface | ||
extends CreateOneInterface<FileCreatableInterface, FileEntityInterface> {} |
7 changes: 4 additions & 3 deletions
7
packages/nestjs-file/src/interfaces/file-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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { FileInterface } from '@concepta/ts-common'; | ||
import { FileCreatableInterface, FileInterface } from '@concepta/ts-common'; | ||
import { ReferenceIdInterface } from '@concepta/ts-core'; | ||
|
||
export interface FileServiceInterface { | ||
push(file: Omit<FileInterface, 'id'>): Promise<FileInterface>; | ||
fetch(file: Omit<FileInterface, 'serviceKey'>): Promise<FileInterface>; | ||
push(file: FileCreatableInterface): Promise<FileInterface>; | ||
fetch(file: ReferenceIdInterface): Promise<FileInterface>; | ||
} |
10 changes: 6 additions & 4 deletions
10
packages/nestjs-file/src/interfaces/file-strategy-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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { FileInterface } from '@concepta/ts-common'; | ||
import { FileCreatableInterface } from '@concepta/ts-common'; | ||
import { FileStorageServiceInterface } from './file-storage-service.interface'; | ||
|
||
export interface FileStrategyServiceInterface { | ||
getUploadUrl(file: FileInterface): Promise<string>; | ||
getDownloadUrl(file: FileInterface): Promise<string>; | ||
resolveStorageService(file: FileInterface): FileStorageServiceInterface; | ||
getUploadUrl(file: FileCreatableInterface): Promise<string>; | ||
getDownloadUrl(file: FileCreatableInterface): Promise<string>; | ||
resolveStorageService( | ||
file: FileCreatableInterface, | ||
): FileStorageServiceInterface; | ||
} |
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,47 @@ | ||
import { InjectDynamicRepository } from '@concepta/nestjs-typeorm-ext'; | ||
import { LookupService, QueryOptionsInterface } from '@concepta/typeorm-common'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { Repository } from 'typeorm'; | ||
|
||
import { FILE_MODULE_FILE_ENTITY_KEY } from '../file.constants'; | ||
import { FileEntityInterface } from '../interfaces/file-entity.interface'; | ||
import { FileLookupServiceInterface } from '../interfaces/file-lookup-service.interface'; | ||
import { FileInterface } from '@concepta/ts-common'; | ||
import { FileServiceKeyMissingException } from '../exceptions/file-service-key-missing.exception'; | ||
import { FilenameMissingException } from '../exceptions/file-name-missing.exception'; | ||
|
||
/** | ||
* File lookup service | ||
*/ | ||
@Injectable() | ||
export class FileLookupService | ||
extends LookupService<FileEntityInterface> | ||
implements FileLookupServiceInterface | ||
{ | ||
constructor( | ||
@InjectDynamicRepository(FILE_MODULE_FILE_ENTITY_KEY) | ||
repo: Repository<FileEntityInterface>, | ||
) { | ||
super(repo); | ||
} | ||
async getUniqueFile( | ||
file: Pick<FileInterface, 'serviceKey' | 'fileName'>, | ||
queryOptions?: QueryOptionsInterface, | ||
) { | ||
if (!file.serviceKey) { | ||
throw new FileServiceKeyMissingException(); | ||
} | ||
if (!file.fileName) { | ||
throw new FilenameMissingException(); | ||
} | ||
return this.findOne( | ||
{ | ||
where: { | ||
serviceKey: file.serviceKey, | ||
fileName: file.fileName, | ||
}, | ||
}, | ||
queryOptions, | ||
); | ||
} | ||
} |
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,38 @@ | ||
import { Repository } from 'typeorm'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { MutateService } from '@concepta/typeorm-common'; | ||
import { InjectDynamicRepository } from '@concepta/nestjs-typeorm-ext'; | ||
import { FileCreatableInterface } from '@concepta/ts-common'; | ||
import { FileEntityInterface } from '../interfaces/file-entity.interface'; | ||
|
||
import { FileCreateDto } from '../dto/file-create.dto'; | ||
import { FileMutateServiceInterface } from '../interfaces/file-mutate-service.interface'; | ||
import { FILE_MODULE_FILE_ENTITY_KEY } from '../file.constants'; | ||
|
||
/** | ||
* File mutate service | ||
*/ | ||
@Injectable() | ||
export class FileMutateService | ||
extends MutateService< | ||
FileEntityInterface, | ||
FileCreatableInterface, | ||
FileCreatableInterface | ||
> | ||
implements FileMutateServiceInterface | ||
{ | ||
protected createDto = FileCreateDto; | ||
protected updateDto = FileCreateDto; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param repo - instance of the file repo | ||
*/ | ||
constructor( | ||
@InjectDynamicRepository(FILE_MODULE_FILE_ENTITY_KEY) | ||
repo: Repository<FileEntityInterface>, | ||
) { | ||
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.