File size: 926 Bytes
18b71c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { NextFunction, Request, Response } from "express";
import { recommendationService } from "../services/recommendation.service";
import { AppError } from "../utils/appError";

export const recommendationController = {
  generate(request: Request, response: Response, next: NextFunction) {
    try {
      if (!request.authUserId) {
        throw new AppError("Unauthorized.", 401);
      }

      const data = recommendationService.generate(request.authUserId);
      response.status(201).json({ success: true, data });
    } catch (error) {
      next(error);
    }
  },

  getLatest(request: Request, response: Response, next: NextFunction) {
    try {
      if (!request.authUserId) {
        throw new AppError("Unauthorized.", 401);
      }

      const data = recommendationService.getLatest(request.authUserId);
      response.json({ success: true, data });
    } catch (error) {
      next(error);
    }
  },
};