Skip to content

Commit

Permalink
code smells delete
Browse files Browse the repository at this point in the history
  • Loading branch information
nkarmazina committed Oct 19, 2023
1 parent 760934c commit 88576ae
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions frontend/src/app/Services/block.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,30 +210,46 @@ export class BlockService {
else return 0;
}

/**
* Сhecking whether the block is used as a reference
* @param blockReferenceId
* @param blocks
* @param stories
*/
/**
* Сhecking whether the block is used as a reference
* @param blockReferenceId
* @param blocks
* @param stories
*/
checkBlockOnReference(blocks:Block[], stories: Story[], blockReferenceId){
if (!this.isBlockReferencedInScenarios(blockReferenceId,stories)) {
this.updateBlockReferenceStatus(blockReferenceId, blocks);
}
}

/**
* check if a block is referenced in any scenario step definitions
* @param blockReferenceId
* @param stories
*/
isBlockReferencedInScenarios(blockReferenceId: string, stories): boolean {
this.searchReferences(stories);
let blockNoLongerRef = true;
for (const scen of this.referenceScenarios){
for (const scen of this.referenceScenarios) {
for (const prop in scen.stepDefinitions) {
for (let i = scen.stepDefinitions[prop].length - 1; i >= 0; i--) {
if (scen.stepDefinitions[prop][i]._blockReferenceId == blockReferenceId) {
blockNoLongerRef = false;
return true;
}
}
}
}
if (blockNoLongerRef){
for (const block of blocks){
if(block._id === blockReferenceId){
block.usedAsReference = false;
this.referencesBlocks.push(block);
}
return false;
}
/**
* update block reference status
* @param blockReferenceId
* @param blocks
*/
updateBlockReferenceStatus(blockReferenceId: string, blocks): void {
for (const block of blocks) {
if (block._id === blockReferenceId) {
block.usedAsReference = false;
this.referencesBlocks.push(block);
}
}
}
Expand Down

0 comments on commit 88576ae

Please sign in to comment.