Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release 0 #15

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
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
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
21 changes: 21 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const contact = require('./router/contacts');
const group = require('./router/groups');
const profile = require('./router/profiles');
const address = require('./router/addresses');
const addresses_with_contact = require('./router/addresses_with_contact');
app.use(bodyParser.urlencoded({ extended: false }))
app.set('views', './views')
app.set('view engine', 'ejs')

app.use('/',contact);
app.use('/',group);
app.use('/',profile);
app.use('/',address);
app.use('/',addresses_with_contact)

app.listen(3000,function(){
console.log('hallo bro..!!!')
})
Binary file added database/data.db
Binary file not shown.
80 changes: 80 additions & 0 deletions models/addresses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('./database/data.db');


class Addresses{
static findAll(){
let query = `SELECT Addresses.*,Contacts.name FROM Addresses LEFT JOIN
Contacts ON Contacts.id = Addresses.contacts_id`;
return new Promise((resolve,reject)=>{
db.all(query,(err,dataAddress)=>{
if(!err){
resolve(dataAddress)
}else{
reject(err)
}
})
})
}
static create(obj){
let query = `INSERT INTO Addresses (street, city, zipcode, contacts_id)
VALUES("${obj.street}", "${obj.city}", "${obj.zipcode}","${obj.contacts_id}")`;
return new Promise((resolve,reject)=>{
db.all(query,(err,dataAddress)=>{
if(!err){
resolve(dataAddress)
}else{
reject(err)
}
})
})
}

static remove(id){
let query = `DELETE FROM Addresses
WHERE id = ${id}`;
return new Promise((resolve,reject)=>{
db.all(query,(err,dataAddress)=>{
if(!err){
resolve(dataAddress)
}else{
reject(err)
}
})
})
}

static findById(id){
let query = `SELECT * FROM Addresses where id = "${id}"`;
return new Promise((resolve,reject)=>{
db.all(query,(err,dataAddress)=>{
if(!err){
resolve(dataAddress)
}else{
reject(err)
}
})
})
}

static update(obj){
let query = `UPDATE Addresses
SET street = "${obj.street}",
city = "${obj.city}",
zipcode = "${obj.zipcode}",
contacts_id = "${obj.contacts_id}"
WHERE id = "${obj.id}"`;
return new Promise((resolve,reject)=>{
db.all(query,(err,dataAddress)=>{
if(!err){
resolve(dataAddress)
}else{
reject(err)
}
})
})
}
}

module.exports = Addresses
79 changes: 79 additions & 0 deletions models/contacts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
"use strict"
const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('./database/data.db');


class Contacts{
static findAll(){
let query = `SELECT * FROM Contacts`;
return new Promise((resolve,reject)=>{
db.all(query,(err,dataContact)=>{
if(!err){
resolve(dataContact)
}else{
reject(err)
}
})
})
}
static create(obj){
let query = `INSERT INTO Contacts (name,company,telp_number,email)
VALUES("${obj.name}", "${obj.company}", "${obj.telp_number}", "${obj.email}")`;
return new Promise((resolve,reject)=>{
db.all(query,(err,dataContact)=>{
if(!err){
resolve(dataContact)
}else{
reject(err)
}
})
})
}

static remove(id){
let query = `DELETE FROM Contacts
WHERE id = ${id}`;
return new Promise((resolve,reject)=>{
db.all(query,(err,dataContact)=>{
if(!err){
resolve(dataContact)
}else{
reject(err)
}
})
})
}

static findById(id){
let query = `SELECT * FROM Contacts where id = "${id}"`;
return new Promise((resolve,reject)=>{
db.all(query,(err,dataContact)=>{
if(!err){
resolve(dataContact)
}else{
reject(err)
}
})
})
}

static update(obj){
let query = `UPDATE Contacts
SET name = "${obj.name}",
company = "${obj.company}",
telp_number = "${obj.telp_number}",
email = "${obj.email}"
WHERE id = "${obj.id}"`;
return new Promise((resolve,reject)=>{
db.all(query,(err,dataContact)=>{
if(!err){
resolve(dataContact)
}else{
reject(err)
}
})
})
}
}

module.exports = Contacts
75 changes: 75 additions & 0 deletions models/groups.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('./database/data.db');

class Groups{
static findAll(){
let query = `SELECT * FROM Groups`;
return new Promise((resolve,reject)=>{
db.all(query,function(err,dataGroup){
if(err){
reject(err)
}else{
resolve(dataGroup)
}
})
})
}

static create(obj){
let query = `INSERT INTO Groups (name_of_group)
VALUES("${obj.name_of_group}")`;
return new Promise((resolve,reject)=>{
db.all(query,function(err,dataGroup){
if(err){
reject(err)
}else{
resolve(dataGroup)
}
})
})
}

static remove(id){
let query = `DELETE FROM Groups
WHERE id = ${id}`;
return new Promise((resolve,reject)=>{
db.all(query,function(err,dataGroup){
if(err){
reject(err)
}else{
resolve(dataGroup)
}
})
})
}

static findById(id){
let query = `SELECT * FROM Groups where id = "${id}"`;
return new Promise((resolve,reject)=>{
db.all(query,function(err,dataGroup){
if(err){
reject(err)
}else{
resolve(dataGroup)
}
})
})
}

static update(obj){
let query = `UPDATE Groups
SET name_of_group = "${obj.name_of_group}"
WHERE id = "${obj.id}"`;
return new Promise((resolve,reject)=>{
db.all(query,function(err,dataGroup){
if(err){
reject(err)
}else{
resolve(dataGroup)
}
})
})
}
}

module.exports = Groups
79 changes: 79 additions & 0 deletions models/profiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('./database/data.db');


class Profile{
static findAll(){
let query = `SELECT Profile.*,Contacts.name FROM Profile LEFT JOIN
Contacts ON Contacts.id = Profile.contacts_id`;
return new Promise((resolve,reject)=>{
db.all(query,(err,dataProfile)=>{
if(!err){
resolve(dataProfile)
}else{
reject(err)
}
})
})
}

static create(obj){
let query = `INSERT INTO Profile (username,password,contacts_id)
VALUES("${obj.username}", "${obj.password}","${obj.contacts_id}")`;
return new Promise((resolve,reject)=>{
db.all(query,(err,dataProfile)=>{
if(!err){
resolve(dataProfile)
}else{
reject(err)
}
})
})
}

static remove(id){
let query = `DELETE FROM Profile
WHERE id = ${id}`;
return new Promise((resolve,reject)=>{
db.all(query,(err,dataProfile)=>{
if(!err){
resolve(dataProfile)
}else{
reject(err)
}
})
})
}

static findById(id){
let query = `SELECT * FROM Profile where id = "${id}"`;
return new Promise((resolve,reject)=>{
db.all(query,(err,dataProfile)=>{
if(!err){
resolve(dataProfile)
}else{
reject(err)
}
})
})
}

static update(obj){
let query = `UPDATE Profile
SET username = "${obj.username}",
password = "${obj.password}",
contacts_id = "${obj.contacts_id}"
WHERE id = "${obj.id}"`;
return new Promise((resolve,reject)=>{
db.all(query,(err,dataProfile)=>{
if(!err){
resolve(dataProfile)
}else{
reject(err)
}
})
})
}
}

module.exports = Profile
1 change: 1 addition & 0 deletions node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading