Skip to content

Commit

Permalink
Merge pull request #236 from bcgov/ticdi-103_doc-type-deletion-issue
Browse files Browse the repository at this point in the history
delete all data related to doc type on deletion
  • Loading branch information
mgtennant authored Sep 24, 2024
2 parents 5370920 + f34d0a6 commit 5ce65af
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 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 @@ -10,9 +10,10 @@ import { DocumentTypeModule } from 'src/document_type/document_type.module';
import { JWTAuthModule } from 'src/auth/jwtauth.module';
import { JwtAuthGuard } from 'src/auth/jwtauth.guard';
import { TTLSService } from 'src/ttls/ttls.service';
import { DocumentDataModule } from 'src/document_data/document_data.module';

@Module({
imports: [HttpModule, JWTAuthModule, DocumentTemplateModule, ProvisionModule, DocumentTypeModule],
imports: [HttpModule, JWTAuthModule, DocumentTemplateModule, ProvisionModule, DocumentTypeModule, DocumentDataModule],
providers: [AdminGuard, AdminService, JwtAuthGuard, TTLSService],
exports: [AdminService],
controllers: [AdminController],
Expand Down
10 changes: 9 additions & 1 deletion backend/src/admin/admin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DocumentTypeService } from 'src/document_type/document_type.service';
import { DocumentType } from 'src/document_type/entities/document_type.entity';
import { TTLSService } from 'src/ttls/ttls.service';
import { Role } from 'src/enum/role.enum';
import { DocumentDataService } from 'src/document_data/document_data.service';

const axios = require('axios');

Expand All @@ -20,7 +21,8 @@ export class AdminService {
private readonly ttlsService: TTLSService,
private readonly documentTemplateService: DocumentTemplateService,
private readonly provisionService: ProvisionService,
private readonly documentTypeService: DocumentTypeService
private readonly documentTypeService: DocumentTypeService,
private readonly documentDataService: DocumentDataService
) {
hostname = process.env.backend_url ? process.env.backend_url : `http://localhost`;
// local development backend port is 3001, docker backend port is 3000
Expand Down Expand Up @@ -443,6 +445,12 @@ export class AdminService {
try {
// remove the related doc type provisions
await this.provisionService.removeDocTypeProvisions(document_type_id);
// remove the related doc type provision groups
await this.documentTypeService.removeProvisionGroupByDocTypeId(document_type_id);
// remove templates related to the doc type
await this.documentTemplateService.removeByDocTypeId(document_type_id);
// remove the related doc type data
await this.documentDataService.removeByDocTypeId(document_type_id);
// remove the doc type
await this.documentTypeService.remove(document_type_id);
} catch (err) {
Expand Down
6 changes: 6 additions & 0 deletions backend/src/document_data/document_data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,4 +452,10 @@ export class DocumentDataService {
return { deleted: false, message: err.message };
}
}

async removeByDocTypeId(document_type_id: number) {
return this.documentDataRepository.delete({
document_type: { id: document_type_id },
});
}
}
4 changes: 4 additions & 0 deletions backend/src/document_template/document_template.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ export class DocumentTemplateService {
return { id: 0 };
}

async removeByDocTypeId(document_type_id: number): Promise<void> {
await this.documentTemplateRepository.delete({ document_type: { id: document_type_id } });
}

async findAll(document_type_id: number): Promise<DocumentTemplate[]> {
return this.documentTemplateRepository.find({
where: { is_deleted: false, document_type: { id: document_type_id } },
Expand Down
4 changes: 4 additions & 0 deletions backend/src/document_type/document_type.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ export class DocumentTypeService {
}
}

async removeProvisionGroupByDocTypeId(document_type_id: number) {
return this.provisionGroupRepository.delete({ document_type: { id: document_type_id } });
}

async updateGroupMaximums(provision_group: number, max: number, provision_group_text: string) {
let provisionGroup: ProvisionGroup = await this.provisionGroupRepository.findOneBy({
provision_group: provision_group,
Expand Down

0 comments on commit 5ce65af

Please sign in to comment.