Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mgtennant committed Mar 18, 2024
1 parent 678e338 commit e6f190a
Show file tree
Hide file tree
Showing 40 changed files with 660 additions and 841 deletions.
3 changes: 2 additions & 1 deletion backend/src/admin/admin.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { AdminService } from './admin.service';
import { AdminController } from './admin.controller';
import { AuthenticationModule } from 'src/authentication/authentication.module';
import { DocumentTemplateModule } from 'src/document_template/document_template.module';
import { ProvisionModule } from 'src/provision/provision.module';

@Module({
imports: [HttpModule, AuthenticationModule, DocumentTemplateModule],
imports: [HttpModule, AuthenticationModule, DocumentTemplateModule, ProvisionModule],
providers: [AdminGuard, AdminService],
exports: [AdminService],
controllers: [AdminController],
Expand Down
2 changes: 1 addition & 1 deletion backend/src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ export class AppController {
// const groupMaxJsonArray = await this.reportService.getGroupMaxByVariant('NOTICE OF FINAL REVIEW');
const groupMaxJsonArray = [];
try {
const nfrDataObject = await this.reportService.getActiveNfrDataByDtid(dtid);
const nfrDataObject = await this.reportService.getDocumentDataByDocTypeIdAndDtid(1, dtid);
nfrData = nfrDataObject.nfrData;
const provisionIds = nfrDataObject.provisionIds ? nfrDataObject.provisionIds : [];
// const mandatoryProvisionIds = await this.reportService.getMandatoryProvisionsByVariant(variantName);
Expand Down
6 changes: 3 additions & 3 deletions backend/src/document_data/document_data.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export class DocumentDataController {
}
}

@Get('dtid/:dtid')
findActiveByDtid(@Param('dtid') dtid: number) {
return this.documentDataService.findActiveByDtid(dtid);
@Get('dtid/:document_type_id/:dtid')
findActiveByDtid(@Param('dtid') dtid: number, @Param('document_type_id') document_type_id: number) {
return this.documentDataService.findDocumentDataByDocTypeIdAndDtid(document_type_id, dtid);
}

@Get('view/:documentDataId')
Expand Down
179 changes: 95 additions & 84 deletions backend/src/document_data/document_data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class DocumentDataService {
'document_data_variables',
'document_data_provisions',
'document_data_variables.document_variable',
'document_data_provisions.provision',
'document_data_provisions.document_provision',
'document_type',
],
});
Expand Down Expand Up @@ -210,6 +210,7 @@ export class DocumentDataService {
where: {
active: true,
},
relations: ['document_type'],
});
}

Expand Down Expand Up @@ -237,39 +238,46 @@ export class DocumentDataService {
const variableIds = existingDataVariables.map((dataVariable) => dataVariable.document_variable.id);
return { documentData, provisionIds, variableIds };
} catch (err) {
console.log('Error in findByDocumentDataId');
console.log(err);
return null;
}
}

