import { DataSource } from 'typeorm';
import { JoinRequestEntity } from '../../../entities';
import { GetJoinRequestByIdQuery } from '../../types';
import { rowToJoinRequest } from '../../mappers';

export async function handleGetJoinRequestById(query: GetJoinRequestByIdQuery, dataSource: DataSource) {
  const repo = dataSource.getRepository(JoinRequestEntity);
  const row = await repo.findOne({ where: { id: query.payload.requestId } });

  return row ? rowToJoinRequest(row) : null;
}
