Refactor 4 with bugfixes
This commit is contained in:
46
server/src/cqrs/mappers.ts
Normal file
46
server/src/cqrs/mappers.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { AuthUserEntity } from '../entities/AuthUserEntity';
|
||||
import { ServerEntity } from '../entities/ServerEntity';
|
||||
import { JoinRequestEntity } from '../entities/JoinRequestEntity';
|
||||
import {
|
||||
AuthUserPayload,
|
||||
ServerPayload,
|
||||
JoinRequestPayload
|
||||
} from './types';
|
||||
|
||||
export function rowToAuthUser(row: AuthUserEntity): AuthUserPayload {
|
||||
return {
|
||||
id: row.id,
|
||||
username: row.username,
|
||||
passwordHash: row.passwordHash,
|
||||
displayName: row.displayName,
|
||||
createdAt: row.createdAt
|
||||
};
|
||||
}
|
||||
|
||||
export function rowToServer(row: ServerEntity): ServerPayload {
|
||||
return {
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
description: row.description ?? undefined,
|
||||
ownerId: row.ownerId,
|
||||
ownerPublicKey: row.ownerPublicKey,
|
||||
isPrivate: !!row.isPrivate,
|
||||
maxUsers: row.maxUsers,
|
||||
currentUsers: row.currentUsers,
|
||||
tags: JSON.parse(row.tags || '[]'),
|
||||
createdAt: row.createdAt,
|
||||
lastSeen: row.lastSeen
|
||||
};
|
||||
}
|
||||
|
||||
export function rowToJoinRequest(row: JoinRequestEntity): JoinRequestPayload {
|
||||
return {
|
||||
id: row.id,
|
||||
serverId: row.serverId,
|
||||
userId: row.userId,
|
||||
userPublicKey: row.userPublicKey,
|
||||
displayName: row.displayName,
|
||||
status: row.status as JoinRequestPayload['status'],
|
||||
createdAt: row.createdAt
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user