Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticdi 104 #226

Merged
merged 4 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion backend/src/document_data/document_data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,21 @@ export class DocumentDataService {
return null;
}

// Used by the search page.
// Used by the search page. *can probably be removed*
async findAll(): Promise<DocumentData[]> {
return await this.documentDataRepository.find({
relations: ['document_type'],
});
}

// Used by the search page. Filters document data for inactive doc types
async findAllWithActiveDT(): Promise<DocumentData[]> {
const documentData = await this.documentDataRepository.find({
relations: ['document_type'],
});
return documentData.filter((data) => data.document_type.active === true);
}

async findByDocumentDataId(documentDataId: number): Promise<{
documentData: DocumentData;
provisionIds: number[];
Expand Down
20 changes: 15 additions & 5 deletions backend/src/document_type/document_type.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ import { JwtAuthGuard } from 'src/auth/jwtauth.guard';
export class DocumentTypeController {
constructor(private documentTypeService: DocumentTypeService) {}

@Get(':id')
findById(@Param('id') id: number) {
return this.documentTypeService.findById(id);
}

@Post('update')
update(
@Body() data: { id: number; name: string; prefix: string; created_by: string; created_date: string },
Expand All @@ -35,6 +30,11 @@ export class DocumentTypeController {
return this.documentTypeService.findAll();
}

@Get('active-doc-types')
findActiveDocTypes() {
return this.documentTypeService.findActiveDocTypes();
}

@Get('get-group-max/:document_type_id')
getGroupMaxByDocTypeId(@Param('document_type_id') document_type_id: number) {
return this.documentTypeService.getGroupMaxByDocTypeId(document_type_id);
Expand All @@ -61,4 +61,14 @@ export class DocumentTypeController {
removeProvisionGroup(@Body() data: { provision_group_id: number }) {
return this.documentTypeService.removeProvisionGroup(data.provision_group_id);
}

@Get('activate/:document_type_id')
activateDocType(@Param('document_type_id') id: number) {
return this.documentTypeService.activateDocType(id);
}

@Get('deactivate/:document_type_id')
deactivateDocType(@Param('document_type_id') id: number) {
return this.documentTypeService.deactivateDocType(id);
}
}
13 changes: 13 additions & 0 deletions backend/src/document_type/document_type.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,17 @@ export class DocumentTypeService {
return accumulator;
}, []);
}

findActiveDocTypes() {
return this.documentTypeRepository.find({ where: { active: true } });
}

// Active variable determines whether or not doc type is displayed in drop down lists
activateDocType(id: number) {
return this.documentTypeRepository.update(id, { active: true });
}

deactivateDocType(id: number) {
return this.documentTypeRepository.update(id, { active: false });
}
}
5 changes: 4 additions & 1 deletion backend/src/document_type/entities/document_type.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ export class DocumentType {
@Column()
name: string;

@Column()
@Column({ nullable: true })
prefix: string;

@Column({ nullable: true })
active: boolean;

@Column({ nullable: true })
created_by: string;

Expand Down
11 changes: 10 additions & 1 deletion backend/src/report/report.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,15 @@ export class ReportService {
// Format provisions in a way that the document template expects
const groupIndexMap = new Map<number, number>();
const showProvisionSections: Record<string, any> = {};

// Format the provisions so that provision free_text gets passed into the document template
provisionJson.sort((a, b) => {
if (a.provision_group === b.provision_group) {
return a.sequence_value - b.sequence_value;
}
return a.provision_group - b.provision_group;
});

provisionJson.forEach((provision) => {
const group = provision.provision_group;
const index = (groupIndexMap.get(group) ?? 0) + 1;
Expand Down Expand Up @@ -987,7 +996,7 @@ export class ReportService {
}

async getDocumentData() {
const documentData = await this.documentDataService.findAll();
const documentData = await this.documentDataService.findAllWithActiveDT();
const templateIds = documentData.map((d) => d.template_id);
const allTemplates = await this.documentTemplateService.getTemplatesInfoByIds(templateIds);

Expand Down
Loading
Loading