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.

93 lines
2.3 KiB

const models = require('../models')
const jalali = require("jalali-moment");
const docxTemp = require('../tools/docxtemp')
let methods = {}
let privates = {
findUser : (userId)=>{
return new Promise((resolve, reject) => {
4 years ago
models.User.findByPk(userId)
4 years ago
.then((user) => {
if(user){
4 years ago
resolve(user.dataValues)
4 years ago
}else{
reject({
eCode: 404,
eText: 'کاربر یافت نشد'
})
}
}).catch(err => {
reject({
eCode: 500,
eText: err
})
})
})
}
}
methods.addUser = (userInfo) => {
return new Promise((resolve, reject) => {
models.User.create(userInfo).then((user) => {
4 years ago
resolve(user)
}).catch(err => {
reject({
eCode: 500,
eText: err
})
})
})
}
methods.completeForm =(userId)=>{
return new Promise((resolve, reject) => {
privates.findUser(userId)
.then(user=>{
4 years ago
let userInfo = user
userInfo.fullName = user.firstName + ' ' + user.lastName
userInfo.deadlineAndUnit = user.deadline + ' ' + user.deadlineUnit
userInfo.obligationDate = jalali( user.obligationDate, 'YYYY/MM/DD').locale('fa').format('YYYY/MM/DD')
userInfo.requestDate = jalali( user.requestDate, 'YYYY/MM/DD').locale('fa').format('YYYY/MM/DD')
userInfo.writtenOrderDate = jalali( user.writtenOrderDate, 'YYYY/MM/DD').locale('fa').format('YYYY/MM/DD')
4 years ago
return docxTemp(userInfo, userInfo.fileName)
4 years ago
}).then(link=>{
resolve(link)
4 years ago
}).catch(err => {
if (err.eText) {
if (typeof (err.eText) !== 'string') {
err.eText = err.eText.toString()
}
reject({
eCode: err.eCode,
eText: err.eText
})
} else {
reject({
eCode: 500,
eText: err
})
}
})
})
}
module.exports = methods