Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
43 changes: 43 additions & 0 deletions core/arrayList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const pool = require('./pool');
function ArrayList(){};
ArrayList.prototype = {



create: function(body, callback)
{


var bind = [];

for(prop in body){
bind.push(body[prop]);
}

let sql = `INSERT INTO arrayList(name,user,createdAt) VALUES ( ? , ? , ?)`;

pool.query(sql, bind, function(err, result) {
if(err) console.log(err);
else
callback(result.insertId);
});
},






delete : function(id,callback) {

let sql = `DELETE FROM arrayList WHERE id = ?`;
pool.query(sql,id,function(err , ret) {
if(err) console.log(err);
callback();
});

},

}

module.exports = ArrayList ;
97 changes: 97 additions & 0 deletions core/category.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
const pool = require('./pool');
function Category(){};
Category.prototype = {

find: function(item = null , callback)
{


let sql = `SELECT * FROM category WHERE id = ?`;


pool.query(sql,item, function(err, result) {
if(err) console.log(err);

if(result.length) {
callback(result[0]);
}else {
callback(null);
}
});
},


create: function(body, callback)
{


var bind = [];

for(prop in body){
bind.push(body[prop]);
}

let sql = `INSERT INTO category(name,user,createdAt) VALUES ( ? , ? , ?)`;

pool.query(sql, bind, function(err, result) {
if(err) console.log(err);
else
callback(result.insertId);
});
},



update:function(old,body,callback){

var self = this ;

self.find(old , function(result) {

if(result) {

var bind = [] ;

for(prop in body){
bind.push(body[prop]);
}

bind.push(old);

let sql = `UPDATE category SET name = ?, user = ? ,updatedAt = ? WHERE id= ?`;

pool.query(sql, bind, function(err, ret) {

console.log(this.sql);
if(err) console.log(err);

self.find(bind[0], function(user) {

if(user) {
callback(user);
return;
}

callback(null);
});

});
}
});
},



delete : function(id,callback) {

let sql = `DELETE FROM category WHERE id = ?`;
pool.query(sql,id,function(err , ret) {
if(err) console.log(err);
callback();
});

},

}

module.exports = Category ;
89 changes: 89 additions & 0 deletions core/item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
const pool = require('./pool');
function Item(){};
Item.prototype = {

find: function(item = null , callback)
{

let sql = `SELECT * FROM item WHERE id = ?`;

pool.query(sql, item, function(err, result) {
if(err) console.log(err);

if(result.length) {
callback(result[0]);
}else {
callback(null);
}
});
},

create: function(body, callback)
{

var bind = [];

for(prop in body){
bind.push(body[prop]);
}

let sql = `INSERT INTO item(name, category, user,note,image,createdAt) VALUES (?, ?, ? , ? , ? , ?)`;

pool.query(sql, bind, function(err, result) {
if(err) console.log(err);
else
callback(result.insertId);
});
},



update:function(old,body,callback){

var self = this ;

self.find(old , function(result) {

if(result) {

var bind = [] ;

for(prop in body){
bind.push(body[prop]);
}

bind.push(old);

let sql = `UPDATE item SET name = ?, category = ?, user = ? , note = ? , image = ?,updatedAt = ? WHERE id= ?`;

pool.query(sql, bind, function(err, ret) {
if(err) console.log(err);

self.find(bind[0], function(user) {

if(user) {
callback(user);
return;
}

callback(null);
});

});
}
});
},

delete : function(id,callback) {

let sql = `DELETE FROM item WHERE id = ?`;
pool.query(sql,id,function(err , ret) {
if(err) console.log(err);
callback();
});

},

}

module.exports = Item ;
95 changes: 95 additions & 0 deletions core/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
const pool = require('./pool');
function List(){};
List.prototype = {

find: function(list = null , callback)
{


let sql = `SELECT * FROM list WHERE id = ?`;


pool.query(sql,list, function(err, result) {
if(err) console.log(err);

if(result.length) {
callback(result[0]);
}else {
callback(null);
}
});
},


create: function(body, callback)
{


var bind = [];

for(prop in body){
bind.push(body[prop]);
}

let sql = `INSERT INTO list(name,user,createdAt) VALUES ( ? , ? , ?)`;

pool.query(sql, bind, function(err, result) {
if(err) console.log(err);
else
callback(result.insertId);
});
},



update:function(old,body,callback){

var self = this ;

self.find(old , function(result) {

if(result) {

var bind = [] ;

for(prop in body){
bind.push(body[prop]);
}

bind.push(old);

let sql = `UPDATE list SET name = ?, user = ? ,updatedAt = ? WHERE id= ?`;

pool.query(sql, bind, function(err, ret) {
if(err) console.log(err);

self.find(bind[0], function(user) {

if(user) {
callback(user);
return;
}

callback(null);
});

});
}
});
},



delete : function(id,callback) {

let sql = `DELETE FROM list WHERE id = ?`;
pool.query(sql,id,function(err , ret) {
if(err) console.log(err);
callback();
});

},

}

module.exports = List ;
58 changes: 58 additions & 0 deletions core/listOfItems.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const pool = require('./pool');
function ListOfItems(){};
ListOfItems.prototype = {

find: function(list = null , callback)
{


let sql = `SELECT * FROM listOfItems WHERE list = ?`;


pool.query(sql,list, function(err, result) {
if(err) console.log(err);

if(result.length) {
callback(result[0]);
}else {
callback(null);
}
});
},


create: function(body, callback)
{


var bind = [];

for(prop in body){
bind.push(body[prop]);
}

let sql = `INSERT INTO listOfItems(list,item) VALUES ( ? , ? )`;

pool.query(sql, bind, function(err, result) {
if(err) console.log(err);
else
callback(result.insertId);
});
},




delete : function(id,callback) {

let sql = `DELETE FROM listOfItems WHERE id = ?`;
pool.query(sql,id,function(err , ret) {
if(err) console.log(err);
callback();
});

},

}

module.exports = ListOfItems ;
Loading