methods.js 2.44 KB
Newer Older
Rosanny Sihombing's avatar
Rosanny Sihombing committed
1
const dbconn = require('../config/dbconn');
Rosanny Sihombing's avatar
Rosanny Sihombing committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

var methods = {
    // test method
	currentDate: function() {
		console.log('Current Date is: ' + new Date().toISOString().slice(0, 10));
    },
    // ===================== user db =====================
    getUserIdByEmail: function(email, callback) {
        var userId
        dbconn.user.query('SELECT id FROM user WHERE email = "' +email+'"', function (err, rows, fields) {
            if (err) {
                throw err;
            }
            else {
                if ( rows.length > 0) {
                    userId = rows[0].id;
                }
            }
            callback(userId, err);
        });
    },
Rosanny Sihombing's avatar
Rosanny Sihombing committed
23
/*
Rosanny Sihombing's avatar
Rosanny Sihombing committed
24
25
26
27
28
29
    getUserProjectRole: function(userId, callback) {
        dbconn.user.query('SELECT project_id, role_id FROM user_project_role WHERE user_id = "' +userId+'"', function (err, rows, fields) {
            if (err) throw err;
            callback(rows, err);
        });
    },
Rosanny Sihombing's avatar
Rosanny Sihombing committed
30
    */
Rosanny Sihombing's avatar
Rosanny Sihombing committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
    addUserProjectRole: function(data, callback) {
        dbconn.user.query('INSERT INTO user_project_role SET ?', data, function (err, results, fields){
            if (err) throw err;
            callback(err);
        })
    },
    // ======================= project db =======================
    getAllProjects: function(callback) {
        dbconn.project.query('CALL getAllprojects', function (err, rows, fields){
            if (err) throw err;
            callback(rows[0], err);
        })
    },
    getAllMailinglists: function(callback) {
        dbconn.project.query('CALL getAllLists', function (err, rows, fields){
            if (err) throw err;
            callback(rows[0], err);
	    })
    },
    getProjectOverviewById: function(projectId, callback) {
        dbconn.project.query('CALL GetProjectInformationByProjectID(' + projectId+ ')', function (err, rows, fields){
            if (err) throw err;
            callback(rows[0], err);
    	})
    },
    getProjectImagesById: function(projectId, callback) {
        dbconn.project.query('CALL getImagesByProjectID(' + projectId+ ')', function (err, rows, fields){
            if (err) throw err;
            callback(rows[0], err);
        })
    },
    addProjectOverview: function(data, callback) {
        dbconn.project.query('INSERT INTO project_overview SET ?', data, function (err, results, fields){
            if (err) {
                console.error(err);
            }
            callback(results, err);
        })
    }
};

module.exports = methods;