Skip to content

📈 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!

- Add isArchived filed to the project table - Create endpoint to archive the project - Add service function to update the project

Yehor Dremliuha6158b3782646
diff --git a/apps/production/src/blog/blog.service.ts b/apps/production/src/blog/blog.service.ts
index 112c3ae3a..333309853 100644
--- a/apps/production/src/blog/blog.service.ts
+++ b/apps/production/src/blog/blog.service.ts
@@ -213,7 +213,10 @@ export class BlogService {
// set to true for infinite depth directory look-up
// eslint-disable-next-line
- const _files = await this.getSitemapFileNames(directory, infiniteRecursive)
+ const _files = await this.getSitemapFileNames(
+ directory,
+ infiniteRecursive,
+ )
filesInDirectories = [
...filesInDirectories,
..._map(_files, file => [directory, _replace(file, /\.md$/, '')]),
diff --git a/apps/production/src/project/entity/project.entity.ts b/apps/production/src/project/entity/project.entity.ts
index 17803f6b3..8bc49d6a3 100644
--- a/apps/production/src/project/entity/project.entity.ts
+++ b/apps/production/src/project/entity/project.entity.ts
@@ -110,4 +110,7 @@ export class Project {
@Column('boolean', { default: false })
isPasswordProtected: boolean
+
+ @Column('boolean', { default: false })
+ isArchived: boolean
}
diff --git a/apps/production/src/project/project.controller.ts b/apps/production/src/project/project.controller.ts
index d5e47d112..a4fed31f4 100644
--- a/apps/production/src/project/project.controller.ts
+++ b/apps/production/src/project/project.controller.ts
@@ -22,7 +22,14 @@ import {
UnauthorizedException,
} from '@nestjs/common'
import { Response } from 'express'
-import { ApiTags, ApiQuery, ApiResponse, ApiBearerAuth } from '@nestjs/swagger'
+import {
+ ApiTags,
+ ApiQuery,
+ ApiResponse,
+ ApiBearerAuth,
+ ApiOkResponse,
+ ApiOperation,
+} from '@nestjs/swagger'
import { ILike } from 'typeorm'
import * as _isEmpty from 'lodash/isEmpty'
import * as _map from 'lodash/map'
@@ -91,6 +98,7 @@ import {
FunnelCreateDTO,
FunnelUpdateDTO,
} from './dto'
+import { ProjectIdDto } from './dto/project-id.dto'
const PROJECTS_MAXIMUM = 50
@@ -1864,4 +1872,44 @@ export class ProjectController {
isErrorDataExists,
}
}
+
+ @ApiOperation({ summary: 'Archive project' })
+ @ApiOkResponse({ type: Project })
+ @ApiBearerAuth()
+ @Post(':projectId/archive')
+ @HttpCode(HttpStatus.OK)
+ @Auth([], true, true)
+ async archiveProject(
+ @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.')
+ }
+
+ this.projectService.allowedToManage(project, userId, user.roles)
+
+ if (project.isArchived) {
+ throw new ConflictException('Project is already archived.')
+ }
+
+ await this.projectService.updateProject(params.projectId, {
+ isArchived: !project.isArchived,
+ })
+
+ return this.projectService.findOne(params.projectId)
+ }
}
diff --git a/apps/production/src/project/project.service.ts b/apps/production/src/project/project.service.ts
index cab9588ef..01764e807 100644
--- a/apps/production/src/project/project.service.ts
+++ b/apps/production/src/project/project.service.ts
@@ -1275,4 +1275,8 @@ export class ProjectService {
return count
}
+
+ async updateProject(id: string, data: Partial<Project>) {
+ await this.projectsRepository.update({ id }, data)
+ }
}