📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
- Add endpoint to unarchive the project - Add migration to the DB
Yehor Dremliuhaaa66491fdc91
diff --git a/apps/production/src/project/dto/project-id.dto.ts b/apps/production/src/project/dto/project-id.dto.tsnew file mode 100644index 000000000..4c33ab2c7--- /dev/null+++ b/apps/production/src/project/dto/project-id.dto.ts@@ -0,0 +1,11 @@+import { ApiProperty } from '@nestjs/swagger'+import { Matches, IsNotEmpty } from 'class-validator'++const PROJECT_ID_REGEX = /^(?!.*--)[a-zA-Z0-9-]{12}$/++export class ProjectIdDto {+ @ApiProperty()+ @Matches(PROJECT_ID_REGEX)+ @IsNotEmpty()+ readonly projectId: string+}diff --git a/apps/production/src/project/project.controller.ts b/apps/production/src/project/project.controller.tsindex a4fed31f4..fa8181d30 100644--- a/apps/production/src/project/project.controller.ts+++ b/apps/production/src/project/project.controller.ts@@ -29,6 +29,7 @@ import {ApiBearerAuth,ApiOkResponse,ApiOperation,+ ApiNoContentResponse,} from '@nestjs/swagger'import { ILike } from 'typeorm'import * as _isEmpty from 'lodash/isEmpty'@@ -1912,4 +1913,44 @@ export class ProjectController {return this.projectService.findOne(params.projectId)}++ @ApiOperation({ summary: 'Unarchive project' })+ @ApiNoContentResponse()+ @ApiBearerAuth()+ @Delete(':projectId/archive')+ @HttpCode(HttpStatus.NO_CONTENT)+ @Auth([], true, true)+ async unarchiveProject(+ @Param() params: ProjectIdDto,+ @CurrentUserId() userId: string,+ ) {+ const project = await this.projectService.findOneWhere(+ { id: params.projectId },+ { relations: ['admin'] },+ )++ if (!project) {+ throw new NotFoundException('Project not found.')+ }++ const user = await this.userService.findOneWithRelations(userId, [+ 'projects',+ ])++ if (!user) {+ throw new NotFoundException('User not found.')+ }++ if (!project.isArchived) {+ throw new ConflictException('Project is unarchived.')+ }++ this.projectService.allowedToManage(project, userId, user.roles)++ await this.projectService.updateProject(params.projectId, {+ isArchived: !project.isArchived,+ })++ return await this.projectService.findOne(params.projectId)+ }}diff --git a/migrations/mysql/2024_06_02.sql b/migrations/mysql/2024_06_02.sqlnew file mode 100644index 000000000..27b0d4223--- /dev/null+++ b/migrations/mysql/2024_06_02.sql@@ -0,0 +1 @@+alter table project add column isArchived tinyint NOT NULL DEFAULT '0' after isPasswordProtected;