-
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
39809c6
commit e1eab43
Showing
140 changed files
with
3,443 additions
and
489 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { makeGetClassByIdQuery } from "./queries/get-class-by-id"; | ||
import { makeListHightlightClassesQuery } from "./queries/list-highlight-classes"; | ||
import { makeListShortClassesQuery } from "./queries/list-short-classes"; | ||
|
||
export function makeClassessUseCases(dependencies: Dependencies) { | ||
return { | ||
queries: { | ||
listHightlightClasses: makeListHightlightClassesQuery(dependencies), | ||
listShortClasses: makeListShortClassesQuery(dependencies), | ||
getClassById: makeGetClassByIdQuery(dependencies), | ||
}, | ||
}; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/application/classes/queries/get-class-by-id/get-class-by-id-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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { ClassDTO } from "@domain/dtos/class"; | ||
import { ClassEntity } from "@domain/entities"; | ||
|
||
export function map(renamedClass: ClassEntity, language: string): ClassDTO { | ||
return { | ||
id: renamedClass.id?.toString() || '', | ||
title: language === 'vi' ? renamedClass.vi_name : renamedClass.en_name, | ||
description: language === 'vi' ? renamedClass.vi_description || '' : renamedClass.en_description || '', | ||
content: language === 'vi' ? renamedClass.vi_content || '' : renamedClass.en_content || '', | ||
image: renamedClass.image || null, | ||
order: renamedClass.order || null, | ||
status: renamedClass.status, | ||
created_at: renamedClass.created_at?.toISOString() || null, | ||
updated_at: renamedClass.updated_at?.toISOString() || null, | ||
created_by: renamedClass.created_by || null, | ||
updated_by: renamedClass.updated_by || null, | ||
}; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/application/classes/queries/get-class-by-id/get-class-by-id-query-validator.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,17 @@ | ||
import { ValidationException } from '@application/common/exceptions'; | ||
import { ZodError, z } from 'zod'; | ||
|
||
import { GetClassByIdQuery } from './get-class-by-id-query'; | ||
|
||
export async function validate(query: GetClassByIdQuery) { | ||
try { | ||
const schema: z.ZodType<GetClassByIdQuery> = z.object({ | ||
language: z.string(), | ||
id: z.string() | ||
}); | ||
|
||
await schema.parseAsync(query); | ||
} catch (error) { | ||
throw new ValidationException(error as ZodError); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/application/classes/queries/get-class-by-id/get-class-by-id-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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { map } from "./get-class-by-id-query-mapper"; | ||
import { validate } from "./get-class-by-id-query-validator"; | ||
|
||
export type GetClassByIdQuery = Readonly<{ | ||
language: string; | ||
id: string | ||
}>; | ||
|
||
export function makeGetClassByIdQuery({ classesRepository }: Pick<Dependencies, 'classesRepository'>) { | ||
return async function getClassByIdQuery(query: GetClassByIdQuery) { | ||
await validate(query); | ||
|
||
const { language, id } = query; | ||
|
||
const renamedClass = await classesRepository.getById({ language, id }); | ||
|
||
return renamedClass ? map(renamedClass, language) : null; | ||
}; | ||
} |
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 @@ | ||
export * from './get-class-by-id-query'; |
1 change: 1 addition & 0 deletions
1
src/application/classes/queries/list-highlight-classes/index.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 @@ | ||
export * from './list-highlight-classes-query'; |
18 changes: 18 additions & 0 deletions
18
...application/classes/queries/list-highlight-classes/list-highlight-classes-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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { ClassDTO } from "@domain/dtos/class"; | ||
import { ClassEntity } from "@domain/entities"; | ||
|
||
export function map(renamedClass: ClassEntity, language: string): ClassDTO { | ||
return { | ||
id: renamedClass.id?.toString() || '', | ||
title: language === 'vi' ? renamedClass.vi_name : renamedClass.en_name, | ||
description: language === 'vi' ? renamedClass.vi_description || '' : renamedClass.en_description || '', | ||
content: language === 'vi' ? renamedClass.vi_content || '' : renamedClass.en_content || '', | ||
image: renamedClass.image || null, | ||
order: renamedClass.order || null, | ||
status: renamedClass.status, | ||
created_at: renamedClass.created_at?.toISOString() || null, | ||
updated_at: renamedClass.updated_at?.toISOString() || null, | ||
created_by: renamedClass.created_by || null, | ||
updated_by: renamedClass.updated_by || null, | ||
}; | ||
} |
18 changes: 18 additions & 0 deletions
18
...lication/classes/queries/list-highlight-classes/list-highlight-classes-query-validator.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,18 @@ | ||
import { ValidationException } from '@application/common/exceptions'; | ||
import { ZodError, z } from 'zod'; | ||
|
||
import { ListHightlightClassesQuery } from './list-highlight-classes-query'; | ||
|
||
export async function validate(query: ListHightlightClassesQuery) { | ||
try { | ||
const schema: z.ZodType<ListHightlightClassesQuery> = z.object({ | ||
language: z.string(), | ||
size: z.number().optional(), | ||
page: z.number().optional() | ||
}); | ||
|
||
await schema.parseAsync(query); | ||
} catch (error) { | ||
throw new ValidationException(error as ZodError); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/application/classes/queries/list-highlight-classes/list-highlight-classes-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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { map } from "./list-highlight-classes-query-mapper"; | ||
import { validate } from "./list-highlight-classes-query-validator"; | ||
|
||
export type ListHightlightClassesQuery = Readonly<{ | ||
language: string; | ||
size?: number; | ||
page?: number | ||
}>; | ||
|
||
export function makeListHightlightClassesQuery({ classesRepository }: Pick<Dependencies, 'classesRepository'>) { | ||
return async function listHightlightClassesQuery(query: ListHightlightClassesQuery) { | ||
await validate(query); | ||
|
||
const { language, size, page } = query; | ||
|
||
const { data, total } = await classesRepository.getHighlightClasses({ language, size, page }); | ||
|
||
const per_page = size; | ||
const current_page = page; | ||
const last_page = total && per_page ? Math.ceil(total / per_page) : 1; | ||
|
||
return { | ||
data: data.map((classItem) => map(classItem, language)), | ||
total, | ||
per_page, | ||
current_page, | ||
last_page, | ||
} | ||
}; | ||
} |
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 @@ | ||
export * from './list-short-classes-query'; |
12 changes: 12 additions & 0 deletions
12
src/application/classes/queries/list-short-classes/list-short-classes-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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ClassDTO } from "@domain/dtos/class"; | ||
import { ClassEntity } from "@domain/entities"; | ||
|
||
type HighlightClassDTO = Omit<ClassDTO, 'description' | 'content' | 'image' | 'status' | 'created_at' | 'updated_at' | 'created_by' | 'updated_by'>; | ||
|
||
export function map(renamedClass: ClassEntity, language: string): HighlightClassDTO { | ||
return { | ||
id: renamedClass.id?.toString() || '', | ||
title: language === 'vi' ? renamedClass.vi_name : renamedClass.en_name, | ||
order: renamedClass.order || null, | ||
}; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/application/classes/queries/list-short-classes/list-short-classes-query-validator.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,16 @@ | ||
import { ValidationException } from '@application/common/exceptions'; | ||
import { ZodError, z } from 'zod'; | ||
|
||
import { ListShortClassesQuery } from './list-short-classes-query'; | ||
|
||
export async function validate(query: ListShortClassesQuery) { | ||
try { | ||
const schema: z.ZodType<ListShortClassesQuery> = z.object({ | ||
language: z.string(), | ||
}); | ||
|
||
await schema.parseAsync(query); | ||
} catch (error) { | ||
throw new ValidationException(error as ZodError); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/application/classes/queries/list-short-classes/list-short-classes-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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { map } from "./list-short-classes-query-mapper"; | ||
import { validate } from "./list-short-classes-query-validator"; | ||
|
||
export type ListShortClassesQuery = Readonly<{ | ||
language: string; | ||
}>; | ||
|
||
export function makeListShortClassesQuery({ classesRepository }: Pick<Dependencies, 'classesRepository'>) { | ||
return async function listShortClassesQuery(query: ListShortClassesQuery) { | ||
await validate(query); | ||
|
||
const { language } = query; | ||
|
||
const classes = await classesRepository.getListShort({ language }); | ||
|
||
return classes.map((classItem) => map(classItem, language)); | ||
}; | ||
} |
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,11 @@ | ||
import { Class } from '@domain/entities'; | ||
import { ClassEntity } from '@domain/entities'; | ||
|
||
export interface ClassesRepository { | ||
highLight(): Promise<{ data: Array<Class> }>; | ||
listShort(): Promise<{ data: Array<Class> }>; | ||
getById(parameters: { language: string, page_id: string }): Promise<Class | null>; | ||
getHighlightClasses(params: { | ||
language: string; | ||
size?: number; | ||
page?: number | ||
}): Promise<{ data: Array<ClassEntity>, total: number } | { data: [], total: null }>; | ||
getListShort(params: { language: string }): Promise<Array<ClassEntity> | []>; | ||
getById(params: { language: string, id: string }): Promise<ClassEntity | null>; | ||
} |
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 { Component } from '@domain/entities'; | ||
import { ComponentEntity } from '@domain/entities'; | ||
|
||
export interface ComponentsRepository { | ||
getBySection(parameters: { language: string, section_id: string }): Promise<Component | null>; | ||
getBySection(parameters: { language: string, section_id: string }): Promise<Array<ComponentEntity> | []>; | ||
} |
4 changes: 2 additions & 2 deletions
4
src/application/common/interfaces/document-types-repository.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,5 +1,5 @@ | ||
import { DocumentType } from '@domain/entities'; | ||
import { DocumentTypeEntity } from '@domain/entities'; | ||
|
||
export interface DocumentTypesRepository { | ||
list(): Promise<{ data: Array<DocumentType> }>; | ||
list(params: { language: string }): Promise<Array<DocumentTypeEntity>>; | ||
} |
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,6 +1,6 @@ | ||
import { Document } from '@domain/entities'; | ||
import { DocumentEntity } from '@domain/entities'; | ||
|
||
export interface DocumentsRepository { | ||
getById(parameters: { language: string, id: number }): Promise<{ data: Array<Document> }>; | ||
getByDocumentType(parameters: { language: string, document_type_id: number, size: number, page: number }): Promise<{ data: Array<Document> }>; | ||
getById(params: { language: string, id: number }): Promise<DocumentEntity | null>; | ||
getByDocumentType(params: { language: string, document_type_id: number, size?: number; page?: number }): Promise<{ data: Array<DocumentEntity>, total: number } | { data: [], total: null }>; | ||
} |
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,9 @@ | ||
import { Feedback } from '@domain/entities'; | ||
import { FeedbackEntity } from '@domain/entities'; | ||
|
||
export interface FeedbacksRepository { | ||
list(): Promise<{ data: Array<Feedback> }>; | ||
list(params: { | ||
language: string; | ||
size?: number; | ||
page?: number | ||
}): Promise<{ data: Array<FeedbackEntity>, total: number } | { data: [], total: null }>; | ||
} |
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
4 changes: 2 additions & 2 deletions
4
src/application/common/interfaces/lecture-types-repository.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,5 +1,5 @@ | ||
import { LectureType } from '@domain/entities'; | ||
import { LectureTypeEntity } from '@domain/entities'; | ||
|
||
export interface LectureTypesRepository { | ||
list(): Promise<{ data: Array<LectureType> }>; | ||
list(params: { language: string }): Promise<Array<LectureTypeEntity>>; | ||
} |
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,9 @@ | ||
import { Lecturer } from '@domain/entities'; | ||
import { LecturerEntity } from '@domain/entities'; | ||
|
||
export interface LecturersRepository { | ||
list(): Promise<{ data: Array<Lecturer> }>; | ||
list(params: { | ||
language: string; | ||
size?: number; | ||
page?: number | ||
}): Promise<{ data: Array<LecturerEntity>, total: number } | { data: [], total: null }>; | ||
} |
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,6 +1,6 @@ | ||
import { Lecture } from '@domain/entities'; | ||
import { LectureEntity } from '@domain/entities'; | ||
|
||
export interface LecturesRepository { | ||
getByLectureType(parameters: { language: string, lecture_type_id: number, size: number, page: number }): Promise<{ data: Array<Lecture> }>; | ||
getById(parameters: { language: string, id: number }): Promise<Lecture | null>; | ||
getByLectureType(params: { language: string, lecture_type_id: number, size?: number, page?: number }): Promise<{ data: Array<LectureEntity>, total: number } | { data: [], total: null }>; | ||
getById(params: { language: string, id: number }): Promise<LectureEntity | null>; | ||
} |
6 changes: 3 additions & 3 deletions
6
src/application/common/interfaces/news-categories-repository.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,5 +1,5 @@ | ||
import { NewsCategory } from '@domain/entities'; | ||
import { NewsCategoryEntity } from '@domain/entities'; | ||
|
||
export interface NewsCategorysRepository { | ||
list(): Promise<{ data: Array<NewsCategory> }>; | ||
export interface NewsCategoriesRepository { | ||
list(params: { language: string; }): Promise<Array<NewsCategoryEntity> | null>; | ||
} |
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,7 @@ | ||
import { News } from '@domain/entities'; | ||
import { NewsEntity } from '@domain/entities'; | ||
|
||
export interface NewssRepository { | ||
getRelated(parameters: { language: string, news_category_id: string, size: number, id: number }): Promise<{ data: Array<News> }>; | ||
getByCategory(parameters: { language: string, news_category_id: string, size: number, page: number }): Promise<{ data: Array<News> }>; | ||
getBySlug(parameters: { language: string, slug: string }): Promise<News | null>; | ||
export interface NewsRepository { | ||
getRelated(params: { language: string, news_category_id: number, size?: number, page?: number, id: number }): Promise<{ data: Array<NewsEntity>, total: number } | { data: [], total: null }>; | ||
getByCategory(params: { language: string, news_category_id: number, size?: number, page?: number }): Promise<{ data: Array<NewsEntity>, total: number } | { data: [], total: null }>; | ||
getBySlug(params: { language: string, slug: string }): Promise<NewsEntity | null>; | ||
} |
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,6 +1,6 @@ | ||
import { Section } from '@domain/entities'; | ||
import { SectionEntity } from "@domain/entities"; | ||
|
||
export interface SectionsRepository { | ||
getByPage(parameters: { language: string, page_id: string }): Promise<{ data: Array<Section> }>; | ||
getByPageUrl(parameters: { language: string, url: string }): Promise<{ data: Array<Section> }>; | ||
getByPage(parameters: { language: string, page_id: string }): Promise<Array<SectionEntity> | []>; | ||
getByPageUrl(parameters: { language: string, url: string }): Promise<Array<SectionEntity> | []>; | ||
} |
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,26 +1,30 @@ | ||
export default class ResponseBase { | ||
static formatCountResponse<T>(data: T, perPage: number, total: number) { | ||
static formatPaginationResponse<T>(status_code: number, data: T, total: number, per_page: number, current_page: number, last_page: number, message: string) { | ||
return { | ||
content: data, | ||
totalElements: perPage, | ||
totalPages: total, | ||
status_code, | ||
data, | ||
total, | ||
per_page, | ||
current_page, | ||
last_page, | ||
message, | ||
}; | ||
} | ||
|
||
static formatBaseResponse<T>(statusCode: number, data: T, message: string) { | ||
static formatBaseResponse<T>(status_code: number, data: T, message: string) { | ||
return { | ||
statusCode: statusCode, | ||
data: data, | ||
message: message, | ||
status_code, | ||
data, | ||
message, | ||
}; | ||
} | ||
|
||
static formatBaseResponseWithTotal<T>(statusCode: number, data: T, total: number, message: string) { | ||
static formatBaseResponseWithTotal<T>(status_code: number, data: T, total: number, message: string) { | ||
return { | ||
statusCode: statusCode, | ||
data: data, | ||
total: total, | ||
message: message, | ||
status_code, | ||
data, | ||
total, | ||
message, | ||
}; | ||
} | ||
} |
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,9 @@ | ||
import { makeComponentGetBySection } from "./queries/get-by-section"; | ||
|
||
export function makeComponentsUseCases(dependencies: Dependencies) { | ||
return { | ||
queries: { | ||
listComponentsBySection: makeComponentGetBySection(dependencies), | ||
}, | ||
}; | ||
} |
Oops, something went wrong.