Skip to content

Commit

Permalink
Fix a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunghee2 committed Aug 2, 2019
1 parent afd1937 commit a423757
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ CREATE TABLE capsule (
) DEFAULT CHARSET=UTF8;
CREATE TABLE invitation (
id INT(11) NOT NULL auto_increment,
idx INT(11) NOT NULL,
latitude DOUBLE(20, 10) NOT NULL,
longitude DOUBLE(20, 10) NOT NULL,
money INT(11) NOT NULL,
end_date DATE NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (idx) REFERENCES user(idx)
) DEFAULT CHARSET=UTF8;
```
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var cookieParser = require('cookie-parser');
var logger = require('morgan');
const Tx = require('ethereumjs-tx');
const initConfig = require('./init');
const LogicHelloWorldJSON = require('../build/contracts/manage.json');
const LogicHelloWorldJSON = require('./build/contracts/manage.json');
const web3 = initConfig.web3;
const user_address = initConfig.user_address;
const user_pk = initConfig.user_pk;
Expand Down
6 changes: 6 additions & 0 deletions routes/capsules/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var express = require('express');
var router = express.Router();

router.use('/', require('./new'));

module.exports = router;
18 changes: 15 additions & 3 deletions routes/capsules/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const gasPrice = initConfig.gas_price;

let hash = '0x011111'; // ipfs 구현 후 수정
var server_address = user_address;
let manage_contract = '0x13FcDeD35083D926f2BC6d64028a8A643B835c3f'
let manage_contract = '0x13FcDeD35083D926f2BC6d64028a8A643B835c3f';
let manage = new web3.eth.Contract(LogicHelloWorldJSON.abi, manage_contract);

const utils = require('../../utils/format');
Expand Down Expand Up @@ -47,8 +47,9 @@ router.post('/', async(req, res, next) => {
const longitude = req.body.longitude;
const start_date = req.body.start_date;
const end_date = req.body.end_date;
const money = req.body.money;
// end_date를 초로 만들어줘야 함, 아래 end_seconds
const end_seconds = 10;
const end_seconds = req.body.end_seconds;
var hash = '0x1343'

web3.eth.getTransactionCount(server_address).then((nonce) => {
Expand Down Expand Up @@ -98,10 +99,21 @@ router.post('/', async(req, res, next) => {
gasLimit: 6721975
}).then((newAddress) => {
console.log(newAddress);
//주소 받음.
const insertInvitationQuery = 'INSERT INTO capsule (idx, capsule_address, money) VALUES (?, ?, ?)';
conn.query(insertInvitationQuery, [findResult[0].idx, newAddress, req.body.money], function(err, insertResult) {
if (insertResult) {
return res.json({code: 200});
} else {
if(err) {
console.log(err);
next(err);
}
return res.status(200).send(utils.successFalse(statusCode.DB_ERROR, resMessage.CREATED_CAPSULE_FAIL));
}
});
});
})
})
});

router.post('/money', async(req, res, next) => {
Expand Down
29 changes: 29 additions & 0 deletions routes/users/invitations.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,33 @@ router.post('/:idx/invitations', async(req, res, next) => {
}
});

// router.delete('/:idx/invitations/:id', async(req, res, next) => {
// var err = validateForm(req.body);
// if(err) {
// console.log(err);
// next(err);
// }

// try{
// const deleteQuery = 'DELETE FROM invitation WHERE idx = ? AND id = ?';
// conn.query(deleteQuery, [req.body.id], function(err, idx) {
// if(idx[0].idx == 0) {
// return res.status(200).send(utils.successFalse(statusCode.DB_ERROR, resMessage.NO_USER));
// } else {
// const insertInvitationQuery = 'INSERT INTO invitation (idx, latitude, longitude, money, end_date) VALUES (?, ?, ?, ?, ?)';
// conn.query(insertInvitationQuery, [idx[0].idx, req.body.latitude, req.body.longitude, req.body.money, req.body.end_date], function(err, insertResult) {
// if (insertResult) {
// return res.json({code: 200});
// } else {
// return res.status(200).send(utils.successFalse(statusCode.DB_ERROR, resMessage.CREATED_INVITATION_FAIL));
// }
// });
// }
// })
// } catch(err) {
// console.log(err);
// next(err);
// }
// });

module.exports = router;

0 comments on commit a423757

Please sign in to comment.