📈 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
Bug fixes
Blaumaus942b77c13f4b
diff --git a/src/project/project.controller.ts b/src/project/project.controller.tsindex f6d1a32c4..f49ca69d9 100644--- a/src/project/project.controller.ts+++ b/src/project/project.controller.ts@@ -65,8 +65,16 @@ export class ProjectController {await this.projectService.checkIfIDUnique(projectDTO.id)try {- const project = await this.projectService.create(projectDTO)- return project+ const project = new Project()+ Object.assign(project, projectDTO)++ const newProject = await this.projectService.create(project)+ const user = await this.userService.findOneWithRelations(userId, ['projects'])+ user.projects.push(project)++ await this.userService.create(user)++ return newProject} catch(e) {if (e.code === 'ER_DUP_ENTRY'){if (e.sqlMessage.includes(projectDTO.id)){@@ -92,21 +100,10 @@ export class ProjectController {throw new NotFoundException()}- await this.projectService.allowedToManage(project.id, userId)- await this.projectService.checkIfIDUnique(projectDTO.id)+ await this.projectService.allowedToManage(project, userId)+ await this.projectService.update(id, projectDTO)- try {- await this.projectService.update(id, projectDTO)- return this.projectService.findOne(id)- } catch(e) {- if (e.code === 'ER_DUP_ENTRY'){- if (e.sqlMessage.includes(projectDTO.id)) {- throw new BadRequestException('Project with selected ID already exists')- }- }-- return new BadRequestException(e)- }+ return this.projectService.findOne(id)}@Delete('/:id')@@ -121,7 +118,7 @@ export class ProjectController {if (!project) {throw new NotFoundException(`Project with ID ${id} does not exist`)}- await this.projectService.allowedToManage(project.id, userId)+ await this.projectService.allowedToManage(project, userId)try {await this.projectService.delete(id)diff --git a/src/project/project.service.ts b/src/project/project.service.tsindex fb02ed6f3..6cc3a091b 100644--- a/src/project/project.service.ts+++ b/src/project/project.service.ts@@ -36,7 +36,7 @@ export class ProjectService {return this.projectsRepository.count()}- async create(project: ProjectDTO): Promise<Project> {+ async create(project: ProjectDTO | Project): Promise<Project> {return this.projectsRepository.save(project)}@@ -49,7 +49,7 @@ export class ProjectService {}findOneWithRelations(id: string): Promise<Project | null> {- return this.projectsRepository.findOne(id, { relations: ['user'] })+ return this.projectsRepository.findOne(id, { relations: ['admin'] })}findOne(id: string): Promise<Project | null> {@@ -64,11 +64,9 @@ export class ProjectService {return userId === project.admin.id}- async allowedToManage(projectId: string, userId: string): Promise<void> {+ async allowedToManage(project: Project, userId: string): Promise<void> {const user = await this.userService.findOne(userId)- const project = await this.findOne(projectId)- // if (user.projects.some(({ id }) => project.id === id)) {if (this.ifAllowedToManage(user.id, project)) {return} else {diff --git a/src/user/user.service.ts b/src/user/user.service.tsindex 71bb220e6..e4c288285 100644--- a/src/user/user.service.ts+++ b/src/user/user.service.ts@@ -46,6 +46,10 @@ export class UserService {return this.findOneWhere({ id })}+ findOneWithRelations(id: string, relations: string[]): Promise<User> {+ return this.usersRepository.findOne(id, { relations })+ }+findWhere(where: Record<string, unknown>): Promise<User[]> {return this.usersRepository.find({ where })}