import { DataSource } from 'typeorm';
import { UserEntity } from '../../../entities';
import { GetUserQuery } from '../../types';
import { rowToUser } from '../../mappers';

export async function handleGetUser(query: GetUserQuery, dataSource: DataSource) {
  const repo = dataSource.getRepository(UserEntity);
  const row = await repo.findOne({ where: { id: query.payload.userId } });

  return row ? rowToUser(row) : null;
}
