Skip to content

Commit

Permalink
generates doc but variables are off
Browse files Browse the repository at this point in the history
  • Loading branch information
mgtennant committed Oct 26, 2023
1 parent 9680e1f commit 06b40e2
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 104 deletions.
63 changes: 0 additions & 63 deletions backend/src/print_request_detail/entities/grazing_lease_vw.ts

This file was deleted.

6 changes: 3 additions & 3 deletions backend/src/print_request_log/print_request_log.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export class PrintRequestLogController {
return this.printRequestLogService.findByDtid(+dtid);
}

@Get("version/:dtid")
findNextVersion(@Param("dtid") dtid: string): Promise<string> {
return this.printRequestLogService.findNextVersion(+dtid);
@Get("version/:dtid/:documentType")
findNextVersion(@Param("dtid") dtid: string, @Param("documentType") documentType: string): Promise<string> {
return this.printRequestLogService.findNextVersion(+dtid, documentType);
}
}
15 changes: 14 additions & 1 deletion backend/src/print_request_log/print_request_log.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,23 @@ export class PrintRequestLogService {
});
}

async findNextVersion(dtid: number): Promise<string> {
async findNextVersion(dtid: number, documentType: string): Promise<string> {
let fullDocumentType = "";
switch (documentType) {
case ("LUR"):
fullDocumentType = "LAND USE REPORT";
break;
case ("GL"):
fullDocumentType = "GRAZING LEASE";
break;
default:
fullDocumentType = "LAND USE REPORT";
break;
}
const requestLogs = await this.printRequestLogRepository.findAndCount({
where: {
dtid: dtid,
document_type: fullDocumentType
},
});
let version = (requestLogs[1] + 1).toString();
Expand Down
11 changes: 6 additions & 5 deletions frontend/public/js/util.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
async function generateReport() {
async function generateReport(documentType) {
const tenureFileNumber = $("#tfn").text();
const prdid = $("#prdid").text();
const dtid = $("#dtid").text();
$("#genReport").prop("disabled", true);
const reportName = await fetch(
`/report/get-report-name/${dtid}/${tenureFileNumber}`,
`/report/get-report-name/${dtid}/${tenureFileNumber}/${documentType}`,
{
method: "GET",
headers: {
Expand All @@ -20,12 +20,13 @@ async function generateReport() {
.catch(() => {
location.reload();
});
const document_type = $("#document_type_id option:selected").text();
console.log(reportName)
const data = {
prdid: prdid,
document_type: document_type,
dtid: dtid,
document_type: documentType,
};
fetch(`/report/generate-lur-report`, {
fetch(`/report/generate-report`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
12 changes: 3 additions & 9 deletions frontend/src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
NFR_VARIANTS_ARRAY,
PAGE_TITLES,
REPORT_TYPES,
REPORT_URLS,
} from "utils/constants";
import { SessionData } from "utils/types";
import { AuthenticationGuard } from "./authentication/authentication.guard";
Expand Down Expand Up @@ -99,7 +100,6 @@ export class AppController {
@Req() request: Request,
@Res() response: Response
) {
console.log("LUR");
const hasParams = request.originalUrl.includes("?session_state");
if (hasParams) {
const urlWithoutParams = request.path;
Expand Down Expand Up @@ -201,22 +201,16 @@ export class AppController {
@Res() res: Response
) {
const decodedDocumentType = decodeURIComponent(documentType).toUpperCase();
console.log(decodedDocumentType);
console.log("888");
console.log(documentType);
console.log("888");
const hasParams = req.originalUrl.includes("?session_state");
if (hasParams) {
const urlWithoutParams = req.path;
res.redirect(301, urlWithoutParams);
} else if (
!NFR_VARIANTS_ARRAY.includes(decodedDocumentType) &&
decodedDocumentType != "GRAZINGLEASE"
) {
!REPORT_URLS.includes(decodedDocumentType) ) {
const redirectUrl = `/dtid/${dtid}`;
res.redirect(301, redirectUrl);
} else {
if (decodedDocumentType == "GRAZINGLEASE") {
if (decodedDocumentType == "GRAZING LEASE") {
return this.getGrazingLeaseDisplayData(session, dtid, res);
} else {
return this.getNfrDisplayData(session, dtid, documentType, res);
Expand Down
1 change: 0 additions & 1 deletion frontend/src/authentication/authentication.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export class AuthenticationFilter implements ExceptionFilter {
keycloak_login_baseurl + "?" + keycloak_login_params;
}
catch(exception: any, host: ArgumentsHost) {
console.log(exception);
if (exception.status == HttpStatus.UNAUTHORIZED) {
console.log("unauth");
const ctx = host.switchToHttp();
Expand Down
26 changes: 16 additions & 10 deletions frontend/src/report/report.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ export class ReportController {
};
}

@Get("get-report-name/:dtid/:tfn")
@Get("get-report-name/:dtid/:tfn/:documentType")
getReportName(
@Param("dtid") dtid: number,
@Param("tfn") tenureFileNumber: string
@Param("tfn") tenureFileNumber: string,
@Param("documentType") documentType: string
): Promise<{ reportName: string }> {
return this.reportService.generateReportName(dtid, tenureFileNumber);
return this.reportService.generateReportName(dtid, tenureFileNumber, documentType);
}

@Get("get-nfr-report-name/:dtid/:tfn")
Expand All @@ -58,15 +59,15 @@ export class ReportController {
return this.reportService.generateNFRReportName(dtid, tenureFileNumber);
}

@Post("generate-lur-report")
@Post("generate-report")
@Header(
"Content-Type",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
)
@Header("Content-Disposition", "attachment; filename=landusereport.docx")
async generateLURReport(
async generateReport(
@Session() session: { data: SessionData },
@Body() data: { prdid: string; document_type: string }
@Body() data: { prdid: string; document_type: string, dtid: number }
) {
// this should eventually check permissions and prevent unauthorized users from generating documents
let idir_username = "";
Expand All @@ -76,10 +77,15 @@ export class ReportController {
} else {
console.log("no active account found");
}

return new StreamableFile(
await this.reportService.generateLURReport(+data.prdid, idir_username)
);
if (data.document_type == 'GL') {
return new StreamableFile(
await this.reportService.generateGLReport(+data.dtid, idir_username)
);
} else {
return new StreamableFile(
await this.reportService.generateLURReport(+data.prdid, idir_username)
);
}
}

@Post("generate-nfr-report")
Expand Down
Loading

0 comments on commit 06b40e2

Please sign in to comment.