-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UseCases to delete Files, RelationshipTemplates and Tokens (#432)
* feat: delete files from backbone * feat: add isOwn check to tokens and templates * feat: adapt files, add use cases * test: add transport tests * refactor: remove unused error * test: add runtime tests * test: fix test * test: improve tests * test: fix token decomposition * fix: sync datawallet * refactor: test names * refactor: capitalize test describe block names Co-authored-by: Britta Stallknecht <[email protected]> * refactor: test name capitalization --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Britta Stallknecht <[email protected]>
- Loading branch information
1 parent
23b0ae3
commit 5e81f68
Showing
19 changed files
with
383 additions
and
15 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
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
37 changes: 37 additions & 0 deletions
37
packages/runtime/src/useCases/transport/files/DeleteFile.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,37 @@ | ||
import { Result } from "@js-soft/ts-utils"; | ||
import { CoreId } from "@nmshd/core-types"; | ||
import { AccountController, File, FileController } from "@nmshd/transport"; | ||
import { Inject } from "@nmshd/typescript-ioc"; | ||
import { FileIdString, RuntimeErrors, SchemaRepository, SchemaValidator, UseCase } from "../../common"; | ||
|
||
export interface DeleteFileRequest { | ||
fileId: FileIdString; | ||
} | ||
|
||
class Validator extends SchemaValidator<DeleteFileRequest> { | ||
public constructor(@Inject schemaRepository: SchemaRepository) { | ||
super(schemaRepository.getSchema("DeleteFileRequest")); | ||
} | ||
} | ||
|
||
export class DeleteFileUseCase extends UseCase<DeleteFileRequest, void> { | ||
public constructor( | ||
@Inject private readonly fileController: FileController, | ||
@Inject private readonly accountController: AccountController, | ||
@Inject validator: Validator | ||
) { | ||
super(validator); | ||
} | ||
|
||
protected async executeInternal(request: DeleteFileRequest): Promise<Result<void>> { | ||
const file = await this.fileController.getFile(CoreId.from(request.fileId)); | ||
if (!file) { | ||
return Result.fail(RuntimeErrors.general.recordNotFound(File)); | ||
} | ||
|
||
await this.fileController.deleteFile(file); | ||
await this.accountController.syncDatawallet(); | ||
|
||
return Result.ok(undefined); | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
packages/runtime/src/useCases/transport/relationshipTemplates/DeleteRelationshipTemplate.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,37 @@ | ||
import { Result } from "@js-soft/ts-utils"; | ||
import { CoreId } from "@nmshd/core-types"; | ||
import { AccountController, RelationshipTemplate, RelationshipTemplateController } from "@nmshd/transport"; | ||
import { Inject } from "@nmshd/typescript-ioc"; | ||
import { RelationshipTemplateIdString, RuntimeErrors, SchemaRepository, SchemaValidator, UseCase } from "../../common"; | ||
|
||
export interface DeleteRelationshipTemplateRequest { | ||
templateId: RelationshipTemplateIdString; | ||
} | ||
|
||
class Validator extends SchemaValidator<DeleteRelationshipTemplateRequest> { | ||
public constructor(@Inject schemaRepository: SchemaRepository) { | ||
super(schemaRepository.getSchema("DeleteRelationshipTemplateRequest")); | ||
} | ||
} | ||
|
||
export class DeleteRelationshipTemplateUseCase extends UseCase<DeleteRelationshipTemplateRequest, void> { | ||
public constructor( | ||
@Inject private readonly relationshipTemplateController: RelationshipTemplateController, | ||
@Inject private readonly accountController: AccountController, | ||
@Inject validator: Validator | ||
) { | ||
super(validator); | ||
} | ||
|
||
protected async executeInternal(request: DeleteRelationshipTemplateRequest): Promise<Result<void>> { | ||
const template = await this.relationshipTemplateController.getRelationshipTemplate(CoreId.from(request.templateId)); | ||
if (!template) { | ||
return Result.fail(RuntimeErrors.general.recordNotFound(RelationshipTemplate)); | ||
} | ||
|
||
await this.relationshipTemplateController.deleteRelationshipTemplate(template); | ||
await this.accountController.syncDatawallet(); | ||
|
||
return Result.ok(undefined); | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
packages/runtime/src/useCases/transport/tokens/DeleteToken.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,37 @@ | ||
import { Result } from "@js-soft/ts-utils"; | ||
import { CoreId } from "@nmshd/core-types"; | ||
import { AccountController, Token, TokenController } from "@nmshd/transport"; | ||
import { Inject } from "@nmshd/typescript-ioc"; | ||
import { RuntimeErrors, SchemaRepository, SchemaValidator, TokenIdString, UseCase } from "../../common"; | ||
|
||
export interface DeleteTokenRequest { | ||
tokenId: TokenIdString; | ||
} | ||
|
||
class Validator extends SchemaValidator<DeleteTokenRequest> { | ||
public constructor(@Inject schemaRepository: SchemaRepository) { | ||
super(schemaRepository.getSchema("DeleteTokenRequest")); | ||
} | ||
} | ||
|
||
export class DeleteTokenUseCase extends UseCase<DeleteTokenRequest, void> { | ||
public constructor( | ||
@Inject private readonly tokenController: TokenController, | ||
@Inject private readonly accountController: AccountController, | ||
@Inject validator: Validator | ||
) { | ||
super(validator); | ||
} | ||
|
||
protected async executeInternal(request: DeleteTokenRequest): Promise<Result<void>> { | ||
const token = await this.tokenController.getToken(CoreId.from(request.tokenId)); | ||
if (!token) { | ||
return Result.fail(RuntimeErrors.general.recordNotFound(Token)); | ||
} | ||
|
||
await this.tokenController.delete(token); | ||
await this.accountController.syncDatawallet(); | ||
|
||
return Result.ok(undefined); | ||
} | ||
} |
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
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.