async findActiveByDtid(dtid: number): Promise<{
async findDocumentDataByDocTypeIdAndDtid(
document_type_id: number,
dtid: number
): Promise<{
documentData: DocumentData;
provisionIds: number[];
variableIds: number[];
}> {
try {
const documentData = await this.documentDataRepository.findOne({
where: { dtid: dtid, active: true },
const documentData = await this.documentDataRepository.find({
where: { dtid: dtid },
join: {
alias: 'document_data',
leftJoinAndSelect: {
document_data_provisions: 'document_data.document_data_provisions',
provision: 'document_data_provisions.provision',
document_provision: 'document_data_provisions.document_provision',
document_data_variables: 'document_data.document_data_variables',
document_variable: 'document_data_variables.document_variable',
},
},
});
const filteredDocumentData = documentData.find((d) => d.document_type.id === document_type_id);
console.log(filteredDocumentData);
const provisionIds =
documentData && documentData.document_data_provisions
? documentData.document_data_provisions.map((dataProvision) => dataProvision.document_provision.id)
filteredDocumentData && filteredDocumentData.document_data_provisions
? filteredDocumentData.document_data_provisions.map((dataProvision) => dataProvision.document_provision.id)
: [];
const variableIds =
documentData && documentData.document_data_variables
? documentData.document_data_variables.map((dataVariable) => dataVariable.document_variable.id)
filteredDocumentData && filteredDocumentData.document_data_variables
? filteredDocumentData.document_data_variables.map((dataVariable) => dataVariable.document_variable.id)
: [];
return { documentData, provisionIds, variableIds };
return { documentData: filteredDocumentData, provisionIds, variableIds };
} catch (err) {
console.log('Error in findActiveByDtid');
console.log(err);
return null;
}
Expand All @@ -282,92 +290,95 @@ export class DocumentDataService {
}

async getVariablesByDtidAndDocType(dtid: number, document_type_id: number) {
// 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 } },
join: {
alias: 'document_data',
leftJoinAndSelect: {
document_data_variables: 'document_data.document_data_variables',
document_variable: 'document_data_variables.document_variable',
try {
const documentData: DocumentData = await this.documentDataRepository.findOne({
where: { dtid: dtid, document_type: { id: document_type_id } },
join: {
alias: 'document_data',
leftJoinAndSelect: {
document_data_variables: 'document_data.document_data_variables',
document_variable: 'document_data_variables.document_variable',
},
},
},
});
// if the documentData doesn't exist yet, return null. This null value is caught elsewhere.
if (!documentData) {
return null;
}
// saved variables attached to the documentData entry
const existingDataVariables: DocumentDataVariable[] = documentData.document_data_variables;
// all variables associated with the variant
const variables: ProvisionVariable[] = await this.provisionService.getVariablesByDocumentTypeId(document_type_id);
// inserting the existing variable_values to the set of all variables
for (const variable of variables) {
const existingDataVariable = existingDataVariables.find(
(dataVariable) => dataVariable.document_variable.id === variable.id
);
if (existingDataVariable) {
variable.variable_value = existingDataVariable.data_variable_value;
});
// if the documentData doesn't exist yet, return null. This null value is caught elsewhere.
if (!documentData) {
return null;
}
// saved variables attached to the documentData entry
const existingDataVariables: DocumentDataVariable[] = documentData.document_data_variables;
// all variables associated with the variant
const variables: ProvisionVariable[] = await this.provisionService.getVariablesByDocumentTypeId(document_type_id);
// inserting the existing variable_values to the set of all variables
for (const variable of variables) {
const existingDataVariable = existingDataVariables.find(
(dataVariable) => dataVariable.document_variable.id === variable.id
);
if (existingDataVariable) {
variable.variable_value = existingDataVariable.data_variable_value;
}
}
const variableIds = existingDataVariables.map((dataVariable) => dataVariable.document_variable.id);
return { variables, variableIds };
} catch (err) {
console.log('Error in getVariablesByDtidAndDocType');
console.log(err);
return null;
}
const variableIds = existingDataVariables.map((dataVariable) => dataVariable.document_variable.id);
return { variables, variableIds };
}

async getProvisionsByDocTypeIdAndDtid(document_type_id: number, dtid: number) {
const documentData: DocumentData = await this.documentDataRepository.findOne({
where: { dtid: dtid, document_type: { id: document_type_id } },
join: {
alias: 'document_data',
leftJoinAndSelect: {
document_data_provisions: 'document_data.document_data_provisions',
provision: 'document_data_provisions.provision',
},
},
});
// if the documentData doesn't exist yet, return null. This null value is caught elsewhere.
if (!documentData) {
return null;
}
// documentData for all variants of this dtid
const fullDocumentData: DocumentData[] = await this.documentDataRepository.find({
where: { dtid: documentData.dtid },
join: {
alias: 'document_data',
leftJoinAndSelect: {
document_data_provisions: 'document_data.document_data_provisions',
provision: 'document_data_provisions.provision',
},
},
});
try {
const documentData = await this.documentDataRepository
.createQueryBuilder('document_data')
.leftJoinAndSelect('document_data.document_data_provisions', 'document_data_provisions')
.leftJoinAndSelect('document_data_provisions.document_provision', 'provision')
.where('document_data.dtid = :dtid', { dtid })
.andWhere('document_data."documentTypeId" = :document_type_id', { document_type_id })
.getOne();
console.log(documentData);

// saved provisions attached to the dtid
const existingDataProvisions: DocumentDataProvision[] = [];
fullDocumentData.forEach((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
const provisions: Provision[] = await this.provisionService.getAllProvisions();
const provisionIds = existingDataProvisions.map((dataProvision) => dataProvision.document_provision.id);
return { provisions, provisionIds };
// all provisions
const provisions: Provision[] = await this.provisionService.getAllProvisionsByDocTypeId(document_type_id);
const provisionIds = existingDataProvisions.map((dataProvision) => dataProvision.document_provision.id);
return { provisions, provisionIds };
} catch (err) {
console.log('Error in getProvisionsByDocTypeIdAndDtid');
console.log(err);
return null;
}
}

async getEnabledProvisionsByDocTypeIdAndDtid(document_type_id: number, dtid: number) {
const documentData: DocumentData = await this.documentDataRepository.findOne({
where: { dtid: dtid, document_type: { id: document_type_id } },
join: {
alias: 'document_data',
leftJoinAndSelect: {
document_data_provisions: 'document_data.document_data_provisions',
provision: 'document_data_provisions.provision',
try {
const documentData: DocumentData = await this.documentDataRepository.findOne({
where: { dtid: dtid, document_type: { id: document_type_id } },
join: {
alias: 'document_data',
leftJoinAndSelect: {
document_data_provisions: 'document_data.document_data_provisions',
provision: 'document_data_provisions.provision',
},
},
},
});
const provisionIds =
documentData && documentData.document_data_provisions
? documentData.document_data_provisions.map((dataProvision) => dataProvision.document_provision.id)
: [];
return provisionIds;
});
const provisionIds =
documentData && documentData.document_data_provisions
? documentData.document_data_provisions.map((dataProvision) => dataProvision.document_provision.id)
: [];
return provisionIds;
} catch (err) {
console.log('Error in getEnabledProvisionsByDocTypeIdAndDtid');
console.log(err);
return null;
}
}

async remove(dtid: number): Promise<{ deleted: boolean; message?: string }> {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/document_data_log/document_data_log.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export class DocumentDataLogService {
async create(documentDataLog: CreateDocumentDataLogDto): Promise<DocumentDataLog> {
const newItem = new DocumentDataLog();
newItem.document_template_id = documentDataLog.document_template_id;
newItem.document_data_id = documentDataLog.document_data_id;
newItem.dtid = documentDataLog.dtid;
newItem.request_app_user = documentDataLog.request_app_user;
newItem.request_json = documentDataLog.request_json;
Expand All @@ -35,10 +34,11 @@ export class DocumentDataLogService {
});
}

async findNextVersion(dtid: number): Promise<string> {
async findNextVersion(dtid: number, document_type_id: number): Promise<string> {
const requestLogs = await this.documentDataLogRepository.findAndCount({
where: {
dtid: dtid,
document_type_id: document_type_id,
},
});
let version = (requestLogs[1] + 1).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { DocumentDataLogDto } from './document_data_log.dto';

export class CreateDocumentDataLogDto extends PickType(DocumentDataLogDto, [
'dtid',
'document_data_id',
'document_type_id',
'document_template_id',
'request_app_user',
Expand Down
1 change: 0 additions & 1 deletion backend/src/document_data_log/dto/document_data_log.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export class DocumentDataLogDto {
dtid: number;
document_data_id: number;
document_type_id: number;
document_template_id: number;
request_app_user: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { DocumentDataLogDto } from './document_data_log.dto';

export class UpdateDocumentDataLogDto extends PickType(DocumentDataLogDto, [
'dtid',
'document_data_id',
'document_type_id',
'document_template_id',
'request_app_user',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ export class DocumentDataLog {
@Column({ nullable: true })
dtid: number;
@Column({ nullable: true })
document_data_id: number;
@Column({ nullable: true })
document_type_id: number;
@Column({ nullable: true })
document_template_id: number;
Expand All @@ -27,7 +25,6 @@ export class DocumentDataLog {

constructor(
dtid?: number,
document_data_id?: number,
document_type_id?: number,
document_template_id?: number,
request_app_user?: string,
Expand All @@ -36,7 +33,6 @@ export class DocumentDataLog {
update_userid?: string
) {
this.dtid = dtid || null;
this.document_data_id = document_data_id || null;
this.document_type_id = document_type_id || null;
this.document_template_id = document_template_id || null;
this.request_app_user = request_app_user || '';
Expand Down
5 changes: 5 additions & 0 deletions backend/src/document_type/entities/document_type.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { DocumentTemplate } from '../../document_template/entities/document_template.entity';
import { DocumentData } from 'src/document_data/entities/document_data.entity';
import { Provision } from 'src/provision/entities/provision.entity';
import { ProvisionGroup } from 'src/provision/entities/provision_group.entity';

@Entity()
export class DocumentType {
Expand All @@ -35,6 +36,10 @@ export class DocumentType {
document_data: DocumentData[];
@ManyToMany(() => Provision, (provision) => provision.document_types)
provisions: Provision[];
@OneToMany(() => ProvisionGroup, (provisionGroup) => provisionGroup.document_type, {
cascade: true,
})
provision_groups: ProvisionGroup[];

constructor(name?: string, create_userid?: string, update_userid?: string) {
this.name = name || '';
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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);
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/provision/entities/provision.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class Provision {
document_data_provisions: DocumentDataProvision[];
@ManyToMany(() => DocumentType)
@JoinTable({
name: 'provision_document_type', // Name of the join table
name: 'provision_document_type',
joinColumn: {
name: 'provision_id',
referencedColumnName: 'id',
Expand Down
Loading

0 comments on commit e6f190a

Please sign in to comment.