Include complete API and frontend sources for unified deployment
This commit is contained in:
1 parent
627b0ae60e
commit
d8fcae32b0
93 files changed
+53270
-3
No files matched your search
@@ -0,0 +1,44 @@
|
||||
import User from '../models/user.js';
|
||||
import Case from '../models/case.js';
|
||||
import { SystemError } from '../utils/errors.js';
|
||||
import { createExpertQrPdf } from '../utils/expert-qr-pdf.js';
|
||||
|
||||
export default async function exportExpertQr({ body }, res) {
|
||||
let url;
|
||||
try {
|
||||
url = new URL(body.baseUrl);
|
||||
} catch (e) {
|
||||
throw new SystemError(400, 'Укажите корректный адрес приложения.');
|
||||
}
|
||||
if (
|
||||
!['http:', 'https:'].includes(url.protocol) ||
|
||||
url.username ||
|
||||
url.password ||
|
||||
url.search ||
|
||||
url.hash ||
|
||||
url.href.length > 300
|
||||
)
|
||||
throw new SystemError(400, 'Укажите адрес приложения без параметров и фрагмента #.');
|
||||
const users = await User.findAll({
|
||||
attributes: ['firstName', 'lastName', 'middleName', 'login', 'passwordForAdmin', 'role'],
|
||||
include: { model: Case, as: 'cases', attributes: ['name'], through: { attributes: [] } },
|
||||
order: [
|
||||
['lastName', 'ASC'],
|
||||
['firstName', 'ASC'],
|
||||
['id', 'ASC'],
|
||||
],
|
||||
});
|
||||
if (!users.length) throw new SystemError(404, 'Нет активных экспертов для экспорта.');
|
||||
if (users.some(user => !user.passwordForAdmin))
|
||||
throw new SystemError(
|
||||
409,
|
||||
'У некоторых экспертов не задан пароль. Задайте пароль в редактировании и повторите экспорт.'
|
||||
);
|
||||
const pdf = await createExpertQrPdf(users, url.href);
|
||||
res.set({
|
||||
'Content-Type': 'application/pdf',
|
||||
'Content-Disposition': 'attachment; filename="experts-qr.pdf"',
|
||||
'Cache-Control': 'private, no-store',
|
||||
});
|
||||
res.send(pdf);
|
||||
}
|
||||
Reference in new issue
Block a user