summaryrefslogtreecommitdiff
path: root/examples/shop.js
blob: e75d2892e01600a05aa75ed2677e56a4bfe67ab6 (plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const database = require('../source/database')
const estore = database('EStore')

class Shop {
    constructor() {}

    async Main() {
        return estore.Query('SELECT * FROM Products').then(output => {
            const data = {
                start: `
                    <section id='shop'>
                    <div>
                    <h1>This is the Shop page</h1>
                `,
                body: '',
                end: `
                    </div>
                    </section>
                `
            }
            if (output) {
                for (let i = 0; i < output[0].length; i++) {
                    data.body += `
                        <div class='item'>
                        <h2>${output[0][i].ProductName}</h2>
                        <p>ID: ${output[0][i].ID}</p>
                        </div>
                    `
                }
            } else {
                data.body = `
                    There are no items in the database.
                `
            }
            return data.start + data.body + data.end
        })
    }
    Product() {
        const data = `
            <section id='product'>
            <div>
            <h1>This is the Product page</h1>
            <p>Description</p>
            </div>
            </section>
        `
        return data
    }
}

module.exports = () => {return new Shop()}