19 lines
669 B
TypeScript
19 lines
669 B
TypeScript
import { DataSource } from 'typeorm';
|
|
import { MessageEntity } from '../../../entities';
|
|
import { GetMessageByIdQuery } from '../../types';
|
|
import { rowToMessage } from '../../mappers';
|
|
import { loadMessageReactionsMap } from '../../relations';
|
|
|
|
export async function handleGetMessageById(query: GetMessageByIdQuery, dataSource: DataSource) {
|
|
const repo = dataSource.getRepository(MessageEntity);
|
|
const row = await repo.findOne({ where: { id: query.payload.messageId } });
|
|
|
|
if (!row) {
|
|
return null;
|
|
}
|
|
|
|
const reactionsByMessageId = await loadMessageReactionsMap(dataSource, [row.id]);
|
|
|
|
return rowToMessage(row, reactionsByMessageId.get(row.id) ?? []);
|
|
}
|