import { DataSource } from 'typeorm';
import { ReactionEntity } from '../../../entities';
import { GetReactionsForMessageQuery } from '../../types';
import { rowToReaction } from '../../mappers';

export async function handleGetReactionsForMessage(query: GetReactionsForMessageQuery, dataSource: DataSource) {
  const repo = dataSource.getRepository(ReactionEntity);
  const rows = await repo.find({ where: { messageId: query.payload.messageId } });

  return rows.map(rowToReaction);
}
