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!

Added confirm transfer project route

Yevhenii Kulisidi7a01f7f21f3b
diff --git a/src/project/dto/confirm-transfer-project.dto.ts b/src/project/dto/confirm-transfer-project.dto.ts
new file mode 100644
index 000000000..fcdfea92f
--- /dev/null
+++ b/src/project/dto/confirm-transfer-project.dto.ts
@@ -0,0 +1,11 @@
+import { IsUUID, Matches } from 'class-validator'
+
+export class ConfirmTransferProjectParamsDto {
+ @Matches(/^(?!.*--)[a-zA-Z0-9-]{12}$/)
+ readonly projectId: string
+}
+
+export class ConfirmTransferProjectQueriesDto {
+ @IsUUID('4')
+ readonly token: string
+}
diff --git a/src/project/dto/index.ts b/src/project/dto/index.ts
index 29558f3cc..42a57b00e 100644
--- a/src/project/dto/index.ts
+++ b/src/project/dto/index.ts
@@ -4,3 +4,4 @@ export * from './get-subscribers.dto'
export * from './update-subscriber.dto'
export * from './remove-subscriber.dto'
export * from './transfer-project.dto'
+export * from './confirm-transfer-project.dto'
diff --git a/src/project/project.controller.ts b/src/project/project.controller.ts
index e6b3ff9b2..500e276a8 100644
--- a/src/project/project.controller.ts
+++ b/src/project/project.controller.ts
@@ -32,6 +32,7 @@ import * as dayjs from 'dayjs'
import { JwtAccessTokenGuard } from 'src/auth/guards'
import { Auth, Public } from 'src/auth/decorators'
+import { isValidDate } from 'src/analytics/analytics.service'
import {
ProjectService,
processProjectUser,
@@ -53,7 +54,6 @@ import { UserService } from '../user/user.service'
import { ProjectDTO } from './dto/project.dto'
import { ShareDTO } from './dto/share.dto'
import { ShareUpdateDTO } from './dto/share-update.dto'
-import { isValidDate } from 'src/analytics/analytics.service'
import { AppLoggerService } from '../logger/logger.service'
import {
isValidPID,
@@ -83,6 +83,8 @@ import {
RemoveSubscriberParamsDto,
TransferProjectParamsDto,
TransferProjectBodyDto,
+ ConfirmTransferProjectParamsDto,
+ ConfirmTransferProjectQueriesDto,
} from './dto'
const PROJECTS_MAXIMUM = ACCOUNT_PLANS[PlanCode.free].maxProjects
@@ -1302,4 +1304,34 @@ export class ProjectController {
headers.origin,
)
}
+
+ @Get(':projectId/transfer')
+ async confirmTransferProject(
+ @Param() params: ConfirmTransferProjectParamsDto,
+ @Query() queries: ConfirmTransferProjectQueriesDto,
+ ) {
+ const project = await this.projectService.getProjectById(params.projectId)
+
+ if (!project) {
+ throw new NotFoundException('Project not found.')
+ }
+
+ const actionToken = await this.actionTokensService.getActionToken(
+ queries.token,
+ )
+
+ if (
+ !actionToken ||
+ actionToken.action !== ActionTokenType.TRANSFER_PROJECT ||
+ actionToken.newValue !== params.projectId
+ ) {
+ throw new BadRequestException('Invalid token.')
+ }
+
+ await this.projectService.confirmTransferProject(
+ params.projectId,
+ actionToken.user.id,
+ actionToken.id,
+ )
+ }
}
diff --git a/src/project/project.service.ts b/src/project/project.service.ts
index 152fd2005..dccfe9092 100644
--- a/src/project/project.service.ts
+++ b/src/project/project.service.ts
@@ -653,4 +653,16 @@ export class ProjectService {
name,
})
}
+
+ async confirmTransferProject(
+ projectId: string,
+ userId: string,
+ token: string,
+ ) {
+ await this.projectsRepository.update(
+ { id: projectId },
+ { admin: { id: userId } },
+ )
+ await this.actionTokens.deleteActionToken(token)
+ }
}