Commit 7ef503bf by RNH

почищено

parent 6fb32b4d
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const dbConfig = require('./config/db');
const MongoClient = require('mongodb').MongoClient;
const mongoose = require('mongoose');
const port = 3000;
const transactions = [];
......@@ -14,11 +11,6 @@ app.listen(port, function () {
});
app.get('/', function (req, res) {
// Transaction.find(function (err, transactions) {
// if (err) return console.error(err);
// console.log(transactions);
// });
res.sendFile(__dirname + '/index.html');
});
......@@ -26,17 +18,6 @@ app.post('/', function (req, res) {
if (Object.keys(req.body).length === 0) {
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) => {
if (acc) return acc;
return trObj.transactionId === req.body.transactionId ? i : false;
......@@ -47,6 +28,7 @@ app.post('/', function (req, res) {
updatedAt: Date.now(),
status: responseStatus
};
console.log(transactions[transactionExists]);
res.send(transactions[transactionExists]);
} else {
const newTransaction = {
......@@ -56,6 +38,7 @@ app.post('/', function (req, res) {
status: responseStatus
};
transactions.push(newTransaction);
console.log(newTransaction);
res.send(newTransaction);
}
});
......@@ -67,22 +50,4 @@ app.get('/getTransactions', function (req, res) {
app.get('/changeStatus', function (req, res) {
responseStatus = !responseStatus;
res.json({ responseStatus });
});
// 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
});
\ No newline at end of file
......@@ -10,8 +10,6 @@
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.2",
"express": "^4.16.3",
"mongodb": "^3.0.4",
"mongoose": "^5.0.10"
"express": "^4.16.3"
}
}
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