final check

master
shoaibalmasi 4 years ago
parent 97d8d34e12
commit 9f50b99c37
  1. 16
      app.js
  2. 9
      routes/index.js
  3. 40
      routes/users.js
  4. 13
      services/user.js

@ -1,13 +1,12 @@
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
const createError = require('http-errors');
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
const usersRouter = require('./routes/users');
var app = express();
const app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
@ -19,7 +18,6 @@ app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.use('/users', usersRouter);
// catch 404 and forward to error handler

@ -1,9 +0,0 @@
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
module.exports = router;

@ -5,22 +5,22 @@ 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
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) => {
@ -48,14 +48,12 @@ router.post('/add', function(req, res) {
})
});
router.post('/complete/form', function(req, res) {
router.post('/complete/form', function (req, res) {
userServeice.completeForm(req.body.userId)
.then((result) => {
console.log('sssssssssssssssssssss');
console.log(result);
res.status(200).send({
success: true,
user: result
link: result
})
})
.catch(err => {
@ -77,7 +75,7 @@ router.post('/complete/form', function(req, res) {
})
})
router.get('/download/:fileName', function(req, res){
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);

@ -7,10 +7,14 @@ let methods = {}
let privates = {
findUser : (userId)=>{
return new Promise((resolve, reject) => {
models.User.findByPk(userId)
.then((user) => {
if(user){
resolve(user.dataValues)
}else{
reject({
eCode: 404,
@ -33,7 +37,7 @@ let privates = {
methods.addUser = (userInfo) => {
return new Promise((resolve, reject) => {
models.User.create(userInfo).then((user) => {
console.log(user);
resolve(user)
}).catch(err => {
@ -50,6 +54,7 @@ methods.completeForm =(userId)=>{
return new Promise((resolve, reject) => {
privates.findUser(userId)
.then(user=>{
let userInfo = user
userInfo.fullName = user.firstName + ' ' + user.lastName
userInfo.obligationDate = jalali( user.obligationDate, 'YYYY/MM/DD').locale('fa').format('YYYY/MM/DD')
@ -57,8 +62,10 @@ methods.completeForm =(userId)=>{
userInfo.writtenOrderDate = jalali( user.writtenOrderDate, 'YYYY/MM/DD').locale('fa').format('YYYY/MM/DD')
return docxTemp(userInfo, 'Hform4.docx')
}).then(text=>{
resolve(text)
}).then(link=>{
resolve(link)
}).catch(err => {
if (err.eText) {
if (typeof (err.eText) !== 'string') {

Loading…
Cancel
Save