From 92733e4527752745fce105e68670b13222e2c897 Mon Sep 17 00:00:00 2001 From: timwekkenbc Date: Mon, 8 Jul 2024 16:38:12 -0700 Subject: [PATCH] Remove any CHEFS and/or submissions functionality --- README.md | 3 +- src/api/ruleData/ruleData.controller.ts | 4 +- src/api/ruleData/ruleData.schema.ts | 6 -- src/api/ruleData/ruleData.service.spec.ts | 2 - src/api/ruleData/ruleData.service.ts | 8 --- src/api/submissions/submission.interface.ts | 10 ---- .../submissions.controller.spec.ts | 46 --------------- src/api/submissions/submissions.controller.ts | 26 --------- .../submissions/submissions.service.spec.ts | 36 ------------ src/api/submissions/submissions.service.ts | 56 ------------------- src/app.module.ts | 12 +--- 11 files changed, 4 insertions(+), 205 deletions(-) delete mode 100644 src/api/submissions/submission.interface.ts delete mode 100644 src/api/submissions/submissions.controller.spec.ts delete mode 100644 src/api/submissions/submissions.controller.ts delete mode 100644 src/api/submissions/submissions.service.spec.ts delete mode 100644 src/api/submissions/submissions.service.ts diff --git a/README.md b/README.md index f706f6d..c02ded3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # BRMS API/Backend -This project is the API/Backend for the SDPR Business Rules Engine (BRE) and Business Rules Engine Management System (BRMS). It will act as a middle layer between GoRules, CHEFS, and the [frontend](https://github.com/bcgov/brms-simulator-frontend) or any other integration. +This project is the API/Backend for the SDPR Business Rules Engine (BRE) and Business Rules Engine Management System (BRMS). It will act primarly as the backend for the [frontend simulator](https://github.com/bcgov/brms-simulator-frontend). ## Local Development Setup @@ -14,7 +14,6 @@ Before running your application locally, you'll need some environment variables. - MONGODB_URL: The URL for connecting to the MongoDB instance you created in the previous step. Set it to something like mongodb://localhost/nest. - FRONTEND_URI: The URI for the frontend application. Set it to http://localhost:8080. -- CHEFS_API_URL: The URL for the Chefs API. Set it to https://submit.digital.gov.bc.ca/app/api/v1. ### Including Rules from the Rules Repository diff --git a/src/api/ruleData/ruleData.controller.ts b/src/api/ruleData/ruleData.controller.ts index a70bbd6..ab497dc 100644 --- a/src/api/ruleData/ruleData.controller.ts +++ b/src/api/ruleData/ruleData.controller.ts @@ -11,7 +11,7 @@ export class RuleDataController { try { return await this.ruleDataService.getAllRuleData(); } catch (error) { - throw new HttpException('Error getting submissions', HttpStatus.INTERNAL_SERVER_ERROR); + throw new HttpException('Error getting list of rule data', HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -20,7 +20,7 @@ export class RuleDataController { try { return await this.ruleDataService.getRuleData(ruleId); } catch (error) { - throw new HttpException('Error getting submissions', HttpStatus.INTERNAL_SERVER_ERROR); + throw new HttpException('Error getting rule data', HttpStatus.INTERNAL_SERVER_ERROR); } } diff --git a/src/api/ruleData/ruleData.schema.ts b/src/api/ruleData/ruleData.schema.ts index ef0bc39..652d02d 100644 --- a/src/api/ruleData/ruleData.schema.ts +++ b/src/api/ruleData/ruleData.schema.ts @@ -13,12 +13,6 @@ export class RuleData { @Prop({ required: true, description: 'The filename of the JSON file containing the rule' }) goRulesJSONFilename: string; - - @Prop({ description: 'The ID of the form in Chefs that corresponds to this rule' }) - chefsFormId: string; - - @Prop({ description: 'The API key of the CHEFS form - needed to access submissions' }) - chefsFormAPIKey: string; } export const RuleDataSchema = SchemaFactory.createForClass(RuleData); diff --git a/src/api/ruleData/ruleData.service.spec.ts b/src/api/ruleData/ruleData.service.spec.ts index a29683f..2ffa8e4 100644 --- a/src/api/ruleData/ruleData.service.spec.ts +++ b/src/api/ruleData/ruleData.service.spec.ts @@ -8,8 +8,6 @@ export const mockRuleData = { _id: 'testId', title: 'Title', goRulesJSONFilename: 'filename.json', - chefsFormId: 'formId', - chefsFormAPIKey: '12345', }; export const mockServiceProviders = [ diff --git a/src/api/ruleData/ruleData.service.ts b/src/api/ruleData/ruleData.service.ts index 6d0be46..1646b78 100644 --- a/src/api/ruleData/ruleData.service.ts +++ b/src/api/ruleData/ruleData.service.ts @@ -77,14 +77,6 @@ export class RuleDataService { } } - async getFormAPIKeyForFormId(chefsFormId: string): Promise { - const ruleData = await this.ruleDataModel.findOne({ chefsFormId }).exec(); - if (!ruleData) { - throw new Error(`Rule data not found for CHEFS form id: ${chefsFormId}`); - } - return ruleData.chefsFormAPIKey; - } - /** * Add rules to the db that exist in the repo, but not yet the db */ diff --git a/src/api/submissions/submission.interface.ts b/src/api/submissions/submission.interface.ts deleted file mode 100644 index 5a553ab..0000000 --- a/src/api/submissions/submission.interface.ts +++ /dev/null @@ -1,10 +0,0 @@ -export interface Submission { - submissionId: string; - createdBy: string; - createdAt: string; - submission: { - data: SubmissionData; - }; -} - -export type SubmissionData = Record; diff --git a/src/api/submissions/submissions.controller.spec.ts b/src/api/submissions/submissions.controller.spec.ts deleted file mode 100644 index 84ccc76..0000000 --- a/src/api/submissions/submissions.controller.spec.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { SubmissionsController } from './submissions.controller'; -import { SubmissionsService } from './submissions.service'; -import { Submission } from './submission.interface'; -import { SubmissionServiceMockProviders } from './submissions.service.spec'; - -describe('SubmissionsController', () => { - let controller: SubmissionsController; - let service: SubmissionsService; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [SubmissionsController], - providers: SubmissionServiceMockProviders, - }).compile(); - - controller = module.get(SubmissionsController); - service = module.get(SubmissionsService); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); - - it('should get submissions', async () => { - const result: Submission[] = []; - jest.spyOn(service, 'getSubmissions').mockImplementation(() => Promise.resolve(result)); - expect(await controller.getSubmissions('formId')).toBe(result); - }); - - it('should get submission by id', async () => { - const result: Submission = { - submissionId: '123456', - createdBy: 'TestCreator', - createdAt: new Date().toDateString(), - submission: { - data: { - name: 'TestName', - age: 25, - }, - }, - }; - jest.spyOn(service, 'getSubmissionById').mockImplementation(() => Promise.resolve(result)); - expect(await controller.getSubmissionById('formId', 'id')).toBe(result); - }); -}); diff --git a/src/api/submissions/submissions.controller.ts b/src/api/submissions/submissions.controller.ts deleted file mode 100644 index 53cb437..0000000 --- a/src/api/submissions/submissions.controller.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { Controller, Get, Param, HttpException, HttpStatus } from '@nestjs/common'; -import { SubmissionsService } from './submissions.service'; -import { Submission } from './submission.interface'; - -@Controller('api/submissions') -export class SubmissionsController { - constructor(private readonly submissionsService: SubmissionsService) {} - - @Get('/list/:formId') - async getSubmissions(@Param('formId') formId: string): Promise { - try { - return await this.submissionsService.getSubmissions(formId); - } catch (error) { - throw new HttpException('Error getting submissions', HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - @Get('/:formId/:id') - async getSubmissionById(@Param('formId') formId: string, @Param('id') id: string): Promise { - try { - return await this.submissionsService.getSubmissionById(formId, id); - } catch (error) { - throw new HttpException('Error getting submission by id', HttpStatus.INTERNAL_SERVER_ERROR); - } - } -} diff --git a/src/api/submissions/submissions.service.spec.ts b/src/api/submissions/submissions.service.spec.ts deleted file mode 100644 index 8ee8dfa..0000000 --- a/src/api/submissions/submissions.service.spec.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { ConfigService } from '@nestjs/config'; -import { SubmissionsService } from './submissions.service'; -import { RuleDataService } from '../ruleData/ruleData.service'; - -export const SubmissionServiceMockProviders = [ - SubmissionsService, - { - provide: ConfigService, - useValue: { - get: jest.fn().mockReturnValue('mock value'), - }, - }, - { - provide: RuleDataService, - useValue: {}, - }, -]; - -describe('SubmissionsService', () => { - let service: SubmissionsService; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - providers: SubmissionServiceMockProviders, - }).compile(); - - service = module.get(SubmissionsService); - }); - - it('should be defined', () => { - expect(service).toBeDefined(); - }); - - // TODO: Add more tests here for each method in your service -}); diff --git a/src/api/submissions/submissions.service.ts b/src/api/submissions/submissions.service.ts deleted file mode 100644 index 0b7b03e..0000000 --- a/src/api/submissions/submissions.service.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { Injectable, InternalServerErrorException } from '@nestjs/common'; -import { ConfigService } from '@nestjs/config'; -import axios, { AxiosInstance } from 'axios'; -import { Submission } from './submission.interface'; // assuming you have this interface -import { RuleDataService } from '../ruleData/ruleData.service'; - -@Injectable() -export class SubmissionsService { - chefsAPIURL: string; - - constructor( - private configService: ConfigService, - private readonly ruleDataService: RuleDataService, - ) { - this.chefsAPIURL = this.configService.get('CHEFS_API_URL'); - - if (!this.chefsAPIURL) { - throw new InternalServerErrorException('Environment variables CHEFS_API_URL is not not set'); - } - } - - async getAxiosCHEFSInstance(formId: string): Promise { - // Get the form API key for the form - const chefsFormAPIKey = await this.ruleDataService.getFormAPIKeyForFormId(formId); - if (!chefsFormAPIKey) { - throw new InternalServerErrorException('chefsFormAPIKey is not set for this CHEFS form'); - } - // Need to convert formid and chefsFormAPIKey to base64 in order to access submissions - const chefsAuth = Buffer.from(`${formId}:${chefsFormAPIKey}`).toString('base64'); - return axios.create({ - headers: { - Authorization: `Basic ${chefsAuth}`, - }, - }); - } - - async getSubmissions(formId: string): Promise { - try { - const axiosCHEFSInstance = await this.getAxiosCHEFSInstance(formId); - const { data } = await axiosCHEFSInstance.get(`${this.chefsAPIURL}/forms/${formId}/submissions`); - return data; - } catch (error) { - throw new Error(`Error getting submissions: ${error.message}`); - } - } - - async getSubmissionById(formId: string, id: string): Promise { - try { - const axiosCHEFSInstance = await this.getAxiosCHEFSInstance(formId); - const { data } = await axiosCHEFSInstance.get(`${this.chefsAPIURL}/submissions/${id}`); - return data; - } catch (error) { - throw new Error(`Error getting submission by id: ${error.message}`); - } - } -} diff --git a/src/app.module.ts b/src/app.module.ts index c72454e..0e0f0e7 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -8,8 +8,6 @@ import { DecisionsController } from './api/decisions/decisions.controller'; import { DecisionsService } from './api/decisions/decisions.service'; import { DocumentsController } from './api/documents/documents.controller'; import { DocumentsService } from './api/documents/documents.service'; -import { SubmissionsController } from './api/submissions/submissions.controller'; -import { SubmissionsService } from './api/submissions/submissions.service'; import { RuleMappingController } from './api/ruleMapping/ruleMapping.controller'; import { RuleMappingService } from './api/ruleMapping/ruleMapping.service'; import { ScenarioData, ScenarioDataSchema } from './api/scenarioData/scenarioData.schema'; @@ -36,17 +34,9 @@ import { ScenarioDataService } from './api/scenarioData/scenarioData.service'; RuleDataController, DecisionsController, DocumentsController, - SubmissionsController, RuleMappingController, ScenarioDataController, ], - providers: [ - RuleDataService, - DecisionsService, - DocumentsService, - SubmissionsService, - RuleMappingService, - ScenarioDataService, - ], + providers: [RuleDataService, DecisionsService, DocumentsService, RuleMappingService, ScenarioDataService], }) export class AppModule {}