Skip to content

Commit

Permalink
Merge pull request #134 from bcgov/consolidate-nest
Browse files Browse the repository at this point in the history
Conversion to React & consolidation of Nest
  • Loading branch information
barrfalk authored Mar 15, 2024
2 parents 4464c94 + 2b98d1c commit 7789734
Show file tree
Hide file tree
Showing 193 changed files with 63,394 additions and 26,066 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/node_modules
17,508 changes: 8,095 additions & 9,413 deletions backend/package-lock.json

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
},
"homepage": "https://github.com/bcgov/greenfield-template#readme",
"dependencies": {
"@nestjs/axios": "^3.0.2",
"@nestjs/cli": "^9.1.5",
"@nestjs/common": "^9.2.0",
"@nestjs/config": "^2.0.1",
Expand All @@ -50,20 +51,28 @@
"@nestjs/swagger": "^6.1.3",
"@nestjs/testing": "^9.2.0",
"@nestjs/typeorm": "^9.0.1",
"aws4-axios": "^2.4.9",
"axios": "^1.1.3",
"base-64": "^1.0.0",
"csvtojson": "^2.0.10",
"dotenv": "^16.0.3",
"express-session": "^1.17.3",
"joi": "^17.6.0",
"jwt-decode": "^3.1.2",
"nestjs-session": "^3.0.1",
"pg": "^8.8.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.5.7",
"session-file-store": "^1.5.0",
"swagger-ui-express": "^4.6.0",
"typeorm": "^0.3.10"
"typeorm": "^0.3.10",
"uuid": "^8.3.2"
},
"devDependencies": {
"@types/base-64": "^1.0.0",
"@types/express": "^4.17.14",
"@types/express-session": "^1.17.4",
"@types/jest": "^27.0.2",
"@types/joi": "^17.2.3",
"@types/multer": "^1.4.7",
"@types/node": "^16.11.1",
"@types/supertest": "^2.0.11",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ExceptionFilter, Catch, ArgumentsHost, HttpException, ForbiddenException } from '@nestjs/common';
import { URL } from 'url';

