generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from bcgov/EMSEDT-185_Search_Functionality
EMSEDT-185: Search Functionality
- Loading branch information
Showing
31 changed files
with
676 additions
and
374 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
backend/src/file_error_logs/dto/create-file_error_log.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { PickType } from "@nestjs/swagger"; | ||
import { FileErrorLogDto } from "./file_error_logs.dto"; | ||
|
||
export class CreateFileErrorLogDto extends PickType(FileErrorLogDto, [ | ||
'file_error_log_id', | ||
'file_submission_id', | ||
'file_name', | ||
'original_file_name', | ||
'file_operation_code', | ||
'ministry_contact', | ||
'error_log', | ||
'create_utc_timestamp' | ||
] as const) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { ApiProperty } from "@nestjs/swagger"; | ||
|
||
export class FileErrorLogDto { | ||
@ApiProperty({ | ||
description: "File error log ID", | ||
}) | ||
file_error_log_id: string; | ||
|
||
@ApiProperty({ | ||
description: "File submission ID", | ||
}) | ||
file_submission_id: string; | ||
|
||
@ApiProperty({ | ||
description: "File name", | ||
}) | ||
file_name: string; | ||
|
||
@ApiProperty({ | ||
description: "original file name", | ||
}) | ||
original_file_name: string; | ||
|
||
@ApiProperty({ | ||
description: "Error log data", | ||
}) | ||
error_log: string; | ||
|
||
@ApiProperty({ | ||
description: 'The operation the file was submitted for', | ||
}) | ||
file_operation_code: string; | ||
|
||
@ApiProperty({ | ||
description: 'The ministry contact that needs to be notified', | ||
}) | ||
ministry_contact: string; | ||
|
||
@ApiProperty({ | ||
description: 'When the user created the record', | ||
}) | ||
create_utc_timestamp: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { CreateFileErrorLogDto } from './create-file_error_log.dto'; | ||
|
||
export class UpdateFileErrorLogDto extends (CreateFileErrorLogDto) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export class FileErrorLog {} |
20 changes: 20 additions & 0 deletions
20
backend/src/file_error_logs/file_error_logs.controller.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { FileErrorLogsController } from './file_error_logs.controller'; | ||
import { FileErrorLogsService } from './file_error_logs.service'; | ||
|
||
describe('FileErrorLogsController', () => { | ||
let controller: FileErrorLogsController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [FileErrorLogsController], | ||
providers: [FileErrorLogsService], | ||
}).compile(); | ||
|
||
controller = module.get<FileErrorLogsController>(FileErrorLogsController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
Controller, | ||
Get, | ||
Post, | ||
Body, | ||
Patch, | ||
Param, | ||
Delete, | ||
UseGuards, | ||
} from "@nestjs/common"; | ||
import { FileErrorLogsService } from "./file_error_logs.service"; | ||
import { CreateFileErrorLogDto } from "./dto/create-file_error_log.dto"; | ||
import { UpdateFileErrorLogDto } from "./dto/update-file_error_log.dto"; | ||
import { ApiTags } from "@nestjs/swagger"; | ||
import { JwtRoleGuard } from "src/auth/jwtrole.guard"; | ||
import { JwtAuthGuard } from "src/auth/jwtauth.guard"; | ||
import { Roles } from "src/auth/decorators/roles.decorators"; | ||
import { Role } from "src/enum/role.enum"; | ||
|
||
@ApiTags("file_error_logs") | ||
@Controller({ path: "file_error_logs", version: "1" }) | ||
@UseGuards(JwtAuthGuard) | ||
@UseGuards(JwtRoleGuard) | ||
@Roles(Role.ENMODS_ADMIN) | ||
export class FileErrorLogsController { | ||
constructor(private readonly fileErrorLogsService: FileErrorLogsService) {} | ||
|
||
@Post() | ||
create(@Body() createFileErrorLogDto: CreateFileErrorLogDto) { | ||
return this.fileErrorLogsService.create(createFileErrorLogDto); | ||
} | ||
|
||
@Get() | ||
findAll() { | ||
return this.fileErrorLogsService.findAll(); | ||
} | ||
|
||
@Get(":file_submission_id") | ||
findOne(@Param("file_submission_id") id: string): Promise<string> { | ||
return this.fileErrorLogsService.findOne(id); | ||
} | ||
|
||
@Patch(":id") | ||
update( | ||
@Param("id") id: string, | ||
@Body() updateFileErrorLogDto: UpdateFileErrorLogDto, | ||
) { | ||
return this.fileErrorLogsService.update(+id, updateFileErrorLogDto); | ||
} | ||
|
||
@Delete(":id") | ||
remove(@Param("id") id: string) { | ||
return this.fileErrorLogsService.remove(+id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { FileErrorLogsService } from './file_error_logs.service'; | ||
import { FileErrorLogsController } from './file_error_logs.controller'; | ||
|
||
@Module({ | ||
controllers: [FileErrorLogsController], | ||
providers: [FileErrorLogsService], | ||
}) | ||
export class FileErrorLogsModule {} |
18 changes: 18 additions & 0 deletions
18
backend/src/file_error_logs/file_error_logs.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { FileErrorLogsService } from './file_error_logs.service'; | ||
|
||
describe('FileErrorLogsService', () => { | ||
let service: FileErrorLogsService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [FileErrorLogsService], | ||
}).compile(); | ||
|
||
service = module.get<FileErrorLogsService>(FileErrorLogsService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { CreateFileErrorLogDto } from "./dto/create-file_error_log.dto"; | ||
import { UpdateFileErrorLogDto } from "./dto/update-file_error_log.dto"; | ||
import { PrismaService } from "nestjs-prisma"; | ||
|
||
@Injectable() | ||
export class FileErrorLogsService { | ||
constructor(private prisma: PrismaService) {} | ||
|
||
create(createFileErrorLogDto: CreateFileErrorLogDto) { | ||
return "This action adds a new fileErrorLog"; | ||
} | ||
|
||
findAll() { | ||
return `This action returns all fileErrorLogs`; | ||
} | ||
|
||
async findOne(file_submission_id: string): Promise<string> { | ||
const fileLogs = await this.prisma.file_error_logs.findMany({ | ||
where: { | ||
file_submission_id: file_submission_id, | ||
}, | ||
}); | ||
|
||
const formattedMessage = formulateErrorFile(fileLogs); | ||
return formattedMessage; | ||
} | ||
|
||
update(id: number, updateFileErrorLogDto: UpdateFileErrorLogDto) { | ||
return `This action updates a #${id} fileErrorLog`; | ||
} | ||
|
||
remove(id: number) { | ||
return `This action removes a #${id} fileErrorLog`; | ||
} | ||
} | ||
|
||
function formulateErrorFile(logs: any) { | ||
let formattedMessages = ""; | ||
const [date, timeWithZ] = new Date(logs[0].create_utc_timestamp) | ||
.toISOString() | ||
.split("T"); | ||
const time = timeWithZ.replace("Z", ""); | ||
let fileOperation = "" | ||
|
||
if (logs[0].file_operation_code === 'VALIDATE'){ | ||
fileOperation = "True"; | ||
}else{ | ||
fileOperation = "False"; | ||
} | ||
|
||
formattedMessages = | ||
`User's Original File: ${logs[0].original_file_name}\n` + | ||
`${date} ${time}\n\n` + | ||
`QA Only: ${fileOperation}\n\n` + | ||
`The following warnings/errors were found during the validation/import of the data.\n` + | ||
`The data will need to be corrected and uploaded again for validation/import to ENMODS.\n` + | ||
`If you have any questions, please contact the ministry contact(s) listed below.\n\n` + | ||
`-----------------------------------------------------------------------\n` + | ||
`Ministry Contact: ${logs[0].ministry_contact}\n` + | ||
`-----------------------------------------------------------------------\n\n`; | ||
|
||
logs[0].error_log.forEach((log) => { | ||
const rowNum = log.rowNum; | ||
|
||
for (const [key, msg] of Object.entries(log.message)) { | ||
formattedMessages += `${log.type}: Row ${rowNum}: ${key} - ${msg}\n`; | ||
} | ||
}); | ||
|
||
if (logs[0].error_log.length >= 1) { | ||
formattedMessages += | ||
"\nData was not updated in ENMODS due to errors found in the submission file. Please correct the data and resubmit."; | ||
} | ||
|
||
return formattedMessages; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.