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!

fixed

Blue Mouseb186a1e7c351
diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts
index 2d65a41cb..e724d7c8e 100644
--- a/src/auth/auth.controller.ts
+++ b/src/auth/auth.controller.ts
@@ -52,7 +52,7 @@ export class AuthController {
}
} else {
user = this.authService.processUser(
- await this.userService.findOneWhere({ id: user_id })
+ await this.userService.findOneWhere({ id: user_id }, ['sharedProjects'])
)
}
diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts
index 1919b4e0f..65832d45d 100644
--- a/src/auth/auth.service.ts
+++ b/src/auth/auth.service.ts
@@ -88,7 +88,7 @@ export class AuthService {
}
async validateUser(email: string, pass: string): Promise<User> {
- const user = await this.userService.findOneWhere({ email })
+ const user = await this.userService.findOneWhere({ email }, ['sharedProjects'])
if (user && await this.checkPassword(pass, user.password)) {
return user
diff --git a/src/project/entity/project.entity.ts b/src/project/entity/project.entity.ts
index 69122d114..92fa3917c 100644
--- a/src/project/entity/project.entity.ts
+++ b/src/project/entity/project.entity.ts
@@ -1,4 +1,4 @@
-import { Entity, Column, PrimaryColumn, ManyToOne } from 'typeorm'
+import { Entity, Column, PrimaryColumn, ManyToOne, OneToMany } from 'typeorm'
import { ApiProperty } from '@nestjs/swagger'
import { User } from '../../user/entities/user.entity'
@@ -39,8 +39,8 @@ export class Project {
admin: User
@ApiProperty({ type: () => ProjectShare })
- @ManyToOne(() => ProjectShare, share => share.project)
- share: ProjectShare
+ @OneToMany(() => ProjectShare, share => share.project)
+ share: ProjectShare[]
@Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
created: Date
diff --git a/src/project/project.controller.ts b/src/project/project.controller.ts
index d942386cb..25808c606 100644
--- a/src/project/project.controller.ts
+++ b/src/project/project.controller.ts
@@ -485,7 +485,7 @@ export class ProjectController {
@Param('pid') pid: string,
@Body() shareDTO: ShareDTO,
@CurrentUserId() uid: string,
- ): Promise<any> {
+ ): Promise<Project> {
this.logger.log({ uid, pid, shareDTO }, 'POST /project/:pid/share')
if (!isValidPID(pid)) {
@@ -517,7 +517,7 @@ export class ProjectController {
const invitee = await this.userService.findOneWhere({
email: shareDTO.email,
- })
+ }, ['sharedProjects'])
if (!invitee) {
throw new NotFoundException(`User with email ${shareDTO.email} is not registered on Swetrix`)
@@ -534,9 +534,17 @@ export class ProjectController {
await this.projectService.createShare(share)
- const updatedProject = await this.projectService.findOne(pid, { relations: ['share'] })
+ // Saving share into project
+ project.share.push(share)
+ await this.projectService.create(project)
+
+ // Saving share into invitees shared projects
+ invitee.sharedProjects.push(share)
+ await this.userService.create(invitee)
- return updatedProject
+ return await this.projectService.findOne(pid, {
+ relations: ['share'],
+ })
} catch (e) {
console.error(`[ERROR] Could not share project (pid: ${project.id}, invitee ID: ${invitee.id}): ${e}`)
throw new BadRequestException(e)