File size: 1,112 Bytes
dfe11f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
 * Controladores del modulo de mercados.
 *
 * Responsabilidades:
 *   - list(req, res)   → listado paginado y filtrado de mercados activos.
 *   - getById(req, res) → detalle de un mercado por su ID nativo de Polymarket.
 *
 * Datos expuestos:
 *   - id, question, category, countryCode, yesPrice, noPrice,
 *     volumeEur, liquidityEur, status, closesAt, lastSynced.
 *
 * Errores:
 *   - 404 NOT_FOUND si el mercado no existe.
 */

import { ok } from '../utils/apiResponse.js';
import { marketsService } from './markets.service.js';

export const marketsController = {
  async list(req, res) {
    const { limit, offset, category, status } = req.query;
    const { data, total } = await marketsService.list({ limit, offset, category, status });
    ok(res, data, { total, limit, offset });
  },

  async getById(req, res) {
    const market = await marketsService.getById(req.params.id);
    ok(res, market);
  },

  async getPriceHistory(req, res) {
    const { interval } = req.query;
    const history = await marketsService.getPriceHistory(req.params.id, interval);
    ok(res, history);
  },
};