Skip to content

Commit

Permalink
Merge pull request #139 from bcgov/adjustments-for-deploy
Browse files Browse the repository at this point in the history
Adjustments for deploy
  • Loading branch information
mgtennant authored Mar 20, 2024
2 parents 0734686 + 6c545fd commit 13b46c5
Show file tree
Hide file tree
Showing 15 changed files with 173 additions and 210 deletions.
2 changes: 2 additions & 0 deletions backend/src/document_data/document_data.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { DocumentDataVariable } from './entities/document_data_variable.entity';
import { DocumentDataController } from './document_data.controller';
import { DocumentDataService } from './document_data.service';
import { DocumentDataLog } from 'src/document_data_log/entities/document_data_log.entity';
import { DocumentTypeModule } from 'src/document_type/document_type.module';

@Module({
imports: [
Expand All @@ -20,6 +21,7 @@ import { DocumentDataLog } from 'src/document_data_log/entities/document_data_lo
TypeOrmModule.forFeature([Provision]),
ProvisionModule,
DocumentTemplateModule,
DocumentTypeModule,
],
controllers: [DocumentDataController],
providers: [DocumentDataService],
Expand Down
49 changes: 22 additions & 27 deletions backend/src/document_data/document_data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { DocumentDataView } from './entities/document_data_vw';
import { ProvisionService } from 'src/provision/provision.service';
import { DocumentTemplateService } from 'src/document_template/document_template.service';
import { DocumentType } from 'src/document_type/entities/document_type.entity';
import { DocumentTypeService } from 'src/document_type/document_type.service';

@Injectable()
export class DocumentDataService {
Expand All @@ -27,6 +28,7 @@ export class DocumentDataService {
private documentDataVariableRepository: Repository<DocumentDataVariable>,
private provisionService: ProvisionService,
private documentTemplateService: DocumentTemplateService,
private documentTypeService: DocumentTypeService,
private dataSource: DataSource
) {}

Expand All @@ -35,8 +37,8 @@ export class DocumentDataService {
provisionArray: { provision_id: number; free_text: string }[],
variableArray: { variable_id: number; variable_value: string }[]
): Promise<DocumentData> {
console.log(variableArray);
const { dtid, document_type_id } = documentDataDto;
// const documentType: DocumentType = await this.documentTemplateService.getDocumentType(document_type_id);
const documentData: DocumentData = await this.documentDataRepository.findOne({
where: { dtid: dtid, document_type: { id: document_type_id } },
relations: [
Expand Down Expand Up @@ -73,6 +75,8 @@ export class DocumentDataService {
documentDataDto.document_type_id
);
documentDataDto['template_id'] = documentTemplate ? documentTemplate.id : null;
documentDataDto['document_type'] = await this.documentTypeService.findById(document_type_id);
delete documentDataDto['document_type_id'];
const newDocumentData: DocumentData = this.documentDataRepository.create(documentDataDto);
const updatedDocumentData = await this.documentDataRepository.save(newDocumentData);

Expand Down Expand Up @@ -252,34 +256,31 @@ export class DocumentDataService {
provisionIds: number[];
variableIds: number[];
}> {
console.log(`document_type_id: ${document_type_id}, dtid: ${dtid}`);
try {
const documentData = await this.documentDataRepository.find({
where: { dtid: dtid },
join: {
alias: 'document_data',
leftJoinAndSelect: {
document_data_provisions: 'document_data.document_data_provisions',
document_provision: 'document_data_provisions.document_provision',
document_data_variables: 'document_data.document_data_variables',
document_variable: 'document_data_variables.document_variable',
relations: {
document_data_provisions: {
document_provision: true,
},
document_data_variables: {
document_variable: true,
},
document_type: true,
},
});
const filteredDocumentData = documentData.find((d) => d.document_type.id === document_type_id);
console.log(filteredDocumentData);
const filteredDocumentData = documentData.find((d) => d.document_type && d.document_type.id === document_type_id);
const provisionIds =
filteredDocumentData && filteredDocumentData.document_data_provisions
? filteredDocumentData.document_data_provisions.map((dataProvision) => dataProvision.document_provision.id)
: [];
filteredDocumentData?.document_data_provisions?.map((dataProvision) => dataProvision.document_provision.id) ??
[];
const variableIds =
filteredDocumentData && filteredDocumentData.document_data_variables
? filteredDocumentData.document_data_variables.map((dataVariable) => dataVariable.document_variable.id)
: [];
return { documentData: filteredDocumentData, provisionIds, variableIds };
filteredDocumentData?.document_data_variables?.map((dataVariable) => dataVariable.document_variable.id) ?? [];
return { documentData: filteredDocumentData || null, provisionIds, variableIds };
} catch (err) {
console.log('Error in findActiveByDtid');
console.log('Error in findDocumentDataByDocTypeIdAndDtid');
console.log(err);
return null;
return { documentData: null, provisionIds: [], variableIds: [] };
}
}

Expand Down Expand Up @@ -336,17 +337,11 @@ export class DocumentDataService {
.where('document_data.dtid = :dtid', { dtid })
.andWhere('document_data."documentTypeId" = :document_type_id', { document_type_id })
.getOne();
console.log(documentData);

// if the documentData doesn't exist yet, return null. This null value is caught elsewhere.
if (!documentData) {
return null;
}

// saved provisions attached to the dtid
const existingDataProvisions: DocumentDataProvision[] = [];
existingDataProvisions.push(...documentData.document_data_provisions);
// all provisions
if (documentData) existingDataProvisions.push(...documentData.document_data_provisions);
// all provisions with the specified document_type_id
const provisions: Provision[] = await this.provisionService.getAllProvisionsByDocTypeId(document_type_id);
const provisionIds = existingDataProvisions.map((dataProvision) => dataProvision.document_provision.id);
return { provisions, provisionIds };
Expand Down
4 changes: 2 additions & 2 deletions backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ async function bootstrap() {
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);
const appService = app.get(AppService);
await appService.initializeDb();
// await appService.initializeDb();

await app.listen(3001);
await app.listen(3000);
}
bootstrap();
2 changes: 1 addition & 1 deletion backend/src/ormconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const config: TypeOrmModuleOptions = {
DocumentTemplate,
DocumentType,
],
synchronize: true,
synchronize: false,
};

export default config;
13 changes: 6 additions & 7 deletions backend/src/provision/provision.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,15 @@ export class ProvisionService {
const provisions: Provision[] = await this.provisionRepository
.createQueryBuilder('provision')
.innerJoinAndSelect('provision.provision_group', 'provision_group')
.innerJoin('provision_group.document_type', 'document_type')
.where('document_type.id = :document_type_id', { document_type_id })
.andWhere('is_deleted = false')
.innerJoin('provision.document_types', 'document_type', 'document_type.id = :document_type_id', {
document_type_id,
})
.where('provision.is_deleted = false')
.getMany();

return provisions;
} catch (err) {
console.log('Error in getAllProvisionsByDocTypeId');
console.log(err);
return null;
console.error('Error in getAllProvisionsByDocTypeId', err);
return [];
}
}

Expand Down
33 changes: 15 additions & 18 deletions backend/src/report/report.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,28 @@ export class ReportController {
};
}

// @Get('get-data/:dtid')
// async getData(@Session() session: { data?: SessionData }, @Param('dtid') dtid: number) {
// console.log(dtid);
// console.log(session);
// await this.reportService.getTtlsDataByDtid(dtid);
// await this.ttlsService.setWebadeToken();
// const response: any = await firstValueFrom(this.ttlsService.callHttp(dtid))
// .then((res) => {
// return res;
// })
// .catch((err) => {
// console.log('callHttp failed');
// console.log(err);
// console.log(err.response.data);
// });
// return response;
// }
// Gets data from ttls route for displaying on report page
@Get('get-data/:dtid')
async getData(@Session() session: { data?: SessionData }, @Param('dtid') dtid: number) {
await this.ttlsService.setWebadeToken();
const response: any = await firstValueFrom(this.ttlsService.callHttp(dtid))
.then((res) => {
return res;
})
.catch((err) => {
console.log('callHttp failed');
console.log(err);
console.log(err.response.data);
});
return response;
}

@Get('get-document-data/:document_type_id/:dtid')
getDocumentDataByDocTypeIdAndDtid(
@Session() session: { data?: SessionData },
@Param('document_type_id') document_type_id: number,
@Param('dtid') dtid: number
) {
console.log('get-document-data ~ dtid:' + dtid + ', doctypeid: ' + document_type_id);
return this.reportService.getDocumentDataByDocTypeIdAndDtid(document_type_id, dtid);
}

Expand Down
82 changes: 7 additions & 75 deletions backend/src/report/report.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { DocumentDataService } from 'src/document_data/document_data.service';
import { DocumentTemplate } from 'src/document_template/entities/document_template.entity';
import { DocumentDataLogService } from 'src/document_data_log/document_data_log.service';
import { DocumentTypeService } from 'src/document_type/document_type.service';
import { Provision } from 'src/provision/entities/provision.entity';
const axios = require('axios');

// generate report needs to be consolidated which is impossible until we figure out how provisions & variables will be dynamically inserted into the docx files
Expand Down Expand Up @@ -750,54 +751,11 @@ export class ReportService {
return response2.data;
}

async getDocumentProvisionsByDocTypeIdAndDtid(document_type_id: number, dtid: number): Promise<any> {
const returnItems = [
'type',
'provision_name',
'help_text',
'free_text',
'category',
'provision_group',
'id',
'mandatory',
];
let reduced, provisions;
// nfrDataId exists so return a list of provisions with pre-existing free_text data inserted, certain provisions preselected
const documentProvisions = await this.documentDataService.getProvisionsByDocTypeIdAndDtid(document_type_id, dtid);
if (documentProvisions) {
const provisionIds = documentProvisions.provisionIds;
provisions = documentProvisions.provisions;
reduced = provisions.map((obj) => {
if (provisionIds.includes(obj.id)) {
obj.select = true;
} else {
obj.select = false;
}
return obj;
});
} else {
// no nfrDataId so just return generic provisions with all of them deselected by default
provisions = await this.provisionService.getProvisionsByDocumentTypeId(document_type_id);
reduced = provisions.map((obj) =>
Object.keys(obj)
.filter((key) => returnItems.includes(key))
.reduce(
(acc, key) => {
acc[key] = obj[key];
return acc;
},
{ select: false }
)
);
}
// make the returned data readable for the ajax request
return reduced.map((obj) => {
const groupObj = obj.provision_group;
delete obj['provision_group'];
obj['max'] = groupObj.max;
obj['provision_group'] = groupObj.provision_group;
return obj;
});
async getDocumentProvisionsByDocTypeIdAndDtid(
document_type_id: number,
dtid: number
): Promise<{ provisions: Provision[]; provisionIds: number[] }> {
return this.documentDataService.getProvisionsByDocTypeIdAndDtid(document_type_id, dtid);
}

getGroupMaxByDocTypeId(document_type_id: number): Promise<any> {
Expand Down Expand Up @@ -856,32 +814,6 @@ export class ReportService {

async getDocumentDataByDocTypeIdAndDtid(document_type_id: number, dtid: number): Promise<any> {
return this.documentDataService.findDocumentDataByDocTypeIdAndDtid(document_type_id, dtid);
// const url = `${hostname}:${port}/document-data/dtid/${dtid}`;
// const response = await axios
// .get(url, {
// headers: {
// 'Content-Type': 'application/json',
// },
// })
// .then((res) => {
// return res.data;
// });
// // const documentData = await this.documentDataService.findActiveByDtid(dtid);
// // console.log('!!!~~~~~~~~');
// // console.log("this.getGroupMaxByVariant('NOTICE OF FINAL REVIEW')");
// // const groupMax = await this.getGroupMaxByVariant('NOTICE OF FINAL REVIEW');
// // // console.log(groupMax);
// // console.log('\ngetActiveNfrDataByDtid');
// // console.log(response);
// // console.log('\ndocument_data_provisions');
// // // console.log(response.nfrData.document_data_provisions);
// // console.log('\ndocument_data_variables');
// // // console.log(response.nfrData.document_data_variables);
// // console.log('\nthis.getMandatoryProvisionsByVariant(NOTICE OF FINAL REVIEW)');
// // const mandatoryProvisions = await this.getMandatoryProvisionsByVariant('NOTICE OF FINAL REVIEW');
// // // console.log(mandatoryProvisions);
// // console.log('~~~~~~~~!!!');
// return response;
}

// async saveNFR(
Expand Down Expand Up @@ -928,7 +860,7 @@ export class ReportService {
const data = {
dtid: dtid,
document_type_id: document_type_id,
template_id: documentTemplate.id,
template_id: documentTemplate ? documentTemplate.id : null,
status: status,
create_userid: idir_username,
ttls_data: [],
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ContentWrapper from './content/ContentWrapper';
import SystemAdministration from './content/pages/SystemAdministration';
import ManageProvisionsPage from './content/pages/ManageProvisionsPage';
import ManageDocumentsPage from './content/pages/ManageDocumentsPage';
import DocumentPreview from './content/pages/documentpreview/DocumentPreview';

const App: FC = () => {
// used to render report pages
Expand All @@ -29,6 +30,14 @@ const App: FC = () => {
<Router>
<Header idirUsername="Michael" isAdmin={true} />
<Routes>
<Route
path={`/`}
element={
<ContentWrapper>
<DocumentPreview />
</ContentWrapper>
}
/>
<Route
path={`/search`}
element={
Expand Down
36 changes: 15 additions & 21 deletions frontend/src/app/common/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,20 @@ import { DTR, DTRDisplayObject, DocType, DocumentDataObject, ProvisionGroup } fr
import { buildDTRDisplayData } from '../util/util';
import * as api from './api';

// /**
// * Gets ttls data and parses it for displaying
// *
// * @param dtid
// * @returns
// */
// export async function getData(dtid: number): Promise<DTRDisplayObject> {
// const dataUrl = `${config.API_BASE_URL}/report/get-data/${dtid}`;

// const data: DTR = await api.get({ url: dataUrl });
// const displayData = buildDTRDisplayData(data);
// return displayData;
// }

export async function getData(document_type_id: number, dtid: number): Promise<DTRDisplayObject> {
const dataUrl = `${config.API_BASE_URL}/report/get-document-data/${document_type_id}/${dtid}`;
const data: DTR = await api.get({ url: dataUrl });
console.log(data);
/**
* Gets ttls data and parses it for displaying
*
* @param dtid
* @returns
*/
export async function getDisplayData(dtid: number): Promise<DTRDisplayObject> {
const url = `${config.API_BASE_URL}/report/get-data/${dtid}`;
const getParameters = api.generateApiParameters(url);
const data: DTR = await api.get<DTR>(getParameters);
const displayData = buildDTRDisplayData(data);
return displayData;
}

/** Section for Notice of Final Review which has lots of custom logic */
export const getDocumentDataByDocTypeIdAndDtid = async (document_type_id: number, dtid: number) => {
const url = `${config.API_BASE_URL}/report/get-document-data/${document_type_id}/${dtid}`;
const getParameters = api.generateApiParameters(url);
Expand All @@ -54,10 +45,13 @@ export const getMandatoryProvisionsByDocTypeId = async (document_type_id: number
export const getDocumentProvisionsByDocTypeIdDtid = async (
document_type_id: number,
dtid: number
): Promise<ProvisionData[]> => {
): Promise<{ provisions: ProvisionData[]; provisionIds: number[] }> => {
const url = `${config.API_BASE_URL}/report/provisions/${document_type_id}/${dtid}`;
const getParameters = api.generateApiParameters(url);
const response: ProvisionData[] = await api.get<ProvisionData[]>(getParameters);
const response: { provisions: ProvisionData[]; provisionIds: number[] } = await api.get<{
provisions: ProvisionData[];
provisionIds: number[];
}>(getParameters);
return response;
};

Expand Down
Loading

0 comments on commit 13b46c5

Please sign in to comment.