@Catch(HttpException)
@Catch(HttpException)
export class AccountFilter implements ExceptionFilter {
catch(exception: ForbiddenException, host: ArgumentsHost) {
const ctx = host.switchToHttp();
Expand All @@ -10,6 +10,6 @@ export class AccountFilter implements ExceptionFilter {
const protocol = process.env.ticdi_environment == 'DEVELOPMENT' ? 'http://' : 'https://';
const url = new URL(protocol + request.headers.host + response.req.url);
const status = exception.getStatus();
response.status(status).redirect(url.origin);
response.status(status).redirect(url.origin);
}
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,90 +13,83 @@ import {
Get,
Param,
Res,
} from "@nestjs/common";
import { ExportDataObject, SessionData, UserObject } from "utils/types";
import { AxiosRequestConfig } from "axios";
import { AdminService } from "./admin.service";
import { AuthenticationFilter } from "src/authentication/authentication.filter";
import { AuthenticationGuard } from "src/authentication/authentication.guard";
import { AdminGuard } from "./admin.guard";
import { FileInterceptor } from "@nestjs/platform-express";
import { Express } from "express";
import * as stream from "stream";
} from '@nestjs/common';
import { ExportDataObject, SessionData, UserObject } from 'utils/types';
import { AxiosRequestConfig } from 'axios';
import { AdminService } from './admin.service';
import { AuthenticationFilter } from 'src/authentication/authentication.filter';
import { AuthenticationGuard } from 'src/authentication/authentication.guard';
import { AdminGuard } from './admin.guard';
import { FileInterceptor } from '@nestjs/platform-express';
import { Express } from 'express';
import * as stream from 'stream';

let requestUrl: string;
let requestConfig: AxiosRequestConfig;

@Controller("admin")
@UseFilters(AuthenticationFilter)
@UseGuards(AuthenticationGuard)
@UseGuards(AdminGuard)
@Controller('admin')
// @UseFilters(AuthenticationFilter)
// @UseGuards(AuthenticationGuard)
// @UseGuards(AdminGuard)
export class AdminController {
constructor(private readonly adminService: AdminService) {
const hostname = process.env.backend_url
? process.env.backend_url
: `http://localhost`;
const hostname = process.env.backend_url ? process.env.backend_url : `http://localhost`;
const port = process.env.backend_url ? 3000 : 3001;
requestUrl = `${hostname}:${port}/template/`;
requestConfig = {
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
};
}

@Get("activate-template/:id/:document_type")
@Get('activate-template/:id/:document_type')
async activateTemplate(
@Session() session: { data?: SessionData },
@Param("id") id,
@Param("document_type") document_type
@Param('id') id,
@Param('document_type') document_type
) {
const update_userid = session.data.activeAccount
const update_userid = session?.data?.activeAccount
? session.data.activeAccount.idir_username
? session.data.activeAccount.idir_username
: ""
: "";
: ''
: '';
return this.adminService.activateTemplate({
id: id,
update_userid: update_userid,
document_type: document_type,
});
}

@Get("download-template/:id")
async downloadTemplate(@Param("id") id, @Res() res) {
@Get('download-template/:id')
async downloadTemplate(@Param('id') id: number, @Res() res) {
const dtObject = await this.adminService.downloadTemplate(id);
const base64Data = dtObject.the_file;
const buffer = Buffer.from(base64Data, "base64");
const buffer = Buffer.from(base64Data, 'base64');
const streamableFile = new stream.PassThrough();
streamableFile.end(buffer);
res.set({
"Content-Type":
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"Content-Disposition": "attachment; filename=file.docx",
'Content-Type': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'Content-Disposition': 'attachment; filename=file.docx',
});
streamableFile.pipe(res);
}

@Get("remove-template/:reportType/:id")
async removeTemplate(
@Param("reportType") reportType: string,
@Param("id") id: number
) {
@Get('remove-template/:reportType/:id')
async removeTemplate(@Param('reportType') reportType: string, @Param('id') id: number) {
return this.adminService.removeTemplate(reportType, id);
}

@Post("upload-template")
@UseInterceptors(FileInterceptor("file"))
@Post('upload-template')
@UseInterceptors(FileInterceptor('file'))
async uploadTemplate2(
@Session() session: { data?: SessionData },
@UploadedFile(
new ParseFilePipe({
validators: [
new MaxFileSizeValidator({ maxSize: 5000000 }),
new FileTypeValidator({
fileType:
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
fileType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
}), // checks the mimetype
],
})
Expand All @@ -105,50 +98,55 @@ export class AdminController {
@Body()
params: {
document_type: string;
active_flag: boolean;
template_name: string;
}
) {
const create_userid = session.data.activeAccount
const create_userid = session?.data?.activeAccount
? session.data.activeAccount.idir_username
? session.data.activeAccount.idir_username
: ""
: "";
const template_author = session.data.activeAccount
: ''
: '';
const template_author = session?.data?.activeAccount
? session.data.activeAccount.name
? session.data.activeAccount.name
: ""
: "";
: ''
: '';
const uploadData = {
document_type: params.document_type,
active_flag: params.active_flag,
active_flag: false,
mime_type: file.mimetype,
file_name: params.template_name,
template_author: template_author,
create_userid: create_userid,
};
await this.adminService.uploadTemplate(uploadData, file);
return { message: "Template uploaded successfully" };
return { message: 'Template uploaded successfully' };
}

// @Post('upload-template')
// @UseInterceptors(FileInterceptor('file'))
// async uploadTemplate(@UploadedFile() file: Express.Multer.File, @Body() body: any) {
// console.log(file); // Check if the file is received correctly
// console.log(body); // Log the body to see if other data is as expected
// return { message: 'Debugging' };
// }

/**
* Used for an AJAX route to render all admins in a datatable
* @returns altered admin object array
*/
@Get("get-admins")
@Get('get-admins')
getAdmins(): Promise<UserObject[]> {
return this.adminService.getAdminUsers();
}

@Get("get-export-data")
getExportData(): Promise<ExportDataObject[]> {
@Get('get-export-data')
getExportData(): Promise<string> {
return this.adminService.getExportData();
}

@Post("add-admin")
async addAdmin(
@Body() searchInputs: { idirUsername: string }
): Promise<{ userObject: UserObject; error: string }> {
@Post('add-admin')
async addAdmin(@Body() searchInputs: { idirUsername: string }): Promise<{ userObject: UserObject; error: string }> {
try {
const user = await this.adminService.addAdmin(searchInputs.idirUsername);
return { userObject: user, error: null };
Expand All @@ -157,7 +155,7 @@ export class AdminController {
}
}

@Post("search-users")
@Post('search-users')
async searchUsers(@Body() searchInputs: { email: string }): Promise<{
userObject: {
firstName: string;
Expand All @@ -175,57 +173,52 @@ export class AdminController {
}
}

@Get("remove-admin/:username")
removeAdmin(
@Param("username") username: string
): Promise<{ message: string }> {
return this.adminService.removeAdmin(username);
@Post('remove-admin')
removeAdmin(@Body() input: { idirUsername: string }): Promise<{ message: string }> {
return this.adminService.removeAdmin(input.idirUsername);
}

@Get("templates/:reportId")
getTemplates(@Param("reportId") reportId: number): Promise<any> {
@Get('templates/:reportId')
getTemplates(@Param('reportId') reportId: number): Promise<any> {
return this.adminService.getTemplates(reportId);
}

@Get("open-document/:nfr_id")
setSessionDocument(
@Session() session: { data?: SessionData },
@Param("nfr_id") nfrId: number
): void {
@Get('open-document/:nfr_id')
setSessionDocument(@Session() session: { data?: SessionData }, @Param('nfr_id') nfrId: number): void {
session.data.selected_document = { nfr_id: nfrId };
}

@Get("get-templates/:document_type")
getDocumentTemplates(@Param("document_type") documentType: string): any {
@Get('get-templates/:document_type')
getDocumentTemplates(@Param('document_type') documentType: string): any {
return this.adminService.getDocumentTemplates(documentType);
}

@Get("nfr-provisions")
@Get('nfr-provisions')
getNFRProvisions(): any {
return this.adminService.getNFRProvisions();
}

@Get("nfr-variables")
@Get('nfr-variables')
getNFRVariables(): any {
return this.adminService.getNFRVariables();
}

@Get("enable-provision/:provisionId")
enableProvision(@Param("provisionId") id: number): any {
@Get('enable-provision/:provisionId')
enableProvision(@Param('provisionId') id: number): any {
return this.adminService.enableProvision(id);
}

@Get("disable-provision/:provisionId")
disableProvision(@Param("provisionId") id: number): any {
@Get('disable-provision/:provisionId')
disableProvision(@Param('provisionId') id: number): any {
return this.adminService.disableProvision(id);
}

@Get("get-group-max")
@Get('get-group-max')
getGroupMax() {
return this.adminService.getGroupMax();
}

@Post("add-provision")
@Post('add-provision')
addProvision(
@Body()
provisionParams: {
Expand All @@ -241,11 +234,11 @@ export class AdminController {
},
@Session() session: { data?: SessionData }
) {
const create_userid = session.data.activeAccount.idir_username;
const create_userid = session?.data?.activeAccount.idir_username;
return this.adminService.addProvision(provisionParams, create_userid);
}

@Post("update-provision")
@Post('update-provision')
updateProvision(
@Body()
provisionParams: {
Expand All @@ -262,11 +255,11 @@ export class AdminController {
},
@Session() session: { data?: SessionData }
) {
const update_userid = session.data.activeAccount.idir_username;
const update_userid = session?.data?.activeAccount.idir_username;
return this.adminService.updateProvision(provisionParams, update_userid);
}

@Post("add-variable")
@Post('add-variable')
addVariable(
@Body()
variableParams: {
Expand All @@ -277,11 +270,11 @@ export class AdminController {
},
@Session() session: { data?: SessionData }
) {
const create_userid = session.data.activeAccount.idir_username;
const create_userid = session?.data?.activeAccount.idir_username;
return this.adminService.addVariable(variableParams, create_userid);
}

@Post("update-variable")
@Post('update-variable')
updateVariable(
@Body()
variableParams: {
Expand All @@ -292,12 +285,12 @@ export class AdminController {
},
@Session() session: { data?: SessionData }
) {
const update_userid = session.data.activeAccount.idir_username;
const update_userid = session?.data?.activeAccount.idir_username;
return this.adminService.updateVariable(variableParams, update_userid);
}

@Get("remove-variable/:id")
removeVariable(@Param("id") id: number) {
@Get('remove-variable/:id')
removeVariable(@Param('id') id: number) {
return this.adminService.removeVariable(id);
}
}
Loading

0 comments on commit 7789734

Please sign in to comment.