Commit 7ef503bf by RNH

почищено

parent 6fb32b4d
const express = require('express'); const express = require('express');
const app = express(); const app = express();
const bodyParser = require('body-parser'); const bodyParser = require('body-parser');
const dbConfig = require('./config/db');
const MongoClient = require('mongodb').MongoClient;
const mongoose = require('mongoose');
const port = 3000; const port = 3000;
const transactions = []; const transactions = [];
...@@ -14,11 +11,6 @@ app.listen(port, function () { ...@@ -14,11 +11,6 @@ app.listen(port, function () {
}); });
app.get('/', function (req, res) { app.get('/', function (req, res) {
// Transaction.find(function (err, transactions) {
// if (err) return console.error(err);
// console.log(transactions);
// });
res.sendFile(__dirname + '/index.html'); res.sendFile(__dirname + '/index.html');
}); });
...@@ -26,17 +18,6 @@ app.post('/', function (req, res) { ...@@ -26,17 +18,6 @@ app.post('/', function (req, res) {
if (Object.keys(req.body).length === 0) { if (Object.keys(req.body).length === 0) {
res.status(400).send('Failed, request body is empty!'); res.status(400).send('Failed, request body is empty!');
} }
// const { transctionId, amount, createdAt, updatedAt, status } = req.body;
// const transaction = new Transaction({
// transctionId,
// amount,
// createdAt,
// updatedAt,
// status,
// });
// transaction.save(function (err, transaction) {
// if (err) return console.error(err);
// });
const transactionExists = transactions.reduce((acc, trObj, i) => { const transactionExists = transactions.reduce((acc, trObj, i) => {
if (acc) return acc; if (acc) return acc;
return trObj.transactionId === req.body.transactionId ? i : false; return trObj.transactionId === req.body.transactionId ? i : false;
...@@ -47,6 +28,7 @@ app.post('/', function (req, res) { ...@@ -47,6 +28,7 @@ app.post('/', function (req, res) {
updatedAt: Date.now(), updatedAt: Date.now(),
status: responseStatus status: responseStatus
}; };
console.log(transactions[transactionExists]);
res.send(transactions[transactionExists]); res.send(transactions[transactionExists]);
} else { } else {
const newTransaction = { const newTransaction = {
...@@ -56,6 +38,7 @@ app.post('/', function (req, res) { ...@@ -56,6 +38,7 @@ app.post('/', function (req, res) {
status: responseStatus status: responseStatus
}; };
transactions.push(newTransaction); transactions.push(newTransaction);
console.log(newTransaction);
res.send(newTransaction); res.send(newTransaction);
} }
}); });
...@@ -68,21 +51,3 @@ app.get('/changeStatus', function (req, res) { ...@@ -68,21 +51,3 @@ app.get('/changeStatus', function (req, res) {
responseStatus = !responseStatus; responseStatus = !responseStatus;
res.json({ responseStatus }); res.json({ responseStatus });
}); });
\ No newline at end of file
// mongoose.connect(dbConfig.url);
// const db = mongoose.connection;
// db.on('error', console.error.bind(console, 'connection error:'));
// db.once('open', function () {
// console.log('Mongoose connection opened');
// });
// const transactionSchema = mongoose.Schema({
// transctionId: String,
// ammount: Number,
// createdAt: Number,
// updatedAt: Number,
// status: Boolean,
// });
// const Transaction = mongoose.model('Transaction', transactionSchema);
\ No newline at end of file
...@@ -10,8 +10,6 @@ ...@@ -10,8 +10,6 @@
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"body-parser": "^1.18.2", "body-parser": "^1.18.2",
"express": "^4.16.3", "express": "^4.16.3"
"mongodb": "^3.0.4",
"mongoose": "^5.0.10"
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment