Compare commits

..

No commits in common. '7f54a7f12a338af993e11740bde453ef3b08cb60' and '5056d0bcaab91ee181d65c05f7741ecca28a1f9c' have entirely different histories.

  1. 21
      migrations/20210325163147-addNewColumn.js
  2. 15
      migrations/20210325170616-changeCodeMelliType.js
  3. 4
      models/user.js
  4. 1
      package.json
  5. 51
      routes/users.js
  6. 24
      services/user.js
  7. BIN
      template/Hform4.docx
  8. 17
      tools/docxtemp.js

@ -1,21 +0,0 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return Promise.all([
queryInterface.addColumn('Users', 'healthCenter', {
type: Sequelize.STRING,
allowNull: true,
}),
queryInterface.addColumn('Users', 'healthCenterCity', {
type: Sequelize.STRING,
allowNull: true,
}),
]);
},
down: (queryInterface) => {
return Promise.all([queryInterface.removeColumn('Users', 'healthCenter'),
queryInterface.removeColumn('Users', 'healthCenterCity')]);
},
};

@ -1,15 +0,0 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return Promise.all([
queryInterface.changeColumn('Users', 'codeMelli', {
type: Sequelize.STRING,
}),
]);
},
down: (queryInterface) => {
return Promise.all([queryInterface.changeColumn('Users', 'codeMelli')]);
},
};

@ -17,7 +17,7 @@ module.exports = (sequelize, DataTypes) => {
firstName: DataTypes.STRING, firstName: DataTypes.STRING,
lastName: DataTypes.STRING, lastName: DataTypes.STRING,
fatherName: DataTypes.STRING, fatherName: DataTypes.STRING,
codeMelli: DataTypes.STRING, codeMelli: DataTypes.BIGINT,
workUnit: DataTypes.STRING, workUnit: DataTypes.STRING,
workUnitCode: DataTypes.INTEGER, workUnitCode: DataTypes.INTEGER,
address: DataTypes.TEXT, address: DataTypes.TEXT,
@ -28,8 +28,6 @@ module.exports = (sequelize, DataTypes) => {
writtenOrderNumber: DataTypes.INTEGER, writtenOrderNumber: DataTypes.INTEGER,
writtenOrderDate: DataTypes.DATE, writtenOrderDate: DataTypes.DATE,
deadline: DataTypes.INTEGER, deadline: DataTypes.INTEGER,
healthCenter: DataTypes.STRING,
healthCenterCity: DataTypes.STRING,
deadlineUnit: { deadlineUnit: {
type: DataTypes.STRING, type: DataTypes.STRING,
defaultValue: 'روز' defaultValue: 'روز'

@ -14,7 +14,6 @@
"http-errors": "~1.6.3", "http-errors": "~1.6.3",
"jalali-moment": "^3.3.10", "jalali-moment": "^3.3.10",
"morgan": "~1.9.1", "morgan": "~1.9.1",
"persianjs": "^0.4.0",
"pg": "^8.5.1", "pg": "^8.5.1",
"pizzip": "^3.0.6", "pizzip": "^3.0.6",
"sequelize": "^6.5.0" "sequelize": "^6.5.0"

@ -6,42 +6,22 @@ var path = require('path');
router.post('/add', function (req, res) { router.post('/add', function (req, res) {
let flag = false;
let emptyFieldsArray =[]
const userInfo = { const userInfo = {
firstName: req.body.firstName.trim(), firstName: req.body.firstName,
lastName: req.body.lastName.trim(), lastName: req.body.lastName,
fatherName: req.body.fatherName.trim(), fatherName: req.body.fatherName,
codeMelli: req.body.codeMelli.trim(), codeMelli: req.body.codeMelli,
workUnit: req.body.workUnit.trim(), workUnit: req.body.workUnit,
workUnitCode: req.body.workUnitCode.trim(), workUnitCode: req.body.workUnitCode,
address: req.body.address.trim(), address: req.body.address,
obligationNumber: req.body.obligationNumber.trim(), obligationNumber: req.body.obligationNumber,
obligationDate: req.body.obligationDate.trim(), obligationDate: req.body.obligationDate,
requestNumber: req.body.requestNumber.trim(), requestNumber: req.body.requestNumber,
requestDate: req.body.requestDate.trim(), requestDate: req.body.requestDate,
writtenOrderNumber: req.body.writtenOrderNumber.trim(), writtenOrderNumber: req.body.writtenOrderNumber,
writtenOrderDate: req.body.writtenOrderDate.trim(), writtenOrderDate: req.body.writtenOrderDate,
deadline: req.body.deadline.trim(), deadline: req.body.deadline
deadlineUnit: req.body.deadlineUnit.trim(),
healthCenter: req.body.healthCenter.trim(),
healthCenterCity: req.body.healthCenterCity.trim()
} }
for (const key in userInfo) {
if (!userInfo[key] || !userInfo[key].trim()) {
emptyFieldsArray.push(key)
flag = true
}
}
if(flag){
res.status(406).send({
success: false,
emptyFields : emptyFieldsArray,
error: `پر کردن همه فیلدها الزامی است`
})
}else {
userServeice.addUser(userInfo) userServeice.addUser(userInfo)
.then((result) => { .then((result) => {
res.status(200).send({ res.status(200).send({
@ -66,8 +46,6 @@ router.post('/add', function (req, res) {
} }
}) })
}
}); });
router.post('/complete/form', function (req, res) { router.post('/complete/form', function (req, res) {
@ -79,7 +57,6 @@ router.post('/complete/form', function (req, res) {
}) })
}) })
.catch(err => { .catch(err => {
console.log(err);
if (err.eText) { if (err.eText) {
if (typeof err.eText !== 'string') { if (typeof err.eText !== 'string') {
err.eText = err.eText.toString() err.eText = err.eText.toString()

@ -1,6 +1,5 @@
const models = require('../models') const models = require('../models')
const jalali = require("jalali-moment"); const jalali = require("jalali-moment");
const persianjs = require('persianjs')
const docxTemp = require('../tools/docxtemp') const docxTemp = require('../tools/docxtemp')
@ -57,26 +56,11 @@ methods.completeForm =(userId)=>{
.then(user=>{ .then(user=>{
let userInfo = user let userInfo = user
userInfo.fullName = user.firstName + ' ' + user.lastName userInfo.fullName = user.firstName + ' ' + user.lastName
userInfo.deadlineAndUnit = user.deadline + ' ' + user.deadlineUnit
userInfo.codeMelli = persianjs(user.codeMelli).englishNumber().toString(); userInfo.obligationDate = jalali( user.obligationDate, 'YYYY/MM/DD').locale('fa').format('YYYY/MM/DD')
userInfo.workUnitCode = persianJs(user.workUnitCode).englishNumber().toString(); userInfo.requestDate = jalali( user.requestDate, 'YYYY/MM/DD').locale('fa').format('YYYY/MM/DD')
userInfo.obligationNumber = persianJs(user.obligationNumber).englishNumber().toString(); userInfo.writtenOrderDate = jalali( user.writtenOrderDate, 'YYYY/MM/DD').locale('fa').format('YYYY/MM/DD')
userInfo.requestNumber = persianJs(user.requestNumber).englishNumber().toString();
userInfo.writtenOrderNumber = persianJs(user.writtenOrderNumber).englishNumber().toString();
userInfo.deadline = persianJs(user.deadline).englishNumber().toString();
userInfo.deadlineAndUnit = userInfo.deadline + ' ' + userInfo.deadlineUnit
userInfo.obligationDate = jalali( user.obligationDate, 'YYYY/MM/DD').locale('fa').format('DD/MM/YYYY')
userInfo.requestDate = jalali( user.requestDate, 'YYYY/MM/DD').locale('fa').format('DD/MM/YYYY')
userInfo.writtenOrderDate = jalali( user.writtenOrderDate, 'YYYY/MM/DD').locale('fa').format('DD/MM/YYYY')
userInfo.obligationDate = persianJs(user.obligationDate).englishNumber().toString();
userInfo.requestDate = persianJs(user.requestDate).englishNumber().toString();
userInfo.writtenOrderDate = persianJs(user.writtenOrderDate).englishNumber().toString();
return docxTemp(userInfo, userInfo.fileName) return docxTemp(userInfo, userInfo.fileName)
}).then(link=>{ }).then(link=>{

Binary file not shown.

@ -30,16 +30,8 @@ function errorHandler(error) {
throw error; throw error;
} }
module.exports = function (templateInfo, fileName) { module.exports = function (userInfo, fileName) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
for (const key in templateInfo) {
if (!templateInfo[key]) {
throw({
eCode: 406,
eText: 'empty fields'
})
}
}
let content = fs.readFileSync(path.resolve(__dirname, `../template/${fileName}`), 'binary'); let content = fs.readFileSync(path.resolve(__dirname, `../template/${fileName}`), 'binary');
let zip = new PizZip(content); let zip = new PizZip(content);
let doc; let doc;
@ -47,11 +39,10 @@ module.exports = function (templateInfo, fileName) {
try { try {
doc = new Docxtemplater(zip); doc = new Docxtemplater(zip);
} catch (error) { } catch (error) {
errorHandler(error); errorHandler(error);
} }
doc.setData(templateInfo); doc.setData(userInfo);
try { try {
doc.render() doc.render()
@ -62,8 +53,8 @@ module.exports = function (templateInfo, fileName) {
let buf = doc.getZip().generate({ let buf = doc.getZip().generate({
type: 'nodebuffer' type: 'nodebuffer'
}); });
fs.writeFileSync(path.resolve(__dirname, `../public/files/${templateInfo.firstName}-${templateInfo.lastName}-${fileName}`), buf); fs.writeFileSync(path.resolve(__dirname, `../public/files/${userInfo.firstName}-${userInfo.lastName}-${fileName}`), buf);
resolve(`http://localhost:3000/users/download/${templateInfo.firstName}-${templateInfo.lastName}-${fileName}`) resolve(`http://localhost:3000/users/download/${userInfo.firstName}-${userInfo.lastName}-${fileName}`)
.catch(err => { .catch(err => {
reject({ reject({

Loading…
Cancel
Save