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

delete all data related to doc type on deletion #236

Merged
merged 1 commit into from
Sep 24, 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
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
Loading