-
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
23 changed files
with
398 additions
and
128 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,7 @@ describe('UpdateUserCommandHandler', () => { | |
const email = '[email protected]'; | ||
const phone = null; | ||
const homepage = 'https://some.home.page/'; | ||
const languages = ['some', 'languages']; | ||
const language = 'some, language'; | ||
const interestIds = ['interest1', 'interest2']; | ||
const prefer = 'some-prefers'; | ||
|
||
|
@@ -95,7 +95,7 @@ describe('UpdateUserCommandHandler', () => { | |
email, | ||
phone, | ||
homepage, | ||
languages, | ||
language, | ||
interestIds, | ||
prefer, | ||
); | ||
|
@@ -140,7 +140,7 @@ describe('UpdateUserCommandHandler', () => { | |
email, | ||
phone, | ||
homepage, | ||
languages, | ||
language, | ||
prefer, | ||
}); | ||
}); | ||
|
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
65 changes: 0 additions & 65 deletions
65
src/app/application/user/query/listUser/ListUserQueryHandler.spec.ts
This file was deleted.
Oops, something went wrong.
51 changes: 37 additions & 14 deletions
51
src/app/application/user/query/listUser/ListUserQueryHandler.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,33 +1,56 @@ | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
import { EntityRepository } from '@mikro-orm/mysql'; | ||
import { InjectRepository } from '@mikro-orm/nestjs'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { IQueryHandler, QueryHandler } from '@nestjs/cqrs'; | ||
|
||
import { | ||
IUserQuery, | ||
UserQuery, | ||
} from '@khlug/app/application/user/query/IUserQuery'; | ||
import { ListUserQuery } from '@khlug/app/application/user/query/listUser/ListUserQuery'; | ||
import { ListUserQueryResult } from '@khlug/app/application/user/query/listUser/ListUserQueryResult'; | ||
import { UserListView } from '@khlug/app/application/user/query/view/UserListView'; | ||
|
||
import { User } from '@khlug/app/domain/user/model/User'; | ||
|
||
@Injectable() | ||
@QueryHandler(ListUserQuery) | ||
export class ListUserQueryHandler | ||
implements IQueryHandler<ListUserQuery, ListUserQueryResult> | ||
{ | ||
constructor( | ||
@Inject(UserQuery) | ||
private readonly userQuery: IUserQuery, | ||
@InjectRepository(User) | ||
private readonly userRepository: EntityRepository<User>, | ||
) {} | ||
|
||
async execute(query: ListUserQuery): Promise<ListUserQueryResult> { | ||
const { state, interestId, limit, offset } = query; | ||
const { email, name, college, grade, state, limit, offset } = query; | ||
|
||
const qb = this.userRepository.createQueryBuilder('user'); | ||
|
||
if (email) { | ||
qb.andWhere('profile.email LIKE ?', [`%${email}%`]); | ||
} | ||
|
||
if (name) { | ||
qb.andWhere('profile.name LIKE ?', [`%${name}%`]); | ||
} | ||
|
||
if (college) { | ||
qb.andWhere('profile.college LIKE ?', [`%${college}%`]); | ||
} | ||
|
||
if (grade) { | ||
qb.andWhere('profile.grade = ?', [grade]); | ||
} | ||
|
||
if (state) { | ||
qb.andWhere('profile.state = ?', [state]); | ||
} | ||
|
||
const listView = await this.userQuery.listUser({ | ||
state, | ||
interestId, | ||
limit, | ||
offset, | ||
}); | ||
const [users, count] = await qb | ||
.limit(limit) | ||
.offset(offset) | ||
.orderBy({ id: 'ASC' }) | ||
.getResultAndCount(); | ||
|
||
const listView: UserListView = { count, users }; | ||
return new ListUserQueryResult(listView); | ||
} | ||
} |
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.