import { Request, Response, NextFunction } from 'express'; import { creaOTrovaLinkIngresso, getLinkIngressoPubblico, richiediIngresso } from '../services/linkIngresso.service'; import { HttpError } from '../errors'; export async function postLinkIngresso(req: Request, res: Response, next: NextFunction): Promise { try { const { orgId } = req.params; const { giaEsistente, ...result } = await creaOTrovaLinkIngresso(orgId, req.auth!.userId); res.status(giaEsistente ? 200 : 201).json(result); } catch (err) { next(err); } } export async function getLinkIngresso(req: Request, res: Response, next: NextFunction): Promise { try { const { token } = req.params; const link = await getLinkIngressoPubblico(token); if (!link) { throw new HttpError(404, 'Link di ingresso non trovato'); } res.json(link); } catch (err) { next(err); } } export async function postRichiediIngresso(req: Request, res: Response, next: NextFunction): Promise { try { const { token } = req.params; const result = await richiediIngresso(token, { userId: req.auth!.userId, email: req.auth!.email, }); res.status(201).json(result); } catch (err) { next(err); } }