import { DataSource } from 'typeorm';
import { JoinRequestEntity } from '../../../entities';
import { CreateJoinRequestCommand } from '../../types';

export async function handleCreateJoinRequest(command: CreateJoinRequestCommand, dataSource: DataSource): Promise<void> {
  const repo = dataSource.getRepository(JoinRequestEntity);
  const { request } = command.payload;
  const entity = repo.create({
    id: request.id,
    serverId: request.serverId,
    userId: request.userId,
    userPublicKey: request.userPublicKey,
    displayName: request.displayName,
    status: request.status,
    createdAt: request.createdAt
  });

  await repo.save(entity);
}
