43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
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<void> {
|
|
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<void> {
|
|
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<void> {
|
|
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);
|
|
}
|
|
}
|