-
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
1 parent
0649a28
commit 4f40289
Showing
15 changed files
with
164 additions
and
36 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
15 changes: 10 additions & 5 deletions
15
...pplication/activity-class/queries/list-activity-class/list-activity-class-query-mapper.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
49 changes: 45 additions & 4 deletions
49
src/application/activity-class/queries/list-activity-class/list-activity-class-query.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,10 +1,51 @@ | ||
import { ActivityClassDTO } from "@domain/dtos/activity-class"; | ||
import { map } from "./list-activity-class-query-mapper"; | ||
|
||
export function makeListActivityClassQuery({ activityClassRepository }: Pick<Dependencies, 'activityClassRepository'>) { | ||
return async function listActivityClassQuery() { | ||
export type ListActivitClassQuery = Readonly<{ | ||
language: string; | ||
}>; | ||
|
||
const activityClasses = await activityClassRepository.list(); | ||
export function makeListActivityClassQuery({ activityClassRepository, db }: Pick<Dependencies, 'activityClassRepository' | 'db'>) { | ||
return async function listActivityClassQuery({ language }: ListActivitClassQuery) { | ||
const activityClasses = await activityClassRepository.list({ language }); | ||
|
||
return activityClasses.map((activityClass) => map(activityClass)); | ||
const enrichedActivityClasses = await Promise.all(activityClasses.map(async (activityClass) => { | ||
const classInfo = await db.renamedclass.findUnique({ | ||
where: { id: Number(activityClass.class_id) }, | ||
}); | ||
|
||
const enrichedClass = { | ||
...activityClass, | ||
id: Number(activityClass.id), | ||
class: { | ||
id: String(activityClass.class_id), | ||
name: language === "vi" ? classInfo?.vi_name ?? '' : classInfo?.en_name ?? '', | ||
description: language === "vi" ? classInfo?.vi_description ?? '' : classInfo?.en_description ?? '', | ||
image: classInfo?.image ?? null, | ||
}, | ||
}; | ||
|
||
const activityClassDTO: ActivityClassDTO = { | ||
id: enrichedClass.id ?? null, | ||
class: { | ||
id: enrichedClass.class.id, | ||
name: enrichedClass.class.name ?? null, | ||
description: enrichedClass.class.description ?? null, | ||
image: enrichedClass.class.image ?? null, | ||
}, | ||
name: enrichedClass.name ?? null, | ||
image_url: enrichedClass.image_url ?? null, | ||
status: enrichedClass.status, | ||
order: enrichedClass.order ?? null, | ||
created_at: enrichedClass.created_at?.toISOString() ?? null, | ||
updated_at: enrichedClass.updated_at?.toISOString() ?? null, | ||
created_by: enrichedClass.created_by ?? null, | ||
updated_by: enrichedClass.updated_by ?? null, | ||
}; | ||
|
||
return activityClassDTO; | ||
})); | ||
|
||
return enrichedActivityClasses.map((activityClass) => map(activityClass)); | ||
}; | ||
} |
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,5 +1,5 @@ | ||
import { ActivityClassEntity } from "@domain/entities/activity-class"; | ||
|
||
export interface ActivityClassesRepository { | ||
list(): Promise<Array<ActivityClassEntity>>; | ||
list(params: { language: string }): Promise<Array<ActivityClassEntity>>; | ||
} |
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,5 +1,5 @@ | ||
import { StudentResultEntity } from "@domain/entities/student-result"; | ||
|
||
export interface StudentResultsRepository { | ||
list(): Promise<Array<StudentResultEntity>>; | ||
list(params: { language: string }): Promise<Array<StudentResultEntity>>; | ||
} |
14 changes: 9 additions & 5 deletions
14
...pplication/student-result/queries/list-student-result/list-student-result-query-mapper.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
50 changes: 46 additions & 4 deletions
50
src/application/student-result/queries/list-student-result/list-student-result-query.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,10 +1,52 @@ | ||
import { StudentResultDTO } from "@domain/dtos/student-result"; | ||
import { map } from "./list-student-result-query-mapper"; | ||
|
||
export function makeListStudentResultQuery({ studentResultRepository }: Pick<Dependencies, 'studentResultRepository'>) { | ||
return async function listStudentResultQuery() { | ||
export type ListStudentResultQuery = Readonly<{ | ||
language: string; | ||
}>; | ||
|
||
const studentResults = await studentResultRepository.list(); | ||
export function makeListStudentResultQuery({ studentResultRepository, db }: Pick<Dependencies, 'studentResultRepository' | 'db'>) { | ||
return async function listStudentResultQuery({ language }: ListStudentResultQuery) { | ||
|
||
return studentResults.map((studentResult) => map(studentResult)); | ||
const studentResults = await studentResultRepository.list({ language }); | ||
|
||
const enrichedStudentResults = await Promise.all(studentResults.map(async (studentResult) => { | ||
const classInfo = await db.renamedclass.findUnique({ | ||
where: { id: Number(studentResult.class_id) }, | ||
}); | ||
|
||
const enrichedStudentResult = { | ||
...studentResult, | ||
class: { | ||
id: String(studentResult.class_id), | ||
name: language === "vi" ? classInfo?.vi_name ?? '' : classInfo?.en_name ?? '', | ||
description: language === "vi" ? classInfo?.vi_description ?? '' : classInfo?.en_description ?? '', | ||
image: classInfo?.image ?? null, | ||
}, | ||
}; | ||
|
||
const studentResultDTO: StudentResultDTO = { | ||
id: enrichedStudentResult.id ?? null, | ||
class: { | ||
id: enrichedStudentResult.class.id, | ||
name: enrichedStudentResult.class.name ?? null, | ||
description: enrichedStudentResult.class.description ?? null, | ||
image: enrichedStudentResult.class.image ?? null, | ||
}, | ||
name: enrichedStudentResult.name ?? null, | ||
description: enrichedStudentResult.description ?? null, | ||
result_image: enrichedStudentResult.result_image ?? '', | ||
order: enrichedStudentResult.order ?? null, | ||
status: enrichedStudentResult.status, | ||
created_at: enrichedStudentResult.created_at?.toISOString() ?? null, | ||
updated_at: enrichedStudentResult.updated_at?.toISOString() ?? null, | ||
created_by: enrichedStudentResult.created_by ?? null, | ||
updated_by: enrichedStudentResult.updated_by ?? null, | ||
}; | ||
|
||
return studentResultDTO; | ||
})); | ||
|
||
return enrichedStudentResults.map((studentResult) => map(studentResult)); | ||
}; | ||
} |
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