Skip to content

Commit 5b1dfee

Browse files
committed
add delete method
1 parent 151c002 commit 5b1dfee

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

apps/api/src/setup/setup.controller.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RouteAccess } from '@douglasneuroinformatics/libnest';
2-
import { Body, Controller, Get, Patch, Post } from '@nestjs/common';
2+
import { Body, Controller, Delete, Get, Patch, Post } from '@nestjs/common';
33
import { ApiOperation, ApiTags } from '@nestjs/swagger';
44
import type { SetupState } from '@opendatacapture/schemas/setup';
55

@@ -12,6 +12,12 @@ import { SetupService } from './setup.service';
1212
export class SetupController {
1313
constructor(private readonly setupService: SetupService) {}
1414

15+
@Delete()
16+
@RouteAccess({ action: 'delete', subject: 'all' })
17+
async delete(): Promise<void> {
18+
return this.setupService.delete();
19+
}
20+
1521
@ApiOperation({
1622
description: 'Return the current setup state',
1723
summary: 'Get State'

apps/api/src/setup/setup.service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ export class SetupService {
2020
return this.usersService.create({ ...admin, basePermissionLevel: 'ADMIN', groupIds: [] });
2121
}
2222

23+
async delete(): Promise<void> {
24+
const isTest = this.configService.get('NODE_ENV') === 'test';
25+
if (!isTest) {
26+
throw new ForbiddenException('Cannot access outside of test');
27+
}
28+
await this.prismaService.dropDatabase();
29+
}
30+
2331
async getState() {
2432
const savedOptions = await this.getSavedOptions();
2533
return {

0 commit comments

Comments
 (0)