본문 바로가기

엉터리 개발 이야기/개인프로젝트

참고코드 - routes

반응형
var express = require('express');
var XLSX = require("xlsx");
var xls = require('node-xlsx');
var fs =require('fs');
var path = require('path');

module.exports = app => {

var router = express.Router();

app.use('/', router);
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});

router.get('/read', function(req, res, next) {
//var workbook = XLSX.readFile(`${__dirname}\upload/out.xlsx`);

fs.readFile(path.join(__dirname, '../' , '/upload/test.txt'), 'utf8' , function (err, data) {
console.log(data);
});

});
}


var express = require('express');


/* GET users listing. */
module.exports = app => {
var router = express.Router();

app.use('/order', router);

router.get('/', function (req, res, next) {
app.db.models.order.findAll({
include: [
{
model: app.db.models.partner,
as: 'partner'
}
]
})
.then((result) => {
console.log(JSON.stringify(result))
res.render('order', {title: 'Order', order_list: result});
});

});
}


var express = require('express');

module.exports = app => {
var router = express.Router();

app.use('/partner', router);
/* GET users listing. */
router.get('/', function (req, res, next) {
app.db.models.partner.findAll({}).then((partner_all) => {
console.log(JSON.stringify(partner_all));
res.render('partner', {title: 'New', partner_list: partner_all});
})
//res.render('partner', { title: 'Partner Information' });
});

router.get('/addPartner', function (req, res, next) {
res.render('addPartner', {title: 'Partner Information'});
});

router.post('/create', function (req, res, next) {

console.log(req.body);
const partner_name = req.body.partner_name;
const partner_code = req.body.partner_code;

const partner_info = {
name: partner_name,
code: partner_code
};

app.db.models.create(
partner_info
).then((result) => {
app.db.models.findAll({}).then((partner_all) => {
console.log(JSON.parse(partner_all));
res.render('partner', {title: 'New', partner_list: partner_all});
})

});

});
}


반응형