function docs(arg) {
arg = arg.split(',')
for(i=0; i<arg.length; i++) {
$('.documents .value').append(`<img src='../images/${arg[i]}'>`)
}
}
docs(data[findId].documents)
let id = '<div class="id">'+data[findId].id+'</div>',
name = '<div class="touch name"><div class="info">Название:</div><div class="value">'+data[findId].name+'</div><div class="fas fa-pencil-alt"></div></div>',
name2 = '<div class="touch item name2"><div class="info">Сокращенное название:</div><div class="value">'+data[findId].name2+'</div><div class="fas fa-pencil-alt"></div></div>',
name3 = '<div class="touch item name3"><div class="info">Полное название:</div><div class="value">'+data[findId].name3+'</div><div class="fas fa-pencil-alt"></div></div>',
email = '<div class="touch item email"><div class="info">E-mail:</div><div class="value">'+data[findId].email+'</div><div class="fas fa-pencil-alt"></div></div>',
region = '<div class="touch item region"><div class="info">Регион:</div><div class="value">'+data[findId].region+'</div><div class="fas fa-pencil-alt"></div></div>',
city = '<div class="touch item city"><div class="info">Город:</div><div class="value">'+data[findId].city+'</div><div class="fas fa-pencil-alt"></div></div>',
street = '<div class="touch item street"><div class="info">Поселок,улица,дом:</div><div class="value">'+data[findId].street+'</div><div class="fas fa-pencil-alt"></div></div>',
face = '<div class="touch item face"><div class="info">Юридический адрес:</div><div class="value">'+data[findId].face+'</div><div class="fas fa-pencil-alt"></div></div>',
physic = '<div class="touch item physic"><div class="info">Фактический адрес:</div><div class="value">'+data[findId].physic+'</div><div class="fas fa-pencil-alt"></div></div>',
index = '<div class="touch item index"><div class="info">Почтовый адрес:</div><div class="value">'+data[findId].indexx+'</div><div class="fas fa-pencil-alt"></div></div>',
phone = '<div class="touch item phone"><div class="info">Телефон:</div><div class="value">'+data[findId].phone+'</div><div class="fas fa-pencil-alt"></div></div>',
orgn = '<div class="touch item orgn"><div class="info">ОРГН:</div><div class="value">'+data[findId].orgn+'</div><div class="fas fa-pencil-alt"></div></div>',
documents = '<div class="touch item documents"><div class="info">Документы:</div><form enctype="multipart/form-data" action="/upload" method="POST"><input type="file" name="imgUploader" multiple><button type="submit">Загрузить</button></form><div class="value"></div><div class="fas fa-pencil-alt"></div></div>',
creator = '<div class="touch item creator"><div class="info">Роли:</div><div class="value">'+role.name+'</div><div class="fas fa-pencil-alt"></div></div>',
bank = '<div class="touch item bank"><div class="info">Банк:</div><div class="value">'+data[findId].bank+'</div><div class="fas fa-pencil-alt"></div></div>',
bik = '<div class="touch item bik"><div class="info">БИК:</div><div class="value">'+data[findId].bik+'</div><div class="fas fa-pencil-alt"></div></div>',
rs = '<div class="touch item rs"><div class="info">Р/С:</div><div class="value">'+data[findId].rs+'</div><div class="fas fa-pencil-alt"></div></div>',
ks = '<div class="touch item ks"><div class="info">К/С:</div><div class="value">'+data[findId].ks+'</div><div class="fas fa-pencil-alt"></div></div>',
button = '<button class="save">Сохранить</button>'
$('.control-company *').detach()
$('.control-company').append(id+name+name2+name3+email+region+city+street+face+physic+index+phone+orgn+documents+creator+bank+bik+rs+ks+button)
const { app,static } = require('../modules/app_config')
const { successAccess } = require('../modules/check_page')
const { pool } = require('../modules/mysql')
const { multer,bodyParser } = require('../modules/packages')
app.use(bodyParser.json())
let images = []
let Storage = multer.diskStorage({
destination: (req, file, callback) => {
callback(null, `${static}/images/`)
},
filename: (req, file, callback) => {
callback(null, file.fieldname + "_" + Date.now() + "_" + file.originalname)
images.push(file.fieldname + "_" + Date.now() + "_" + file.originalname)
}
})
let upload = multer({
storage: Storage
}).array("imgUploader", 4)
app.get('/control-company', (req,res) => {
res.sendFile(`${static}/www/control-company.html`)
})
app.post('/create-company', (req,res) => {
const {
name,
name2,
name3,
email,
documents,
skype,
website,
creator
} = req.body
pool.query(`select * from users where email = '${creator}'`, (error,results,fields) => {
const creator_id = results.map(r => r.id)
pool.query(`INSERT INTO the_company SET ?`,{name,name2,name3,email,documents,skype,website,creator_id},(err,res) => {
if(err) console.log(err)
})
})
upload(req, res, function(err) {
if (err) {
return console.log("Something went wrong!")
}
console.log("File uploaded sucessfully!")
})
setTimeout(() => {
console.log(images)
images = []
},200)
return res.redirect('/')
})
app.post('/control-company', (req,res) => {
let company
pool.query("SELECT * FROM the_company WHERE creator_id = '" + req.user + "'" , function(err,res){
company = res.map(the_company_list => the_company_list)
})
const send = ms => {
return new Promise(r => setTimeout(() => r(), ms))
}
send(200).then(() => res.send(company))
})
async function sendUser(url,name,email,role,password) {
this.url = url
this.name = name
this.email = email
this.role = role
this.password = password
this.options = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body:
JSON.stringify({
firstname: this.name,
email: this.email,
role: this.role,
password: this.password
})
}
const response = await fetch(this.url,this.options)
const data = await response.json()
if(data) document.location.replace(`${data.step}`)
}
async function authenticateForUser(url,email,password) {
this.url = url
this.email = email
this.password = password
this.options = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body:
JSON.stringify({
email: this.email,
password: this.password
})
}
const response = await fetch(this.url,this.options)
const data = await response.json()
// if(data) document.location.replace(`${data.step}`)
}