publishers try ex cel export (wip)
This commit is contained in:
@ -15,7 +15,7 @@ const data = require("./data");
|
||||
// for nodejs
|
||||
//const api = require("./pages/api/index");
|
||||
|
||||
exports.GenerateExcel = async function (req, res) {
|
||||
exports.ScheduleGenerateExcel = async function (req, res) {
|
||||
|
||||
const prisma = common.getPrismaClient();
|
||||
const year = req.params.year;
|
||||
@ -611,6 +611,55 @@ exports.ReadDocxFileForMonth = async function (filePath, buffer, month, year, pr
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
exports.ExportPublishersToExcel = async function (req, res) {
|
||||
const prisma = common.getPrismaClient();
|
||||
const publishers = await prisma.publisher.findMany({
|
||||
// where: { isActive: true, },
|
||||
include: {
|
||||
// availabilities: { where: { isActive: true, }, },
|
||||
// assignments: { include: { shift: true, }, },
|
||||
congregation: true,
|
||||
|
||||
},
|
||||
});
|
||||
const ExcelJS = require("exceljs");
|
||||
const xjswb = new ExcelJS.Workbook();
|
||||
const sheet = xjswb.addWorksheet("Publishers");
|
||||
sheet.columns = [
|
||||
{ header: "Name", key: "name", width: 32 },
|
||||
{ header: "Trained", key: "trained", width: 10 },
|
||||
{ header: "Email", key: "email", width: 32 },
|
||||
{ header: "Phone", key: "phone", width: 32 },
|
||||
{ header: "Role", key: "role", width: 32 },
|
||||
{ header: "Congregation", key: "congregationName", width: 32 },
|
||||
{ header: "Last Login", key: "lastLogin", width: 32 },
|
||||
{ header: "Type", key: "PublisherTypeText", width: 32 },
|
||||
{ header: "Active", key: "isActive", width: 10 },
|
||||
{ header: "Created At", key: "createdAt", width: 32 },
|
||||
{ header: "Updated At", key: "updatedAt", width: 32 },
|
||||
];
|
||||
publishers.forEach((publisher) => {
|
||||
sheet.addRow({
|
||||
name: publisher.firstName + " " + publisher.lastName,
|
||||
trained: publisher.isTrained,
|
||||
email: publisher.email,
|
||||
phone: publisher.phone,
|
||||
role: publisher.role,
|
||||
congregationName: publisher.congregation.name,
|
||||
lastLogin: publisher.lastLogin,
|
||||
PublisherTypeText: publisher.PublisherTypeText,
|
||||
isActive: publisher.isActive,
|
||||
createdAt: publisher.createdAt,
|
||||
updatedAt: publisher.updatedAt,
|
||||
|
||||
});
|
||||
});
|
||||
res.setHeader("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
res.setHeader("Content-Disposition", "attachment; filename=" + encodeURI("Publishers.xlsx"));
|
||||
xjswb.xlsx.write(res);
|
||||
}
|
||||
|
||||
const weekNames = [
|
||||
"Понеделник",
|
||||
"Вторник",
|
||||
|
Reference in New Issue
Block a user