You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

86 lines
2.1 KiB

var express = require('express');
var router = express.Router();
const userServeice = require('../services/user')
const fs = require('fs')
var path = require('path');
router.post('/add', function (req, res) {
const userInfo = {
firstName: req.body.firstName,
lastName: req.body.lastName,
fatherName: req.body.fatherName,
codeMelli: req.body.codeMelli,
workUnit: req.body.workUnit,
workUnitCode: req.body.workUnitCode,
address: req.body.address,
obligationNumber: req.body.obligationNumber,
obligationDate: req.body.obligationDate,
requestNumber: req.body.requestNumber,
requestDate: req.body.requestDate,
writtenOrderNumber: req.body.writtenOrderNumber,
writtenOrderDate: req.body.writtenOrderDate,
deadline: req.body.deadline
}
userServeice.addUser(userInfo)
.then((result) => {
res.status(200).send({
success: true,
user: result
})
})
.catch(err => {
if (err.eText) {
if (typeof err.eText !== 'string') {
err.eText = err.eText.toString()
}
res.status(err.eCode).send({
success: false,
error: err.eText
})
} else {
res.status(500).send({
success: false,
error: err.toString()
})
}
})
});
router.post('/complete/form', function (req, res) {
userServeice.completeForm(req.body.userId)
.then((result) => {
res.status(200).send({
success: true,
link: result
})
})
.catch(err => {
if (err.eText) {
if (typeof err.eText !== 'string') {
err.eText = err.eText.toString()
}
res.status(err.eCode).send({
success: false,
error: err.eText
})
} else {
res.status(500).send({
success: false,
error: err.toString()
})
}
})
})
router.get('/download/:fileName', function (req, res) {
var file = fs.readFileSync(path.join(__dirname + `/../public/files/${req.params.fileName}`), 'binary');
res.setHeader('Content-Length', file.length);
res.write(file, 'binary');
res.end();
});
module.exports = router;