Skip to content

Commit 11bcdb2

Browse files
committed
test variation delete added
1 parent dbccc3b commit 11bcdb2

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

src/test-variations/test-variations.controller.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Controller, ParseUUIDPipe, Get, UseGuards, Param, Query, Put, Body } from '@nestjs/common';
1+
import { Controller, ParseUUIDPipe, Get, UseGuards, Param, Query, Put, Body, Delete } from '@nestjs/common';
22
import { ApiTags, ApiParam, ApiBearerAuth, ApiQuery, ApiOkResponse } from '@nestjs/swagger';
33
import { TestVariationsService } from './test-variations.service';
44
import { TestVariation, Baseline } from '@prisma/client';
@@ -56,7 +56,18 @@ export class TestVariationsController {
5656
@ApiOkResponse({ type: BuildDto })
5757
@ApiBearerAuth()
5858
@UseGuards(JwtAuthGuard)
59-
merge(@Query('projectId') projectId: string, @Query('branchName') branchName: string): Promise<BuildDto> {
59+
merge(
60+
@Query('projectId', new ParseUUIDPipe()) projectId: string,
61+
@Query('branchName') branchName: string
62+
): Promise<BuildDto> {
6063
return this.testVariations.merge(projectId, branchName);
6164
}
65+
66+
@Delete(':id')
67+
@ApiParam({ name: 'id', required: true })
68+
@ApiBearerAuth()
69+
@UseGuards(JwtAuthGuard)
70+
delete(@Param('id', new ParseUUIDPipe()) id: string): Promise<TestVariation> {
71+
return this.testVariations.delete(id);
72+
}
6273
}

src/test-variations/test-variations.service.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Injectable, Inject, forwardRef } from '@nestjs/common';
22
import { IgnoreAreaDto } from '../test-runs/dto/ignore-area.dto';
33
import { PrismaService } from '../prisma/prisma.service';
4-
import { TestVariation, Baseline, Project, Build } from '@prisma/client';
4+
import { TestVariation, Baseline, Project, Build, TestRun } from '@prisma/client';
55
import { StaticService } from '../shared/static/static.service';
66
import { CommentDto } from '../shared/dto/comment.dto';
77
import { BaselineDataDto, convertBaselineDataToQuery } from '../shared/dto/baseline-data.dto';
@@ -165,4 +165,31 @@ export class TestVariationsService {
165165

166166
return build;
167167
}
168+
169+
async delete(id: string): Promise<TestVariation> {
170+
const [testVariation, testRuns] = await Promise.all([
171+
this.getDetails(id),
172+
this.prismaService.testRun.findMany({
173+
where: { testVariationId: id },
174+
})
175+
])
176+
177+
// delete testRun
178+
await Promise.all(testRuns.map(item => this.testRunsService.delete(item.id)));
179+
180+
// delete baseline
181+
await Promise.all(testVariation.baselines.map(baseline => this.deleteBaseline(baseline)));
182+
183+
// delete testVariation
184+
return this.prismaService.testVariation.delete({
185+
where: { id },
186+
});
187+
}
188+
189+
private async deleteBaseline(baseline: Baseline): Promise<Baseline> {
190+
this.staticService.deleteImage(baseline.baselineName);
191+
return this.prismaService.baseline.delete({
192+
where: { id: baseline.id },
193+
});
194+
}
168195
}

0 commit comments

Comments
 (0)