-
Notifications
You must be signed in to change notification settings - Fork 0
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
6 changed files
with
41 additions
and
9 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
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
20 changes: 19 additions & 1 deletion
20
apps/levansy-access-service/src/domain/use-case/bio-product/update.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,18 +1,36 @@ | ||
import { Inject, Injectable } from '@nestjs/common' | ||
|
||
import { BioProductAction, assertPermission } from 'src/domain/entity' | ||
import { | ||
AuthContextToken, | ||
BioProductRepositoryToken, | ||
IAuthContext, | ||
IBioProductRepository, | ||
} from 'src/domain/interface' | ||
import { BioProductFindOneUseCase } from './find-one' | ||
|
||
@Injectable() | ||
export class BioProductUpdateUseCase { | ||
constructor( | ||
@Inject(BioProductRepositoryToken) | ||
private readonly bioProductRepository: IBioProductRepository, | ||
@Inject(AuthContextToken) private readonly authContext: IAuthContext, | ||
private readonly bioProductFindOneUseCase: BioProductFindOneUseCase, | ||
) {} | ||
|
||
execute(...input: Parameters<IBioProductRepository['update']>) { | ||
async execute(...input: Parameters<IBioProductRepository['update']>) { | ||
const { ability } = this.authContext.getData() | ||
|
||
const target = await this.bioProductFindOneUseCase.execute({ | ||
filter: input[0], | ||
}) | ||
|
||
if (target === null) { | ||
throw new Error('not found') | ||
} | ||
|
||
assertPermission(ability, 'BioProduct', BioProductAction.Update, target) | ||
|
||
return this.bioProductRepository.update(...input) | ||
} | ||
} |