Skip to content

Commit

Permalink
#fix: thuanvv fix api
Browse files Browse the repository at this point in the history
  • Loading branch information
VanThuan76 committed Jan 11, 2025
1 parent c13b880 commit 31b5b45
Show file tree
Hide file tree
Showing 24 changed files with 324 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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,
name: 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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,
name: 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type HighlightClassDTO = Omit<ClassDTO, 'description' | 'content' | 'image' | 's
export function map(renamedClass: ClassEntity, language: string): HighlightClassDTO {
return {
id: renamedClass.id?.toString() || '',
title: language === 'vi' ? renamedClass.vi_name : renamedClass.en_name,
name: language === 'vi' ? renamedClass.vi_name : renamedClass.en_name,
order: renamedClass.order || null,
};
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConfigSystem } from '@domain/entities';
import { CoreSystemConfigEntity } from '@domain/entities';

export interface ConfigSystemsRepository {
website(): Promise<{ data: Array<ConfigSystem> }>;
registration(): Promise<{ data: Array<ConfigSystem> }>;
export interface CoreSystemConfigsRepository {
website(): Promise<CoreSystemConfigEntity[] | []>;
registration(): Promise<CoreSystemConfigEntity[] | []>;
}
1 change: 1 addition & 0 deletions src/application/common/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export * from './lecture-types-repository';
export * from './feedbacks-repository';
export * from './news-categories-repository';
export * from './news-repository';
export * from './core-system-configs-repository';
11 changes: 11 additions & 0 deletions src/application/core-system-config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { makeGetWebsiteQuery } from "./queries/get-website";
import { makeGetRegistrationQuery } from "./queries/get-registration";

export function makeCoreSystemConfigsUseCases(dependencies: Dependencies) {
return {
queries: {
getWebsite: makeGetWebsiteQuery(dependencies),
getRegistration: makeGetRegistrationQuery(dependencies),
},
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { CoreSystemConfigEntity } from "@domain/entities";
import { CoreSystemConfigDTO } from "@domain/dtos/core-system-config";

export function map(coreSystemConfig: CoreSystemConfigEntity): CoreSystemConfigDTO {
return {
id: Number(coreSystemConfig.id),
group: coreSystemConfig.group,
type: coreSystemConfig.type,
value: coreSystemConfig.value,
image: coreSystemConfig.image || "",
description_vi: coreSystemConfig.description_vi || "",
description_en: coreSystemConfig.description_en || "",
order: Number(coreSystemConfig.order),
block_delete: coreSystemConfig.block_delete || 0,
status: Number(coreSystemConfig.status),
created_at: coreSystemConfig.created_at?.toISOString() || null,
updated_at: coreSystemConfig.updated_at?.toISOString() || null,
created_by: coreSystemConfig.created_by || "",
updated_by: coreSystemConfig.updated_by || ""
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { map } from "./get-registration-query-mapper";

export function makeGetRegistrationQuery({ coreSystemConfigsRepository }: Pick<Dependencies, 'coreSystemConfigsRepository'>) {
return async function getRegistrationQuery() {

const coreRegistrationSystemConfig = await coreSystemConfigsRepository.registration();

return coreRegistrationSystemConfig.map((item) => map(item));
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './get-registration-query';
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { CoreSystemConfigEntity } from "@domain/entities";
import { CoreSystemConfigDTO } from "@domain/dtos/core-system-config";

export function map(coreSystemConfig: CoreSystemConfigEntity): CoreSystemConfigDTO {
return {
id: Number(coreSystemConfig.id),
group: coreSystemConfig.group,
type: coreSystemConfig.type,
value: coreSystemConfig.value,
image: coreSystemConfig.image || "",
description_vi: coreSystemConfig.description_vi || "",
description_en: coreSystemConfig.description_en || "",
order: Number(coreSystemConfig.order),
block_delete: coreSystemConfig.block_delete || 0,
status: Number(coreSystemConfig.status),
created_at: coreSystemConfig.created_at?.toISOString() || null,
updated_at: coreSystemConfig.updated_at?.toISOString() || null,
created_by: coreSystemConfig.created_by || "",
updated_by: coreSystemConfig.updated_by || ""
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { map } from "./get-website-query-mapper";

export function makeGetWebsiteQuery({ coreSystemConfigsRepository }: Pick<Dependencies, 'coreSystemConfigsRepository'>) {
return async function getWebsiteQuery() {

const coreWebsiteSystemConfig = await coreSystemConfigsRepository.website();

return coreWebsiteSystemConfig.map((item) => map(item));
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './get-website-query';
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function map(news: NewsEntity, language: string): NewsDTO {
read_time: news.read_time || 1,
title: language === 'vi' ? news.vi_title || '' : news.en_title || '',
description: language === 'vi' ? news.vi_description || '' : news.en_description || '',
content: language === 'vi' ? news.vi_content || '' : news.en_content || '',
order: news.order || null,
status: news.status,
created_at: news.created_at ? news.created_at.toISOString() : null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function map(news: NewsEntity, language: string): NewsDTO {
read_time: news.read_time || 1,
title: language === 'vi' ? news.vi_title || '' : news.en_title || '',
description: language === 'vi' ? news.vi_description || '' : news.en_description || '',
content: language === 'vi' ? news.vi_content || '' : news.en_content || '',
order: news.order || null,
status: news.status,
created_at: news.created_at ? news.created_at.toISOString() : null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function map(news: NewsEntity, language: string): NewsDTO {
read_time: news.read_time || 1,
title: language === 'vi' ? news.vi_title || '' : news.en_title || '',
description: language === 'vi' ? news.vi_description || '' : news.en_description || '',
content: language === 'vi' ? news.vi_content || '' : news.en_content || '',
order: news.order || null,
status: news.status,
created_at: news.created_at ? news.created_at.toISOString() : null,
Expand Down
2 changes: 1 addition & 1 deletion src/domain/dtos/class.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface ClassDTO {
id: string;
title: string;
name: string;
description: string;
content: string;
image: string | null;
Expand Down
16 changes: 16 additions & 0 deletions src/domain/dtos/core-system-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export interface CoreSystemConfigDTO {
id: number;
group: string;
type: string;
value: string;
image: null | string;
description_vi: string;
description_en: string;
order: number;
block_delete: number;
status: number;
created_at: string | null;
updated_at: string | null;
created_by: string | null;
updated_by: string | null;
}
1 change: 1 addition & 0 deletions src/domain/dtos/news.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface NewsDTO {
read_time: number;
image: string;
title: string | null;
content: string | null;
description: string | null;
order: number | null;
status: number;
Expand Down
66 changes: 33 additions & 33 deletions src/domain/entities/core-system-config.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
export class ConfigSystem {
export class CoreSystemConfigEntity {
public id?: number;
public group: string;
public type: string;
public value: string;
public image?: string;
public descriptionVi: string;
public descriptionEn?: string;
public order?: number;
public blockDelete?: boolean;
public status?: boolean;
public createdAt?: Date;
public updatedAt?: Date;
public createdBy?: string;
public updatedBy?: string;
public image?: string | null;
public description_vi: string;
public description_en?: string | null;
public order?: number | null;
public block_delete?: number | null;
public status?: boolean | null;
public created_at?: Date | null;
public updated_at?: Date | null;
public created_by?: string | null;
public updated_by?: string | null;

constructor(config: {
constructor(coreSystemConfigEntity: {
id?: number;
group: string;
type: string;
value: string;
image?: string;
descriptionVi: string;
descriptionEn?: string;
description_vi: string;
description_en?: string;
order?: number;
blockDelete?: boolean;
block_delete?: number;
status?: boolean;
createdAt?: Date;
updatedAt?: Date;
createdBy?: string;
updatedBy?: string;
created_at?: Date;
updated_at?: Date;
created_by?: string;
updated_by?: string;
}) {
this.id = config.id;
this.group = config.group;
this.type = config.type;
this.value = config.value;
this.image = config.image;
this.descriptionVi = config.descriptionVi;
this.descriptionEn = config.descriptionEn;
this.order = config.order;
this.blockDelete = config.blockDelete;
this.status = config.status;
this.createdAt = config.createdAt;
this.updatedAt = config.updatedAt;
this.createdBy = config.createdBy;
this.updatedBy = config.updatedBy;
this.id = coreSystemConfigEntity.id;
this.group = coreSystemConfigEntity.group;
this.type = coreSystemConfigEntity.type;
this.value = coreSystemConfigEntity.value;
this.image = coreSystemConfigEntity.image;
this.description_vi = coreSystemConfigEntity.description_vi;
this.description_en = coreSystemConfigEntity.description_en;
this.order = coreSystemConfigEntity.order;
this.block_delete = coreSystemConfigEntity.block_delete;
this.status = coreSystemConfigEntity.status;
this.created_at = coreSystemConfigEntity.created_at;
this.updated_at = coreSystemConfigEntity.updated_at;
this.created_by = coreSystemConfigEntity.created_by;
this.updated_by = coreSystemConfigEntity.updated_by;
}
}
2 changes: 2 additions & 0 deletions src/infrastructure/di.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type Dependencies = {
lecturersRepository: Interfaces.LecturersRepository;
newsCategoriesRepository: Interfaces.NewsCategoriesRepository;
newsRepository: Interfaces.NewsRepository;
coreSystemConfigsRepository: Interfaces.CoreSystemConfigsRepository
};

export function makeInfrastructureDependencies(): {
Expand Down Expand Up @@ -52,5 +53,6 @@ export function makeInfrastructureDependencies(): {
lecturersRepository: asFunction(repositories.makeLecturersRepository).singleton(),
newsCategoriesRepository: asFunction(repositories.makeNewsCategoriesRepository).singleton(),
newsRepository: asFunction(repositories.makeNewsRepository).singleton(),
coreSystemConfigsRepository: asFunction(repositories.makeCoreSystemConfigRepository).singleton(),
};
}
43 changes: 43 additions & 0 deletions src/infrastructure/repositories/core-system-config-repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { CoreSystemConfigsRepository } from '@application/common/interfaces';

export function makeCoreSystemConfigRepository({ db }: Dependencies): CoreSystemConfigsRepository {
return {
async website() {
const coreSystemConfig = await db.core_system_config.findMany({
where: {
group: 'Website',
type: 'Footer',
status: 1,
},
orderBy: {
order: 'asc',
},
});

return coreSystemConfig.map((config) => ({
...config,
status: config.status === 1,
id: Number(config.id),
}));
},


async registration() {
const coreSystemConfig = await db.core_system_config.findMany({
where: {
group: 'Registration',
status: 1,
},
orderBy: {
order: 'asc',
},
});

return coreSystemConfig.map((config) => ({
...config,
status: config.status === 1,
id: Number(config.id),
}));
},
};
}
1 change: 1 addition & 0 deletions src/infrastructure/repositories/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './lecture-type-repository';
export * from './lecturer-repository';
export * from './news-categories-repository';
export * from './news-repository';
export * from './core-system-config-repository';
Loading

0 comments on commit 31b5b45

Please sign in to comment.