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!

Restructure the repo according to the task

Yehor Dremliuha4b88787a02f3
diff --git a/apps/production/src/app.module.ts b/apps/production/src/app.module.ts
index d58d807b6..73e905b5e 100644
--- a/apps/production/src/app.module.ts
+++ b/apps/production/src/app.module.ts
@@ -25,7 +25,6 @@ import { OgImageModule } from './og-image/og-image.module'
import { IntegrationsModule } from './integrations/integrations.module'
import { HealthModule } from './health/health.module'
import { AppController } from './app.controller'
-import { ECommerceModule } from './e-commerce/e-commerce.module';
const modules = [
ConfigModule.forRoot({
@@ -85,7 +84,6 @@ const modules = [
...modules,
...(process.env.ENABLE_INTEGRATIONS === 'true' ? [IntegrationsModule] : []),
...(process.env.IS_MASTER_NODE === 'true' ? [TaskManagerModule] : []),
- ECommerceModule,
],
controllers: [AppController],
})
diff --git a/apps/production/src/e-commerce/e-commerce.module.ts b/apps/production/src/e-commerce/e-commerce.module.ts
deleted file mode 100644
index c5832d253..000000000
--- a/apps/production/src/e-commerce/e-commerce.module.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-import { Module } from '@nestjs/common';
-import { ViewsModule } from './views/views.module';
-
-@Module({
- imports: [ViewsModule]
-})
-export class ECommerceModule {}
diff --git a/apps/production/src/e-commerce/views/entities/view.entity.ts b/apps/production/src/e-commerce/views/entities/view.entity.ts
deleted file mode 100644
index 4582dfc74..000000000
--- a/apps/production/src/e-commerce/views/entities/view.entity.ts
+++ /dev/null
@@ -1,83 +0,0 @@
-import { ApiProperty } from "@nestjs/swagger";
-import { Project } from "../../../project/entity/project.entity";
-import { Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
-
-@Entity('views')
-export class ViewEntity {
- @ApiProperty()
- @PrimaryGeneratedColumn('uuid')
- id: string
-
- @ApiProperty()
- @Column()
- projectId: string
-
- @ApiProperty()
- @Column({ type: 'bigint', nullable: true })
- psid: string | null
-
- @ApiProperty()
- @Column('varchar')
- pg: string | null
-
- @ApiProperty()
- @Column('varchar')
- ev: string
-
- @ApiProperty()
- @Column('varchar', { nullable: true })
- dv: string | null
-
- @ApiProperty()
- @Column('varchar', { nullable: true })
- br: string | null
-
- @ApiProperty()
- @Column('varchar', { nullable: true })
- os: string | null
-
- @ApiProperty()
- @Column('varchar', { nullable: true })
- lc: string | null
-
- @ApiProperty()
- @Column('varchar', { nullable: true })
- ref: string | null
-
- @ApiProperty()
- @Column('varchar', { nullable: true })
- so: string | null
-
- @ApiProperty()
- @Column('varchar', { nullable: true })
- me: string | null
-
- @ApiProperty()
- @Column('varchar', { nullable: true })
- ca: string | null
-
- @ApiProperty()
- @Column('varchar', { length: 2, nullable: true })
- cc: string
-
- @ApiProperty()
- @Column('varchar', { nullable: true })
- rg: string | null
-
- @ApiProperty()
- @Column('varchar', { nullable: true })
- ct: string | null
-
- @ApiProperty()
- @CreateDateColumn()
- createdAt: Date
-
- @ApiProperty()
- @UpdateDateColumn()
- updatedAt: Date
-
- @ManyToOne(() => Project, project => project.views)
- project: Project
-
-}
-
diff --git a/apps/production/src/e-commerce/views/repositories/views.repository.ts b/apps/production/src/e-commerce/views/repositories/views.repository.ts
deleted file mode 100644
index 8b24e633a..000000000
--- a/apps/production/src/e-commerce/views/repositories/views.repository.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-import { Injectable } from "@nestjs/common";
-import { InjectRepository } from "@nestjs/typeorm";
-import { ViewEntity } from "../entities/view.entity";
-import { Repository } from "typeorm";
-
-@Injectable()
-export class ViewsRepository {
- constructor(
- @InjectRepository(ViewEntity)
- private viewsRepository: Repository<ViewEntity>,
- ) {
-
- }
- async findViews(projectId:string){
- return await this.viewsRepository.find({
- projectId
- })
- }
-
-}
\ No newline at end of file
diff --git a/apps/production/src/e-commerce/views/views.controller.ts b/apps/production/src/e-commerce/views/views.controller.ts
deleted file mode 100644
index ad8caaafe..000000000
--- a/apps/production/src/e-commerce/views/views.controller.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import { Controller, Get, NotFoundException, Query } from '@nestjs/common';
-import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
-import { ViewsRepository } from './repositories/views.repository';
-import { ViewEntity } from './entities/view.entity';
-import { ProjectService } from '../../project/project.service';
-
-@ApiTags("E-commerce/views")
-@Controller('e-commerce/views')
-export class ViewsController {
- constructor(
- private readonly viewsRepository: ViewsRepository,
- private readonly projectService: ProjectService
- ) {}
-
- @ApiOperation({ summary: 'Get project views' })
- @ApiOkResponse({ type: ViewEntity })
- @Get()
- async getViews(@Query('projectId') projectId: string) {
- const project = await this.projectService.findProject(projectId)
-
- if (!project) {
- throw new NotFoundException('View not found.')
- }
-
- return await this.viewsRepository.findViews(projectId)
- }
-}
diff --git a/apps/production/src/e-commerce/views/views.module.ts b/apps/production/src/e-commerce/views/views.module.ts
deleted file mode 100644
index af9883bce..000000000
--- a/apps/production/src/e-commerce/views/views.module.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import { Module } from '@nestjs/common';
-import { ViewsController } from './views.controller';
-import { ViewEntity } from './entities/view.entity';
-import { TypeOrmModule } from '@nestjs/typeorm';
-import { ViewsRepository } from './repositories/views.repository';
-import { ProjectModule } from '../../project/project.module';
-
-
-@Module({
- imports: [TypeOrmModule.forFeature([ViewEntity]), ProjectModule],
- controllers: [ViewsController],
- providers: [ViewsRepository]
-
-})
-export class ViewsModule {
-
-
-}
\ No newline at end of file
diff --git a/apps/production/src/project/entity/project-view.entity.ts b/apps/production/src/project/entity/project-view.entity.ts
new file mode 100644
index 000000000..e61d628cc
--- /dev/null
+++ b/apps/production/src/project/entity/project-view.entity.ts
@@ -0,0 +1,89 @@
+import {
+ Column,
+ CreateDateColumn,
+ Entity,
+ ManyToOne,
+ PrimaryGeneratedColumn,
+ UpdateDateColumn,
+} from 'typeorm'
+
+import { ApiProperty } from '@nestjs/swagger'
+import { Project } from './project.entity'
+
+@Entity('project_views')
+export class ProjectViewEntity {
+ @ApiProperty()
+ @PrimaryGeneratedColumn('uuid')
+ id: string
+
+ @ApiProperty()
+ @Column()
+ projectId: string
+
+ @ApiProperty()
+ @Column({ type: 'bigint', nullable: true })
+ psid: string | null
+
+ @ApiProperty()
+ @Column('varchar')
+ pg: string | null
+
+ @ApiProperty()
+ @Column('varchar')
+ ev: string
+
+ @ApiProperty()
+ @Column('varchar', { nullable: true })
+ dv: string | null
+
+ @ApiProperty()
+ @Column('varchar', { nullable: true })
+ br: string | null
+
+ @ApiProperty()
+ @Column('varchar', { nullable: true })
+ os: string | null
+
+ @ApiProperty()
+ @Column('varchar', { nullable: true })
+ lc: string | null
+
+ @ApiProperty()
+ @Column('varchar', { nullable: true })
+ ref: string | null
+
+ @ApiProperty()
+ @Column('varchar', { nullable: true })
+ so: string | null
+
+ @ApiProperty()
+ @Column('varchar', { nullable: true })
+ me: string | null
+
+ @ApiProperty()
+ @Column('varchar', { nullable: true })
+ ca: string | null
+
+ @ApiProperty()
+ @Column('varchar', { length: 2, nullable: true })
+ cc: string
+
+ @ApiProperty()
+ @Column('varchar', { nullable: true })
+ rg: string | null
+
+ @ApiProperty()
+ @Column('varchar', { nullable: true })
+ ct: string | null
+
+ @ApiProperty()
+ @CreateDateColumn()
+ createdAt: Date
+
+ @ApiProperty()
+ @UpdateDateColumn()
+ updatedAt: Date
+
+ @ManyToOne(() => Project, project => project.views)
+ project: Project
+}
diff --git a/apps/production/src/project/entity/project.entity.ts b/apps/production/src/project/entity/project.entity.ts
index ba53d6609..240be81c4 100644
--- a/apps/production/src/project/entity/project.entity.ts
+++ b/apps/production/src/project/entity/project.entity.ts
@@ -15,7 +15,7 @@ import { ExtensionToProject } from '../../marketplace/extensions/entities/extens
import { ProjectSubscriber } from './project-subscriber.entity'
import { Funnel } from './funnel.entity'
import { CAPTCHA_SECRET_KEY_LENGTH } from '../../common/constants'
-import { ViewEntity } from '../../e-commerce/views/entities/view.entity'
+import { ProjectViewEntity } from './project-view.entity'
// In case of modifying some properties here add them to the GDPR data export email template
@Entity()
@@ -114,6 +114,7 @@ export class Project {
@Column('boolean', { default: false })
isArchived: boolean
- @OneToMany(() => ViewEntity, view => view.id)
- views: ViewEntity[]
+
+ @OneToMany(() => ProjectViewEntity, projectView => projectView.id)
+ views: ProjectViewEntity[]
}
diff --git a/apps/production/src/project/project.controller.ts b/apps/production/src/project/project.controller.ts
index 0aeeb34d0..bbe4c2f29 100644
--- a/apps/production/src/project/project.controller.ts
+++ b/apps/production/src/project/project.controller.ts
@@ -24,7 +24,14 @@ import {
DefaultValuePipe,
} from '@nestjs/common'
import { Response } from 'express'
-import { ApiTags, ApiQuery, ApiResponse, ApiBearerAuth } from '@nestjs/swagger'
+import {
+ ApiTags,
+ ApiQuery,
+ ApiResponse,
+ ApiBearerAuth,
+ ApiOperation,
+ ApiOkResponse,
+} from '@nestjs/swagger'
import { ILike } from 'typeorm'
import * as _isEmpty from 'lodash/isEmpty'
import * as _map from 'lodash/map'
@@ -93,6 +100,8 @@ import {
FunnelCreateDTO,
FunnelUpdateDTO,
} from './dto'
+import { ProjectsViewsRepository } from './repositories/projects-views.repository'
+import { ProjectViewEntity } from './entity/project-view.entity'
const PROJECTS_MAXIMUM = 50
@@ -113,6 +122,7 @@ export class ProjectController {
private readonly logger: AppLoggerService,
private readonly actionTokensService: ActionTokensService,
private readonly mailerService: MailerService,
+ private readonly projectsViewsRepository: ProjectsViewsRepository,
) {}
@ApiBearerAuth()
@@ -1883,4 +1893,17 @@ export class ProjectController {
isErrorDataExists,
}
}
+
+ @ApiOperation({ summary: 'Get project views' })
+ @ApiOkResponse({ type: ProjectViewEntity })
+ @Get(':projectId/views')
+ async getProjectViews(@Param('projectId') projectId: string) {
+ const project = await this.projectService.findProject(projectId)
+
+ if (!project) {
+ throw new NotFoundException('Project not found.')
+ }
+
+ return this.projectsViewsRepository.findViews(projectId)
+ }
}
diff --git a/apps/production/src/project/project.module.ts b/apps/production/src/project/project.module.ts
index 06516b762..c459e03ff 100644
--- a/apps/production/src/project/project.module.ts
+++ b/apps/production/src/project/project.module.ts
@@ -8,6 +8,8 @@ import { ActionTokensModule } from '../action-tokens/action-tokens.module'
import { MailerModule } from '../mailer/mailer.module'
import { AppLoggerModule } from '../logger/logger.module'
import { Project, ProjectSubscriber, Funnel, ProjectShare } from './entity'
+import { ProjectsViewsRepository } from './repositories/projects-views.repository'
+import { ProjectViewEntity } from './entity/project-view.entity'
@Module({
imports: [
@@ -16,13 +18,14 @@ import { Project, ProjectSubscriber, Funnel, ProjectShare } from './entity'
ProjectShare,
ProjectSubscriber,
Funnel,
+ ProjectViewEntity,
]),
forwardRef(() => UserModule),
AppLoggerModule,
ActionTokensModule,
MailerModule,
],
- providers: [ProjectService],
+ providers: [ProjectService, ProjectsViewsRepository],
exports: [ProjectService],
controllers: [ProjectController],
})
diff --git a/apps/production/src/project/repositories/projects-views.repository.ts b/apps/production/src/project/repositories/projects-views.repository.ts
new file mode 100644
index 000000000..6be7b2e09
--- /dev/null
+++ b/apps/production/src/project/repositories/projects-views.repository.ts
@@ -0,0 +1,16 @@
+import { Injectable } from '@nestjs/common'
+import { InjectRepository } from '@nestjs/typeorm'
+import { Repository } from 'typeorm'
+import { ProjectViewEntity } from '../entity/project-view.entity'
+
+@Injectable()
+export class ProjectsViewsRepository {
+ constructor(
+ @InjectRepository(ProjectViewEntity)
+ private viewsRepository: Repository<ProjectViewEntity>,
+ ) {}
+
+ async findViews(projectId: string) {
+ return this.viewsRepository.find({ projectId })
+ }
+}