import { Express, Request } from 'express';
import { ProjectsResC } from './route-projects-type';

export const routeProjects = (app: Express) => {
    app.get('/get-projects', async (req, res) => {
        try {
            const data = await fetch(
                `${process.env.PROJECTS_API_URL || ''}/projects/updated/2025-07-29T12%3A30%3A00Z`,
                {
                    "headers": {
                        "accept": "application/json",
                        "accept-language": "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7"
                    },
                    "referrer": "http://172.28.214.84:8102/api/swagger-ui/index.html",
                    "body": null,
                    "method": "GET",
                    "mode": "cors",
                    "credentials": "include"
                }
            );
            const reJsonedData: unknown = await data.json();
            const checkedData = ProjectsResC.parse(reJsonedData);
            return res.json(checkedData.projects)
        } catch (e) {
            console.log(e);
            res.status(500).end();
        }

    });
}