-
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.
fix: 쿼리 인터페이스 대신 레포지토리를 사용하도록 수정 (#72)
- Loading branch information
Showing
8 changed files
with
108 additions
and
61 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 was deleted.
Oops, something went wrong.
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
47 changes: 38 additions & 9 deletions
47
src/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQueryHandler.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,25 +1,54 @@ | ||
import { Inject } from '@nestjs/common'; | ||
import { EntityRepository } from '@mikro-orm/mysql'; | ||
import { InjectRepository } from '@mikro-orm/nestjs'; | ||
import { NotFoundException } from '@nestjs/common'; | ||
import { IQueryHandler, QueryHandler } from '@nestjs/cqrs'; | ||
|
||
import { GetDoorLockPasswordQuery } from '@khlug/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQuery'; | ||
import { GetDoorLockPasswordQueryResult } from '@khlug/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQueryResult'; | ||
import { | ||
CacheQueryToken, | ||
ICacheQuery, | ||
} from '@khlug/app/application/infraBlue/query/ICacheQuery'; | ||
|
||
import { Cache, CacheId } from '@khlug/app/domain/cache/model/Cache'; | ||
|
||
import { Message } from '@khlug/constant/message'; | ||
|
||
@QueryHandler(GetDoorLockPasswordQuery) | ||
export class GetDoorLockPasswordQueryHandler | ||
implements | ||
IQueryHandler<GetDoorLockPasswordQuery, GetDoorLockPasswordQueryResult> | ||
{ | ||
constructor( | ||
@Inject(CacheQueryToken) | ||
private readonly cacheQuery: ICacheQuery, | ||
@InjectRepository(Cache) | ||
private readonly cacheRepository: EntityRepository<Cache>, | ||
) {} | ||
|
||
async execute(): Promise<GetDoorLockPasswordQueryResult> { | ||
const doorLockPasswordView = await this.cacheQuery.getDoorLockPassword(); | ||
return new GetDoorLockPasswordQueryResult(doorLockPasswordView); | ||
const passwords = await this.cacheRepository.find({ | ||
id: { | ||
$in: [ | ||
CacheId.masterPassword, | ||
CacheId.jajudyPassword, | ||
CacheId.facilityTeamPassword, | ||
], | ||
}, | ||
}); | ||
|
||
const masterPassword = passwords.find( | ||
(password) => password.id === CacheId.masterPassword, | ||
); | ||
const jajudyPassword = passwords.find( | ||
(password) => password.id === CacheId.jajudyPassword, | ||
); | ||
const facilityTeamPassword = passwords.find( | ||
(password) => password.id === CacheId.facilityTeamPassword, | ||
); | ||
|
||
if (!masterPassword || !jajudyPassword || !facilityTeamPassword) { | ||
throw new NotFoundException(Message.SOME_DOOR_LOCK_PASSWORD_NOT_FOUND); | ||
} | ||
|
||
return new GetDoorLockPasswordQueryResult({ | ||
master: masterPassword.content, | ||
forJajudy: jajudyPassword.content, | ||
forFacilityTeam: facilityTeamPassword.content, | ||
}); | ||
} | ||
} |
12 changes: 10 additions & 2 deletions
12
src/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQueryResult.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,7 +1,15 @@ | ||
import { IQueryResult } from '@nestjs/cqrs'; | ||
|
||
import { DoorLockPasswordView } from '@khlug/app/application/infraBlue/query/view/DoorLockPasswordView'; | ||
import { Typeof } from '@khlug/util/types'; | ||
|
||
export class GetDoorLockPasswordQueryResult implements IQueryResult { | ||
constructor(readonly view: DoorLockPasswordView) {} | ||
master: string; | ||
forJajudy: string; | ||
forFacilityTeam: string; | ||
|
||
constructor(params: Typeof<GetDoorLockPasswordQueryResult>) { | ||
this.master = params.master; | ||
this.forJajudy = params.forJajudy; | ||
this.forFacilityTeam = params.forFacilityTeam; | ||
} | ||
} |
5 changes: 0 additions & 5 deletions
5
src/app/application/infraBlue/query/view/DoorLockPasswordView.ts
This file was deleted.
Oops, something went wrong.
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