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'); const createError = require('http-errors');
var express = require('express'); const express = require('express');
var path = require('path'); const path = require('path');
var cookieParser = require('cookie-parser'); const cookieParser = require('cookie-parser');
var logger = require('morgan'); const logger = require('morgan');
var indexRouter = require('./routes/index'); const usersRouter = require('./routes/users');
var usersRouter = require('./routes/users');
var app = express(); const app = express();
// view engine setup // view engine setup
app.set('views', path.join(__dirname, 'views')); app.set('views', path.join(__dirname, 'views'));
@ -19,7 +18,6 @@ app.use(express.urlencoded({ extended: false }));
app.use(cookieParser()); app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public'))); app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.use('/users', usersRouter); app.use('/users', usersRouter);
// catch 404 and forward to error handler // 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'); var path = require('path');
router.post('/add', function(req, res) { router.post('/add', function (req, res) {
const userInfo ={ const userInfo = {
firstName : req.body.firstName, firstName: req.body.firstName,
lastName : req.body.lastName, lastName: req.body.lastName,
fatherName : req.body.fatherName, fatherName: req.body.fatherName,
codeMelli : req.body.codeMelli, codeMelli: req.body.codeMelli,
workUnit : req.body.workUnit, workUnit: req.body.workUnit,
workUnitCode : req.body.workUnitCode, workUnitCode: req.body.workUnitCode,
address : req.body.address, address: req.body.address,
obligationNumber : req.body.obligationNumber, obligationNumber: req.body.obligationNumber,
obligationDate : req.body.obligationDate, obligationDate: req.body.obligationDate,
requestNumber : req.body.requestNumber, requestNumber: req.body.requestNumber,
requestDate : req.body.requestDate, requestDate: req.body.requestDate,
writtenOrderNumber : req.body.writtenOrderNumber, writtenOrderNumber: req.body.writtenOrderNumber,
writtenOrderDate : req.body.writtenOrderDate, writtenOrderDate: req.body.writtenOrderDate,
deadline : req.body.deadline deadline: req.body.deadline
} }
userServeice.addUser(userInfo) userServeice.addUser(userInfo)
.then((result) => { .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) userServeice.completeForm(req.body.userId)
.then((result) => { .then((result) => {
console.log('sssssssssssssssssssss');
console.log(result);
res.status(200).send({ res.status(200).send({
success: true, success: true,
user: result link: result
}) })
}) })
.catch(err => { .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'); var file = fs.readFileSync(path.join(__dirname + `/../public/files/${req.params.fileName}`), 'binary');
res.setHeader('Content-Length', file.length); res.setHeader('Content-Length', file.length);

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

Loading…
Cancel
Save