'use strict';

var request = require('request');

const API_HOST = process.env.UI_API_URL;
const PRODUCTS_URL = '/products/{date}';
const MENU_URL = '/menus/{date}';
const CATEGORIES_URL = '/categories';

const HTTP_REQUEST_GET = 'GET';
const HTTP_REQUEST_POST = 'POST';

function ApiService() {
}

ApiService.prototype = {
    getSellingProducts: function (date) {
        return [
            {
                id: 1,
                name: "Produs 1",
                title: "Titlu produs 1"
            },
            {
                id: 2,
                name: "Produs 2",
                title: "Titlu produs 2"
            },
            {
                id: 3,
                name: "Produs 3",
                title: "Titlu produs 3"
            }
        ];
        var url = PRODUCTS_URL.replace('{data}', date);

        return this.request(url, HTTP_REQUEST_GET);
    },
    getProduct: function (id) {
        return {
            id: 1,
            name: "Produs 1",
            title: "Titlu produs 1"
        };
    },
    getSellingMenus: function (date) {
        var url = MENU_URL.replace('{data}', date);

        return this.request(url, HTTP_REQUEST_GET);
    },
    getSellingProductCategories: function () {
        return [
            {
                id: 1,
                name: "categorie 1",
                title: "Blab labla 1"
            },
            {
                id: 2,
                name: "categorie 2",
                title: "Titlu"
            }
        ];
        return this.request(CATEGORIES_URL, HTTP_REQUEST_GET);
    },
    getUrl: function (url) {
        return API_HOST + url;
    },
    request: function (url, method) {
        var options = {
            port: 80,
            method: method
        };
        request(this.getUrl(url), options, function (error, response, body) {
            if (!error && response.statusCode === 200) {
                return body;
            } else {
                console.log(error);
            }
        });
    }
};

module.exports.getInstance = function () {
    return new ApiService();
};
@@ -184,16 +184,20 @@
 URL = '/
+api/
 categori
@@ -198,16 +198,34 @@
 tegories
+/daily?date=%7Bdate%7D
 ';%0A%0Acons
@@ -1264,273 +1264,116 @@
     
-return %5B%0A            %7B%0A                id: 1,%0A                name: %22categorie 1%22,%0A                title: %22Blab labla 1%22%0A            %7D,%0A            %7B%0A                id: 2,%0A                name: %22categorie 2%22,%0A                title: %22Titlu%22%0A            %7D%0A        %5D;
+var date = new Date();%0A        var url = CATEGORIES_URL.replace('%7Bdata%7D', date.format(%22%25Y-%25m-%25d%22));%0A        
 %0A   
@@ -1397,30 +1397,19 @@
 request(
-CATEGORIES_URL
+url
 , HTTP_R

add categories api