add type to reportdata
parent
a7380707fa
commit
f1ffdefbf8
|
|
@ -1,32 +1,26 @@
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { convertHTMLToPDF } from '@cityssm/pdf-puppeteer';
|
import { convertHTMLToPDF } from '@cityssm/pdf-puppeteer';
|
||||||
import * as dateTimeFunctions from '@cityssm/utils-datetime';
|
|
||||||
import camelcase from 'camelcase';
|
import camelcase from 'camelcase';
|
||||||
import { renderFile as renderEjsFile } from 'ejs';
|
import { renderFile as renderEjsFile } from 'ejs';
|
||||||
import * as configFunctions from '../../helpers/functions.config.js';
|
import { getConfigProperty } from '../../helpers/functions.config.js';
|
||||||
import * as lotOccupancyFunctions from '../../helpers/functions.lotOccupancy.js';
|
|
||||||
import { getPdfPrintConfig, getReportData } from '../../helpers/functions.print.js';
|
import { getPdfPrintConfig, getReportData } from '../../helpers/functions.print.js';
|
||||||
const attachmentOrInline = configFunctions.getConfigProperty('settings.printPdf.contentDisposition');
|
const attachmentOrInline = getConfigProperty('settings.printPdf.contentDisposition');
|
||||||
export async function handler(request, response, next) {
|
export async function handler(request, response, next) {
|
||||||
const printName = request.params.printName;
|
const printName = request.params.printName;
|
||||||
if (!configFunctions
|
if (!getConfigProperty('settings.lotOccupancy.prints').includes(`pdf/${printName}`) &&
|
||||||
.getConfigProperty('settings.lotOccupancy.prints')
|
!getConfigProperty('settings.workOrders.prints').includes(`pdf/${printName}`)) {
|
||||||
.includes(`pdf/${printName}`) &&
|
response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/dashboard/?error=printConfigNotAllowed`);
|
||||||
!configFunctions
|
|
||||||
.getConfigProperty('settings.workOrders.prints')
|
|
||||||
.includes(`pdf/${printName}`)) {
|
|
||||||
response.redirect(`${configFunctions.getConfigProperty('reverseProxy.urlPrefix')}/dashboard/?error=printConfigNotAllowed`);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const printConfig = getPdfPrintConfig(printName);
|
const printConfig = getPdfPrintConfig(printName);
|
||||||
if (printConfig === undefined) {
|
if (printConfig === undefined) {
|
||||||
response.redirect(`${configFunctions.getConfigProperty('reverseProxy.urlPrefix')}/dashboard/?error=printConfigNotFound`);
|
response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/dashboard/?error=printConfigNotFound`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const reportData = await getReportData(printConfig, request.query);
|
const reportData = await getReportData(printConfig, request.query);
|
||||||
const reportPath = path.join('views', 'print', 'pdf', `${printName}.ejs`);
|
const reportPath = path.join('views', 'print', 'pdf', `${printName}.ejs`);
|
||||||
function pdfCallbackFunction(pdf) {
|
function pdfCallbackFunction(pdf) {
|
||||||
response.setHeader('Content-Disposition', `${attachmentOrInline}; filename=${camelcase(printConfig.title)}.pdf`);
|
response.setHeader('Content-Disposition', `${attachmentOrInline}; filename=${camelcase(printConfig?.title ?? 'export')}.pdf`);
|
||||||
response.setHeader('Content-Type', 'application/pdf');
|
response.setHeader('Content-Type', 'application/pdf');
|
||||||
response.send(pdf);
|
response.send(pdf);
|
||||||
}
|
}
|
||||||
|
|
@ -42,9 +36,6 @@ export async function handler(request, response, next) {
|
||||||
});
|
});
|
||||||
pdfCallbackFunction(pdf);
|
pdfCallbackFunction(pdf);
|
||||||
}
|
}
|
||||||
reportData.configFunctions = configFunctions;
|
|
||||||
reportData.dateTimeFunctions = dateTimeFunctions;
|
|
||||||
reportData.lotOccupancyFunctions = lotOccupancyFunctions;
|
|
||||||
await renderEjsFile(reportPath, reportData, {}, ejsCallbackFunction);
|
await renderEjsFile(reportPath, reportData, {}, ejsCallbackFunction);
|
||||||
}
|
}
|
||||||
export default handler;
|
export default handler;
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,17 @@
|
||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
|
|
||||||
import { convertHTMLToPDF } from '@cityssm/pdf-puppeteer'
|
import { convertHTMLToPDF } from '@cityssm/pdf-puppeteer'
|
||||||
import * as dateTimeFunctions from '@cityssm/utils-datetime'
|
|
||||||
import camelcase from 'camelcase'
|
import camelcase from 'camelcase'
|
||||||
import { renderFile as renderEjsFile } from 'ejs'
|
import { renderFile as renderEjsFile } from 'ejs'
|
||||||
import type { NextFunction, Request, Response } from 'express'
|
import type { NextFunction, Request, Response } from 'express'
|
||||||
|
|
||||||
import * as configFunctions from '../../helpers/functions.config.js'
|
import { getConfigProperty } from '../../helpers/functions.config.js'
|
||||||
import * as lotOccupancyFunctions from '../../helpers/functions.lotOccupancy.js'
|
|
||||||
import {
|
import {
|
||||||
getPdfPrintConfig,
|
getPdfPrintConfig,
|
||||||
getReportData
|
getReportData
|
||||||
} from '../../helpers/functions.print.js'
|
} from '../../helpers/functions.print.js'
|
||||||
|
|
||||||
const attachmentOrInline = configFunctions.getConfigProperty(
|
const attachmentOrInline = getConfigProperty(
|
||||||
'settings.printPdf.contentDisposition'
|
'settings.printPdf.contentDisposition'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -25,15 +23,15 @@ export async function handler(
|
||||||
const printName = request.params.printName
|
const printName = request.params.printName
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!configFunctions
|
!getConfigProperty('settings.lotOccupancy.prints').includes(
|
||||||
.getConfigProperty('settings.lotOccupancy.prints')
|
`pdf/${printName}`
|
||||||
.includes(`pdf/${printName}`) &&
|
) &&
|
||||||
!configFunctions
|
!getConfigProperty('settings.workOrders.prints').includes(
|
||||||
.getConfigProperty('settings.workOrders.prints')
|
`pdf/${printName}`
|
||||||
.includes(`pdf/${printName}`)
|
)
|
||||||
) {
|
) {
|
||||||
response.redirect(
|
response.redirect(
|
||||||
`${configFunctions.getConfigProperty(
|
`${getConfigProperty(
|
||||||
'reverseProxy.urlPrefix'
|
'reverseProxy.urlPrefix'
|
||||||
)}/dashboard/?error=printConfigNotAllowed`
|
)}/dashboard/?error=printConfigNotAllowed`
|
||||||
)
|
)
|
||||||
|
|
@ -44,7 +42,7 @@ export async function handler(
|
||||||
|
|
||||||
if (printConfig === undefined) {
|
if (printConfig === undefined) {
|
||||||
response.redirect(
|
response.redirect(
|
||||||
`${configFunctions.getConfigProperty('reverseProxy.urlPrefix')}/dashboard/?error=printConfigNotFound`
|
`${getConfigProperty('reverseProxy.urlPrefix')}/dashboard/?error=printConfigNotFound`
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -56,7 +54,7 @@ export async function handler(
|
||||||
function pdfCallbackFunction(pdf: Buffer): void {
|
function pdfCallbackFunction(pdf: Buffer): void {
|
||||||
response.setHeader(
|
response.setHeader(
|
||||||
'Content-Disposition',
|
'Content-Disposition',
|
||||||
`${attachmentOrInline}; filename=${camelcase(printConfig!.title)}.pdf`
|
`${attachmentOrInline}; filename=${camelcase(printConfig?.title ?? 'export')}.pdf`
|
||||||
)
|
)
|
||||||
|
|
||||||
response.setHeader('Content-Type', 'application/pdf')
|
response.setHeader('Content-Type', 'application/pdf')
|
||||||
|
|
@ -82,10 +80,6 @@ export async function handler(
|
||||||
pdfCallbackFunction(pdf)
|
pdfCallbackFunction(pdf)
|
||||||
}
|
}
|
||||||
|
|
||||||
reportData.configFunctions = configFunctions
|
|
||||||
reportData.dateTimeFunctions = dateTimeFunctions
|
|
||||||
reportData.lotOccupancyFunctions = lotOccupancyFunctions
|
|
||||||
|
|
||||||
await renderEjsFile(reportPath, reportData, {}, ejsCallbackFunction)
|
await renderEjsFile(reportPath, reportData, {}, ejsCallbackFunction)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,19 @@
|
||||||
|
import type { Lot, LotOccupancy, WorkOrder } from '../types/recordTypes.js';
|
||||||
interface PrintConfig {
|
interface PrintConfig {
|
||||||
title: string;
|
title: string;
|
||||||
params: string[];
|
params: string[];
|
||||||
}
|
}
|
||||||
|
interface ReportData {
|
||||||
|
headTitle: string;
|
||||||
|
lot?: Lot;
|
||||||
|
lotOccupancy?: LotOccupancy;
|
||||||
|
workOrder?: WorkOrder;
|
||||||
|
configFunctions: unknown;
|
||||||
|
dateTimeFunctions: unknown;
|
||||||
|
lotOccupancyFunctions: unknown;
|
||||||
|
}
|
||||||
export declare function getScreenPrintConfig(printName: string): PrintConfig | undefined;
|
export declare function getScreenPrintConfig(printName: string): PrintConfig | undefined;
|
||||||
export declare function getPdfPrintConfig(printName: string): PrintConfig | undefined;
|
export declare function getPdfPrintConfig(printName: string): PrintConfig | undefined;
|
||||||
export declare function getPrintConfig(screenOrPdfPrintName: string): PrintConfig | undefined;
|
export declare function getPrintConfig(screenOrPdfPrintName: string): PrintConfig | undefined;
|
||||||
export declare function getReportData(printConfig: PrintConfig, requestQuery: Record<string, unknown>): Promise<Record<string, unknown>>;
|
export declare function getReportData(printConfig: PrintConfig, requestQuery: Record<string, unknown>): Promise<ReportData>;
|
||||||
export {};
|
export {};
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
|
import * as dateTimeFunctions from '@cityssm/utils-datetime';
|
||||||
import getLot from '../database/getLot.js';
|
import getLot from '../database/getLot.js';
|
||||||
import getLotOccupancy from '../database/getLotOccupancy.js';
|
import getLotOccupancy from '../database/getLotOccupancy.js';
|
||||||
import getWorkOrder from '../database/getWorkOrder.js';
|
import getWorkOrder from '../database/getWorkOrder.js';
|
||||||
import { getConfigProperty } from './functions.config.js';
|
import * as configFunctions from './functions.config.js';
|
||||||
|
import * as lotOccupancyFunctions from './functions.lotOccupancy.js';
|
||||||
const screenPrintConfigs = {
|
const screenPrintConfigs = {
|
||||||
lotOccupancy: {
|
lotOccupancy: {
|
||||||
title: `${getConfigProperty('aliases.lot')} ${getConfigProperty('aliases.occupancy')} Print`,
|
title: `${configFunctions.getConfigProperty('aliases.lot')} ${configFunctions.getConfigProperty('aliases.occupancy')} Print`,
|
||||||
params: ['lotOccupancyId']
|
params: ['lotOccupancyId']
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -46,13 +48,16 @@ export function getPrintConfig(screenOrPdfPrintName) {
|
||||||
}
|
}
|
||||||
export async function getReportData(printConfig, requestQuery) {
|
export async function getReportData(printConfig, requestQuery) {
|
||||||
const reportData = {
|
const reportData = {
|
||||||
headTitle: printConfig.title
|
headTitle: printConfig.title,
|
||||||
|
configFunctions,
|
||||||
|
dateTimeFunctions,
|
||||||
|
lotOccupancyFunctions
|
||||||
};
|
};
|
||||||
if (printConfig.params.includes('lotOccupancyId') &&
|
if (printConfig.params.includes('lotOccupancyId') &&
|
||||||
typeof requestQuery.lotOccupancyId === 'string') {
|
typeof requestQuery.lotOccupancyId === 'string') {
|
||||||
const lotOccupancy = await getLotOccupancy(requestQuery.lotOccupancyId);
|
const lotOccupancy = await getLotOccupancy(requestQuery.lotOccupancyId);
|
||||||
if ((lotOccupancy?.lotId ?? -1) !== -1) {
|
if (lotOccupancy !== undefined && (lotOccupancy?.lotId ?? -1) !== -1) {
|
||||||
reportData.lot = getLot(lotOccupancy.lotId);
|
reportData.lot = await getLot(lotOccupancy.lotId ?? -1);
|
||||||
}
|
}
|
||||||
reportData.lotOccupancy = lotOccupancy;
|
reportData.lotOccupancy = lotOccupancy;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,35 @@
|
||||||
|
import * as dateTimeFunctions from '@cityssm/utils-datetime'
|
||||||
|
|
||||||
import getLot from '../database/getLot.js'
|
import getLot from '../database/getLot.js'
|
||||||
import getLotOccupancy from '../database/getLotOccupancy.js'
|
import getLotOccupancy from '../database/getLotOccupancy.js'
|
||||||
import getWorkOrder from '../database/getWorkOrder.js'
|
import getWorkOrder from '../database/getWorkOrder.js'
|
||||||
|
import type { Lot, LotOccupancy, WorkOrder } from '../types/recordTypes.js'
|
||||||
|
|
||||||
import { getConfigProperty } from './functions.config.js'
|
import * as configFunctions from './functions.config.js'
|
||||||
|
import * as lotOccupancyFunctions from './functions.lotOccupancy.js'
|
||||||
|
|
||||||
interface PrintConfig {
|
interface PrintConfig {
|
||||||
title: string
|
title: string
|
||||||
params: string[]
|
params: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ReportData {
|
||||||
|
headTitle: string
|
||||||
|
|
||||||
|
lot?: Lot
|
||||||
|
lotOccupancy?: LotOccupancy
|
||||||
|
workOrder?: WorkOrder
|
||||||
|
|
||||||
|
configFunctions: unknown
|
||||||
|
dateTimeFunctions: unknown
|
||||||
|
lotOccupancyFunctions: unknown
|
||||||
|
}
|
||||||
|
|
||||||
const screenPrintConfigs: Record<string, PrintConfig> = {
|
const screenPrintConfigs: Record<string, PrintConfig> = {
|
||||||
lotOccupancy: {
|
lotOccupancy: {
|
||||||
title: `${getConfigProperty(
|
title: `${configFunctions.getConfigProperty(
|
||||||
'aliases.lot'
|
'aliases.lot'
|
||||||
)} ${getConfigProperty('aliases.occupancy')} Print`,
|
)} ${configFunctions.getConfigProperty('aliases.occupancy')} Print`,
|
||||||
params: ['lotOccupancyId']
|
params: ['lotOccupancyId']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -69,9 +85,12 @@ export function getPrintConfig(
|
||||||
export async function getReportData(
|
export async function getReportData(
|
||||||
printConfig: PrintConfig,
|
printConfig: PrintConfig,
|
||||||
requestQuery: Record<string, unknown>
|
requestQuery: Record<string, unknown>
|
||||||
): Promise<Record<string, unknown>> {
|
): Promise<ReportData> {
|
||||||
const reportData: Record<string, unknown> = {
|
const reportData: ReportData = {
|
||||||
headTitle: printConfig.title
|
headTitle: printConfig.title,
|
||||||
|
configFunctions,
|
||||||
|
dateTimeFunctions,
|
||||||
|
lotOccupancyFunctions
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|
@ -80,8 +99,8 @@ export async function getReportData(
|
||||||
) {
|
) {
|
||||||
const lotOccupancy = await getLotOccupancy(requestQuery.lotOccupancyId)
|
const lotOccupancy = await getLotOccupancy(requestQuery.lotOccupancyId)
|
||||||
|
|
||||||
if ((lotOccupancy?.lotId ?? -1) !== -1) {
|
if (lotOccupancy !== undefined && (lotOccupancy?.lotId ?? -1) !== -1) {
|
||||||
reportData.lot = getLot(lotOccupancy!.lotId!)
|
reportData.lot = await getLot(lotOccupancy.lotId ?? -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
reportData.lotOccupancy = lotOccupancy
|
reportData.lotOccupancy = lotOccupancy
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue