https://project.mdnd-it.cc/work_packages/94
This commit is contained in:
2025-08-23 04:25:28 +02:00
parent 725516ad6c
commit 19cfa031d0
25823 changed files with 1095587 additions and 2801760 deletions
@@ -0,0 +1,19 @@
export abstract class BaseMapper<TEntity, TShortDto, TDetailDto> {
abstract toShortDto(entity: TEntity): TShortDto;
abstract toDetailDto(entity: TEntity): TDetailDto;
toShortDtoList(entities: TEntity[]): TShortDto[] {
return entities.map(entity => this.toShortDto(entity));
}
toDetailDtoList(entities: TEntity[]): TDetailDto[] {
return entities.map(entity => this.toDetailDto(entity));
}
static toShortDtoListStatic<T, TDto>(
entities: T[],
mapperFn: (entity: T) => TDto
): TDto[] {
return entities.map(mapperFn);
}
}
@@ -0,0 +1,26 @@
import { ChatAggregate } from '../../../Domain/Chat/ChatAggregate';
import { ShortChatDto, DetailChatDto } from '../ChatDto';
export class ChatMapper {
static toShortDto(chat: ChatAggregate): ShortChatDto {
return {
id: chat.id,
userCount: chat.users?.length ?? 0,
state: chat.state,
};
}
static toDetailDto(chat: ChatAggregate): DetailChatDto {
return {
id: chat.id,
users: chat.users ?? [],
messages: chat.messages,
updateDate: chat.updateDate,
state: chat.state,
};
}
static toShortDtoList(chats: ChatAggregate[]): ShortChatDto[] {
return chats.map(this.toShortDto);
}
}
@@ -0,0 +1,36 @@
import { ContactAggregate } from '../../../Domain/Contact/ContactAggregate';
import { CreateContactDto, UpdateContactDto, ShortContactDto, DetailContactDto } from '../ContactDto';
export class ContactMapper {
static toShortDto(contact: ContactAggregate): ShortContactDto {
return {
id: contact.id,
name: contact.name,
email: contact.email,
type: contact.type,
createDate: contact.createDate,
state: contact.state,
};
}
static toDetailDto(contact: ContactAggregate): DetailContactDto {
return {
id: contact.id,
name: contact.name,
email: contact.email,
userid: contact.userid,
type: contact.type,
txt: contact.txt,
state: contact.state,
createDate: contact.createDate,
updateDate: contact.updateDate,
adminResponse: contact.adminResponse,
responseDate: contact.responseDate,
respondedBy: contact.respondedBy,
};
}
static toShortDtoList(contacts: ContactAggregate[]): ShortContactDto[] {
return contacts.map(this.toShortDto);
}
}
@@ -0,0 +1,31 @@
import { DeckAggregate } from '../../../Domain/Deck/DeckAggregate';
import { CreateDeckDto, UpdateDeckDto, ShortDeckDto, DetailDeckDto } from '../DeckDto';
export class DeckMapper {
static toShortDto(deck: DeckAggregate): ShortDeckDto {
return {
id: deck.id,
name: deck.name,
type: deck.type,
playedNumber: deck.playedNumber,
ctype: deck.ctype,
};
}
static toDetailDto(deck: DeckAggregate): DetailDeckDto {
return {
id: deck.id,
name: deck.name,
type: deck.type,
userid: deck.userid,
creationdate: deck.creationdate,
cards: deck.cards,
playedNumber: deck.playedNumber,
ctype: deck.ctype,
};
}
static toShortDtoList(decks: DeckAggregate[]): ShortDeckDto[] {
return decks.map(this.toShortDto);
}
}
@@ -0,0 +1,36 @@
import { OrganizationAggregate } from '../../../Domain/Organization/OrganizationAggregate';
import { CreateOrganizationDto, UpdateOrganizationDto, ShortOrganizationDto, DetailOrganizationDto } from '../OrganizationDto';
export class OrganizationMapper {
static toShortDto(org: OrganizationAggregate): ShortOrganizationDto {
return {
id: org.id,
name: org.name,
state: org.state,
userinorg: org.userinorg,
maxOrganizationalDecks: org.maxOrganizationalDecks,
};
}
static toDetailDto(org: OrganizationAggregate): DetailOrganizationDto {
return {
id: org.id,
name: org.name,
contactfname: org.contactfname,
contactlname: org.contactlname,
contactphone: org.contactphone,
contactemail: org.contactemail,
state: org.state,
regdate: org.regdate,
updatedate: org.updatedate,
url: org.url,
userinorg: org.userinorg,
maxOrganizationalDecks: org.maxOrganizationalDecks,
users: org.users?.map(u => u.id) ?? [],
};
}
static toShortDtoList(orgs: OrganizationAggregate[]): ShortOrganizationDto[] {
return orgs.map(this.toShortDto);
}
}
@@ -0,0 +1,33 @@
import { UserAggregate, UserState } from '../../../Domain/User/UserAggregate';
import { CreateUserDto, UpdateUserDto, ShortUserDto, DetailUserDto } from '../UserDto';
import { BaseMapper } from './BaseMapper';
export class UserMapper {
static toShortDto(user: UserAggregate): ShortUserDto {
return {
id: user.id,
username: user.username,
state: user.state,
authLevel: (user.state === UserState.ADMIN ? 1 : 0) as 0 | 1,
};
}
static toDetailDto(user: UserAggregate): DetailUserDto {
return {
id: user.id,
orgid: user.orgid,
username: user.username,
email: user.email,
fname: user.fname,
lname: user.lname,
code: user.token,
type: user.type,
phone: user.phone,
state: user.state,
};
}
static toShortDtoList(users: UserAggregate[]): ShortUserDto[] {
return BaseMapper.toShortDtoListStatic(users, UserMapper.toShortDto);
}
}