Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
TransactionServer
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Артём Мельников
TransactionServer
Commits
7ef503bf
Commit
7ef503bf
authored
Mar 20, 2018
by
RNH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
почищено
parent
6fb32b4d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
41 deletions
+4
-41
index.js
index.js
+3
-38
package.json
package.json
+1
-3
No files found.
index.js
View file @
7ef503bf
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
);
}
});
...
...
@@ -68,21 +51,3 @@ app.get('/changeStatus', function (req, res) {
responseStatus
=
!
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
package.json
View file @
7ef503bf
...
...
@@ -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"
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment