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');
4 years ago
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) => {
4 years ago
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()
})
}
4 years ago
})
});
4 years ago
router.post('/complete/form', function (req, res) {
userServeice.completeForm(req.body.userId)
4 years ago
.then((result) => {
res.status(200).send({
success: true,
link: result
})
})
4 years ago
.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()
})
}
4 years ago
})
})
4 years ago
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();
});
4 years ago
module.exports = router;