import { Request, Response, NextFunction } from 'express'; import scanService from '../services/scanService'; import { PAGINATION } from '../utils/constants'; import { Marketplace } from '@prisma/client'; export class ScanController { async create(req: Request, res: Response, next: NextFunction) { try { const { marketplace, keyword, category, products } = req.body; const result = await scanService.createScan( req.user!.userId, marketplace as Marketplace, keyword, category, products ); res.status(201).json({ success: true, data: result }); } catch (error) { next(error); } } async getHistory(req: Request, res: Response, next: NextFunction) { try { const page = parseInt(req.query.page as string) || PAGINATION.defaultPage; const limit = Math.min( parseInt(req.query.limit as string) || PAGINATION.defaultLimit, PAGINATION.maxLimit ); const filters = { marketplace: req.query.marketplace as Marketplace | undefined, keyword: req.query.keyword as string | undefined, startDate: req.query.startDate as string | undefined, endDate: req.query.endDate as string | undefined, }; const result = await scanService.getScanHistory(req.user!.userId, page, limit, filters); res.json({ success: true, data: result }); } catch (error) { next(error); } } async getDetail(req: Request, res: Response, next: NextFunction) { try { const { id } = req.params; const result = await scanService.getScanDetail(req.user!.userId, id); res.json({ success: true, data: result }); } catch (error) { next(error); } } async getCount(req: Request, res: Response, next: NextFunction) { try { const count = await scanService.getUserScanCount(req.user!.userId); res.json({ success: true, data: { count } }); } catch (error) { next(error); } } } export default new ScanController();