Skip to content

The goal of this project is to create a website that helps customers find the best prices for buckwheat.

License

Notifications You must be signed in to change notification settings

mezidia/grechka.com

Repository files navigation

Grechka.com

Language

Hello everyone! This is the repository of the site grechka.com. Visit grechka.com here!

Table of contents

Motivation

The goal of this project is to create a website that helps customers find the best prices for buckwheat.

Build status

Here you can see build status of continuous integration:

Lint Code Base

Badges

Other badges

Theme Platform

Code style

We are using Codacy to automate our code quality.

Codacy Badge

Screenshots

  • Main page

Screenshot 1

  • Filters

Screenshot 2

  • Show products with filters

Screenshot 3

  • About page

Screenshot 4

  • Filters on adaptive screen

Screenshot 5

Tech/framework used

Built with

Features

On the site you can find the cheapest buckwheat, sort by price segment, by price, by weight, in direct and reverse order and get the lowest price in recent times.

Code Example

  • Product schema
const mongoose = require('mongoose');

const productSchema = mongoose.Schema({
  productName: String,
  categoryId: mongoose.Schema.Types.ObjectId,
  manufacturerId: mongoose.Schema.Types.ObjectId,
  weight: Number,
  price: Number,
  priceSegment: String,
  productURL: String,
  productImgURL: String,
  description: String,
});
  • Server
'use strict';

const http = require('http');
const FileManager = require('./fileManager').FileManager;
const Database = require('./Database').Database;
const config = require('./config.json');
const setNewProduct = require('./setNewProduct').setNewProduct;
const minPriceByDay = require('./minPriceByDay').minPriceByDay;
const fileManager = new FileManager();
const dbVar = config.development.database;
const db = new Database(dbVar);

//types of request extensions
const mime = {
  'html': 'text/html',
  'js': 'application/javascript',
  'css': 'text/css',
  'png': 'image/png',
  'ico': 'image/x-icon',
  '/date': 'text/plain',
  '/getProdData': 'text/plain',
  'svg': 'image/svg+xml',
};

class Server {
  constructor(port) {
    const server = http.createServer();
    server.listen(port, () => {
      console.log('Server running on port: ' + port);
    });
    server.on('request', this.handleRequest);
  }

  //function for handling requests
  async handleRequest(req, res) {
    let data = null;
    const url = req.url;
    let name = url;
    const method = req.method;
    let extention = url.split('.')[1];
    if (method === 'GET') {
      if (url === '/') {
        extention = 'html';
        name = '/public/index.html';
      } else if (url === '/about') {
        extention = 'html';
        name = '/public/about.html';
      } else if (url === '/getProdData') {
        console.log('/getProdData');
        data = [];
        const products = await db.getAllByTableName('Product');
        for (const product of products) {
          const category = (await db.find('Category', { _id: product.categoryId })).categoryType;
          const isCompanyName = (await db.find('Manufacturer', { _id: product.manufacturerId }));
          if (isCompanyName) {
            data.push(setNewProduct(product, category, isCompanyName.companyName));
          } else {
            data.push(setNewProduct(product, category));
          }
        }
        console.log(data);
        data = JSON.stringify(data);
      } else if (url === '/getGraphicData') {
        console.log('/getGraphicData');
        const history = await db.getAllByTableName('History');
        data = JSON.stringify(minPriceByDay(history));
      }
      const typeAns = mime[extention];
      if (!data) data = await fileManager.readFile('.' + name);
      if (!data) {
        console.log('no such file => ' + name);
        //handle if no page
        const pageNotFound = await fileManager.readFile('./public/pageNotFound.html');
        res.writeHead(404, { 'Content-Type': 'text/html; charset=utf-8' });
        res.write(pageNotFound);
      } else if (typeof data === 'number') {
        console.log('error occured => ' + name);
        res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
      } else {
        res.writeHead(200, { 'Content-Type': `${typeAns}; charset=utf-8` });
        res.write(data);
      }
      res.end();
    } else if (method === 'POST') {
      console.log('POST');
    }
  }
}

module.exports = { Server };

Fast usage

Just open the link in the description and enjoy your pastime.

Contribute

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Also look at the CONTRIBUTING.md.

License

MIT © mezidia

About

The goal of this project is to create a website that helps customers find the best prices for buckwheat.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •