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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"cors": "^2.2.0",
"express": "^4.9.3",
"morgan": "^1.1.1",
"serve-favicon": "^2.0.1"
"mssql": "^4.1.0",
"serve-favicon": "^2.0.1",
"tsd": "^0.6.5"
},
"devDependencies": {
"browser-sync": "^2.5.0",
Expand Down
2 changes: 1 addition & 1 deletion src/client/app/customers/customer-detail.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

function getCustomer(id) {
return dataservice.getCustomer(id).then(function(data) {
vm.customer = data;
vm.customer = data[0];
vm.original = angular.copy(vm.customer);
return vm.customer;
});
Expand Down
8 changes: 8 additions & 0 deletions src/server/config/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const config = {
user: 'gulppatterns',
password: 'TheForceIsWeak',
server: 'localhost',
database: 'gulppatterns'
}

module.exports = config;
57 changes: 43 additions & 14 deletions src/server/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ module.exports = function(app) {
var api = '/api/';
var data = '/../data/';
var jsonfileservice = require('../utils/jsonfileservice')();
var sql = require('mssql');
var four0four = require('../utils/404')();
var config = require('../config/db');

app.get(api + 'customer/:id', getCustomer);
app.get(api + 'customers', getCustomers);
Expand All @@ -12,23 +14,50 @@ module.exports = function(app) {
function getCustomer(req, res, next) {
var id = req.params.id;
var msg = 'customer id ' + id + ' not found. ';
try {
var json = jsonfileservice.getJsonFromFile(data + 'customers.json');
var customer = json.filter(function(c) {
return c.id === parseInt(id);
});
if (customer && customer[0]) {
res.send(customer[0]);
} else {
four0four.send404(req, res, msg);
}
}
catch (ex) {
four0four.send404(req, res, msg + ex.message);
}
sql.connect(config).then(pool => {
// Store Procedure

return pool.request()
.input('customerid', sql.Int, id)
.execute('customers_sp')
sql.close()
}).then(result => {
res.send(result.recordset);
sql.close()
}).catch(err => {
// ... error checks
console.log(err)
sql.close()
})

sql.on('error', err => {
console.log(err)
})
}

function getCustomers(req, res, next) {
sql.connect(config).then(pool => {
// Store Procedure

return pool.request()
.input('customerid', sql.Int, null)
.execute('customers_sp')
sql.close()
}).then(result => {
res.send(result.recordset);
sql.close()
}).catch(err => {
// ... error checks
console.log(err)
sql.close()
})

sql.on('error', err => {
console.log(err)
})
}

function getCustomersv1(req, res, next) {
var msg = 'customers not found. ';
try {
var json = jsonfileservice.getJsonFromFile(data + 'customers.json');
Expand Down