📈 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
Remove uptime groups
Blue Mouse391a9e55febe
diff --git a/apps/production/src/analytics/analytics.controller.ts b/apps/production/src/analytics/analytics.controller.tsindex e6ce706bf..487cef0b4 100644--- a/apps/production/src/analytics/analytics.controller.ts+++ b/apps/production/src/analytics/analytics.controller.ts@@ -1616,7 +1616,6 @@ export class AnalyticsController {): Promise<any> {const {pid,- monitorGroupId,monitorId,monitorIds,period,@@ -1638,11 +1637,7 @@ export class AnalyticsController {const idsArray = getMonitorIdsArray(monitorIds, monitorId)const validationPromises = _map(idsArray, async currentId => {- await this.analyticsService.checkUptimeAccess(- pid,- monitorGroupId,- currentId,- )+ await this.analyticsService.checkUptimeAccess(pid, currentId)})await Promise.all(validationPromises)@@ -1668,7 +1663,6 @@ export class AnalyticsController {): Promise<any & { chart: any }> {const {pid,- monitorGroupId,monitorId,period,timeBucket,@@ -1677,7 +1671,6 @@ export class AnalyticsController {timezone = DEFAULT_TIMEZONE,} = parameters- // TODO: CHECK THAT MONITOR GROUP BELONGS TO THE PROVIDED PIDthis.analyticsService.validatePID(pid)if (!_isEmpty(period)) {@@ -1692,11 +1685,7 @@ export class AnalyticsController {await this.analyticsService.checkBillingAccess(pid)- await this.analyticsService.checkUptimeAccess(- pid,- monitorGroupId,- monitorId,- )+ await this.analyticsService.checkUptimeAccess(pid, monitorId)let newTimebucket = timeBucketlet allowedTumebucketForPeriodAlldiff --git a/apps/production/src/analytics/analytics.service.ts b/apps/production/src/analytics/analytics.service.tsindex a663cd25a..d18809c95 100644--- a/apps/production/src/analytics/analytics.service.ts+++ b/apps/production/src/analytics/analytics.service.ts@@ -395,18 +395,10 @@ export class AnalyticsService {}}- async checkUptimeAccess(- pid: string,- monitorGroupId: string,- monitorId: number,- ) {+ async checkUptimeAccess(pid: string, monitorId: number) {const monitor = await this.projectService.findMonitorById(monitorId as unknown as string,- monitorGroupId,pid,- {- relations: ['group'],- },)if (!monitor) {diff --git a/apps/production/src/analytics/dto/get-monitor-data.dto.ts b/apps/production/src/analytics/dto/get-monitor-data.dto.tsindex d84ee0c69..3eb2a8b43 100644--- a/apps/production/src/analytics/dto/get-monitor-data.dto.ts+++ b/apps/production/src/analytics/dto/get-monitor-data.dto.ts@@ -12,10 +12,6 @@ export class GetMonitorDataDto {@IsNotEmpty()monitorId: number- @ApiProperty()- @IsNotEmpty()- monitorGroupId: string-@ApiProperty()period: stringdiff --git a/apps/production/src/analytics/dto/get-uptime-birdseye.dto.ts b/apps/production/src/analytics/dto/get-uptime-birdseye.dto.tsindex e76ae3fb3..3e421ad59 100644--- a/apps/production/src/analytics/dto/get-uptime-birdseye.dto.ts+++ b/apps/production/src/analytics/dto/get-uptime-birdseye.dto.ts@@ -16,10 +16,6 @@ export class GetUptimeBirdseyeDto {@IsArray()monitorIds?: number[]- @ApiProperty()- @IsNotEmpty()- monitorGroupId: string-@ApiProperty()period: stringdiff --git a/apps/production/src/app.module.ts b/apps/production/src/app.module.tsindex 1de585559..ef9da1b3e 100644--- a/apps/production/src/app.module.ts+++ b/apps/production/src/app.module.ts@@ -58,7 +58,7 @@ const modules = [username: process.env.MYSQL_USER,password: process.env.MYSQL_ROOT_PASSWORD,database: process.env.MYSQL_DATABASE,- synchronize: false, // process.env.NODE_ENV !== 'production',+ synchronize: true, // process.env.NODE_ENV !== 'production',entities: [`${__dirname}/**/*.entity{.ts,.js}`],}),BullModule.forRoot({diff --git a/apps/production/src/common/templates/en/uptime-monitoring-failure.html b/apps/production/src/common/templates/en/uptime-monitoring-failure.htmlindex d5882fcb1..75156e4bf 100644--- a/apps/production/src/common/templates/en/uptime-monitoring-failure.html+++ b/apps/production/src/common/templates/en/uptime-monitoring-failure.html@@ -1,3 +1,3 @@Hello,-We have just detected that the monitor {{monitorName}} (monitor group - {{groupName}}, project - {{projectName}}) is down.+We have just detected that the monitor {{monitorName}} of the {{projectName}} project is down.diff --git a/apps/production/src/project/consumers/monitor.consumer.ts b/apps/production/src/project/consumers/monitor.consumer.tsindex e29632807..101f1b3cb 100644--- a/apps/production/src/project/consumers/monitor.consumer.ts+++ b/apps/production/src/project/consumers/monitor.consumer.ts@@ -35,12 +35,11 @@ export class MonitorConsumer {if (!monitor.acceptedStatusCodes.includes(res.statusCode)) {try {await this.mailerService.sendEmail(- monitor.group.project.admin.email,+ monitor.project.admin.email,LetterTemplate.UptimeMonitoringFailure,{- projectName: monitor.group.project.name,+ projectName: monitor.project.name,monitorName: monitor.name,- groupName: monitor.group.name,},)} catch (reason) {diff --git a/apps/production/src/project/dto/create-monitor-group.dto.ts b/apps/production/src/project/dto/create-monitor-group.dto.tsdeleted file mode 100644index a0d1a0773..000000000--- a/apps/production/src/project/dto/create-monitor-group.dto.ts+++ /dev/null@@ -1,6 +0,0 @@-import { ApiProperty } from '@nestjs/swagger'--export class CreateMonitorGroupDto {- @ApiProperty()- name: string-}diff --git a/apps/production/src/project/dto/monitor-group-id.dto.ts b/apps/production/src/project/dto/monitor-group-id.dto.tsdeleted file mode 100644index 1e09a04f3..000000000--- a/apps/production/src/project/dto/monitor-group-id.dto.ts+++ /dev/null@@ -1,9 +0,0 @@-import { ApiProperty } from '@nestjs/swagger'-import { IsNotEmpty, IsUUID } from 'class-validator'--export class MonitorGroupIdDto {- @ApiProperty()- @IsUUID()- @IsNotEmpty()- readonly monitorGroupId: string-}diff --git a/apps/production/src/project/dto/update-monitor-group.dto.ts b/apps/production/src/project/dto/update-monitor-group.dto.tsdeleted file mode 100644index a68983d8f..000000000--- a/apps/production/src/project/dto/update-monitor-group.dto.ts+++ /dev/null@@ -1,6 +0,0 @@-import { ApiProperty } from '@nestjs/swagger'--export class UpdateMonitorGroupDto {- @ApiProperty()- name: string-}diff --git a/apps/production/src/project/entity/monitor-group.entity.ts b/apps/production/src/project/entity/monitor-group.entity.tsdeleted file mode 100644index ca3a3fce3..000000000--- a/apps/production/src/project/entity/monitor-group.entity.ts+++ /dev/null@@ -1,26 +0,0 @@-import {- Entity,- Column,- PrimaryGeneratedColumn,- ManyToOne,- OneToMany,-} from 'typeorm'-import { Project } from './project.entity'-import { MonitorEntity } from './monitor.entity'--@Entity('monitor_groups')-export class MonitorGroupEntity {- @PrimaryGeneratedColumn('uuid')- id: string-- @Column()- name: string-- @ManyToOne(() => Project, project => project.monitorsGroups, {- onDelete: 'CASCADE',- })- project: Project-- @OneToMany(() => MonitorEntity, monitor => monitor.id)- monitors: MonitorEntity[]-}diff --git a/apps/production/src/project/entity/monitor.entity.ts b/apps/production/src/project/entity/monitor.entity.tsindex 1168132cb..8d636a543 100644--- a/apps/production/src/project/entity/monitor.entity.ts+++ b/apps/production/src/project/entity/monitor.entity.ts@@ -7,7 +7,7 @@ import {UpdateDateColumn,} from 'typeorm'import { ApiProperty } from '@nestjs/swagger'-import { MonitorGroupEntity } from './monitor-group.entity'+import { Project } from './project.entity'@Entity('monitor')export class MonitorEntity {@@ -51,10 +51,10 @@ export class MonitorEntity {@Column({ type: 'text', nullable: true })description: string | null- @ManyToOne(() => MonitorGroupEntity, group => group.monitors, {+ @ManyToOne(() => Project, project => project.monitors, {onDelete: 'CASCADE',})- group: MonitorGroupEntity+ project: Project@ApiProperty()@CreateDateColumn()diff --git a/apps/production/src/project/entity/project.entity.ts b/apps/production/src/project/entity/project.entity.tsindex 7ce11de8f..59581af2f 100644--- a/apps/production/src/project/entity/project.entity.ts+++ b/apps/production/src/project/entity/project.entity.ts@@ -16,7 +16,7 @@ import { ProjectSubscriber } from './project-subscriber.entity'import { Funnel } from './funnel.entity'import { CAPTCHA_SECRET_KEY_LENGTH } from '../../common/constants'import { ProjectViewEntity } from './project-view.entity'-import { MonitorGroupEntity } from './monitor-group.entity'+import { MonitorEntity } from './monitor.entity'// In case of modifying some properties here add them to the GDPR data export email template@Entity()@@ -119,6 +119,6 @@ export class Project {@OneToMany(() => ProjectViewEntity, projectView => projectView.id)views: ProjectViewEntity[]- @OneToMany(() => MonitorGroupEntity, monitorGroup => monitorGroup.id)- monitorsGroups: MonitorGroupEntity[]+ @OneToMany(() => MonitorEntity, monitor => monitor.id)+ monitors: MonitorEntity[]}diff --git a/apps/production/src/project/project.controller.ts b/apps/production/src/project/project.controller.tsindex 76adc5162..e338b1ea7 100644--- a/apps/production/src/project/project.controller.ts+++ b/apps/production/src/project/project.controller.ts@@ -33,7 +33,7 @@ import {ApiOkResponse,ApiNoContentResponse,} from '@nestjs/swagger'-import { FindConditions, ILike } from 'typeorm'+import { FindConditions, ILike, In } from 'typeorm'import * as _isEmpty from 'lodash/isEmpty'import * as _map from 'lodash/map'import * as _trim from 'lodash/trim'@@ -109,10 +109,6 @@ import { UpdateProjectViewDto } from './dto/update-project-view.dto'import { ProjectViewIdsDto } from './dto/project-view-ids.dto'import { CreateMonitorHttpRequestDTO } from './dto/create-monitor.dto'import { MonitorEntity } from './entity/monitor.entity'-import { MonitorGroupEntity } from './entity/monitor-group.entity'-import { CreateMonitorGroupDto } from './dto/create-monitor-group.dto'-import { UpdateMonitorGroupDto } from './dto/update-monitor-group.dto'-import { MonitorGroupIdDto } from './dto/monitor-group-id.dto'import { UpdateMonitorHttpRequestDTO } from './dto/update-monitor.dto'const PROJECTS_MAXIMUM = 50@@ -1896,6 +1892,46 @@ export class ProjectController {await this.projectService.deleteShare(shareId)}+ @ApiOperation({ summary: 'Get monitors for the project' })+ @ApiBearerAuth()+ @ApiOkResponse({ type: MonitorEntity })+ @Get('/monitors')+ @Auth([])+ public async getAllMonitors(+ @CurrentUserId() userId: string,+ @Query('take') take: number | undefined,+ @Query('skip') skip: number | undefined,+ ): Promise<Pagination<MonitorEntity>> {+ this.logger.log({ userId, take, skip }, 'GET /project/monitors')++ const projects = await this.projectService.findWhere({ admin: userId })++ if (_isEmpty(projects)) {+ return {+ results: [],+ total: 0,+ page_total: 0,+ }+ }++ const pids = _map(projects, project => project.id)++ const result = await this.projectService.paginateMonitors(+ {+ take,+ skip,+ },+ { project: In(pids) },+ )++ result.results = _map(result.results, monitor => ({+ ..._omit(monitor, ['project']),+ projectId: monitor.project.id,+ }))++ return result+ }+@ApiBearerAuth()@Get('/:id')@Auth([], true, true)@@ -2155,187 +2191,13 @@ export class ProjectController {return this.projectService.sendPredictAiRequest(params.projectId)}- @ApiOperation({ summary: 'Create monitor group' })- @ApiBearerAuth()- @ApiOkResponse({ type: MonitorGroupEntity })- @Post(':projectId/monitor-groups')- @Auth([], true, true)- public async createMonitorGroup(- @Param() { projectId }: ProjectIdDto,- @Body() body: CreateMonitorGroupDto,- @CurrentUserId() userId: string,- ): Promise<MonitorGroupEntity> {- const project = await this.projectService.findProject(projectId, [- 'admin',- 'share',- ])-- if (!project) {- throw new NotFoundException('Project not found.')- }-- const user = await this.userService.findUserV2(userId, ['roles'])-- if (!user) {- throw new NotFoundException('User not found.')- }-- this.projectService.allowedToManage(project, userId, user.roles)-- const monitorGroup =- await this.projectService.findMonitorGroupByProjectIdAndName(- projectId,- body.name,- )- if (monitorGroup) {- throw new ConflictException('Monitor group exists.')- }-- return this.projectService.createMonitorGroup(projectId, body)- }-- @ApiOperation({ summary: 'Get all monitor groups for a project' })- @ApiBearerAuth()- @ApiOkResponse({ type: [MonitorGroupEntity] })- @Get(':projectId/monitor-groups')- @Auth([], true, true)- async getMonitorGroups(- @Param() { projectId }: ProjectIdDto,- @CurrentUserId() userId: string,- ): Promise<MonitorGroupEntity[]> {- const project = await this.projectService.findProject(projectId, [- 'admin',- 'share',- ])-- if (!project) {- throw new NotFoundException('Project not found.')- }-- const user = await this.userService.findUserV2(userId, ['roles'])-- if (!user) {- throw new NotFoundException('User not found.')- }-- this.projectService.allowedToManage(project, userId, user.roles)-- const monitorGroup =- await this.projectService.getMonitorGroupsByProjectId(projectId)-- return monitorGroup- }-- @ApiOperation({ summary: 'Get monitor group by ID' })- @ApiBearerAuth()- @ApiOkResponse({ type: MonitorGroupEntity })- @Get(':projectId/monitor-groups/:monitorGroupId')- @Auth([], true, true)- async getMonitorGroup(- @Param() { projectId }: ProjectIdDto,- @Param() { monitorGroupId }: MonitorGroupIdDto,- @CurrentUserId() userId: string,- ): Promise<MonitorGroupEntity> {- const project = await this.projectService.findProject(projectId, [- 'admin',- 'share',- ])-- if (!project) {- throw new NotFoundException('Project not found.')- }-- const user = await this.userService.findUserV2(userId, ['roles'])-- if (!user) {- throw new NotFoundException('User not found.')- }-- this.projectService.allowedToManage(project, userId, user.roles)-- const monitorGroup = await this.projectService.findMonitorGroup(- projectId,- monitorGroupId,- )- if (!monitorGroup) {- throw new NotFoundException('Monitor group not found.')- }-- return monitorGroup- }-- @ApiOperation({ summary: 'Update monitor group' })- @ApiBearerAuth()- @ApiOkResponse({ type: MonitorGroupEntity })- @Put(':projectId/monitor-groups/:monitorGroupId')- @Auth([], true, true)- async updateMonitorGroup(- @Param() { projectId }: ProjectIdDto,- @Param() { monitorGroupId }: MonitorGroupIdDto,- @Body() updateMonitorGroupDto: UpdateMonitorGroupDto,- @CurrentUserId() userId: string,- ): Promise<MonitorGroupEntity> {- const project = await this.projectService.findProject(projectId, [- 'admin',- 'share',- ])-- if (!project) {- throw new NotFoundException('Project not found.')- }-- const user = await this.userService.findUserV2(userId, ['roles'])-- if (!user) {- throw new NotFoundException('User not found.')- }-- this.projectService.allowedToManage(project, userId, user.roles)-- return this.projectService.updateMonitorGroup(- projectId,- monitorGroupId,- updateMonitorGroupDto,- )- }-- @ApiOperation({ summary: 'Delete monitor group' })- @ApiBearerAuth()- @Delete(':projectId/monitor-groups/:monitorGroupId')- @Auth([], true, true)- async deleteMonitorGroup(- @Param() { projectId }: ProjectIdDto,- @Param() { monitorGroupId }: MonitorGroupIdDto,- @CurrentUserId() userId: string,- ): Promise<void> {- const project = await this.projectService.findProject(projectId, [- 'admin',- 'share',- ])-- if (!project) {- throw new NotFoundException('Project not found.')- }-- const user = await this.userService.findUserV2(userId, ['roles'])-- if (!user) {- throw new NotFoundException('User not found.')- }-- this.projectService.allowedToManage(project, userId, user.roles)-- return this.projectService.deleteMonitorGroup(projectId, monitorGroupId)- }-@ApiOperation({ summary: 'Create monitor for the project' })@ApiBearerAuth()@ApiOkResponse({ type: MonitorEntity })- @Post(':projectId/monitor-groups/:monitorGroupId/monitor')+ @Post(':projectId/monitor')@Auth([], true, true)public async createMonitor(@Param() { projectId }: ProjectIdDto,- @Param() { monitorGroupId }: MonitorGroupIdDto,@Body() body: CreateMonitorHttpRequestDTO,@CurrentUserId() userId: string,): Promise<MonitorEntity> {@@ -2356,19 +2218,7 @@ export class ProjectController {this.projectService.allowedToManage(project, userId, user.roles)- const monitorGroup = await this.projectService.findMonitorGroup(- monitorGroupId,- projectId,- )-- if (!monitorGroup) {- throw new NotFoundException('Monitor group not found.')- }-- const monitor = await this.projectService.createMonitorInGroup(- body,- monitorGroup.id,- )+ const monitor = await this.projectService.createMonitor(body, projectId)// Create a job in service for sending httpRequestawait this.projectService.sendHttpRequest(monitor.id, {@@ -2382,11 +2232,10 @@ export class ProjectController {@ApiOperation({ summary: 'Get monitor for the project' })@ApiBearerAuth()@ApiOkResponse({ type: MonitorEntity })- @Get(':projectId/monitor-groups/:monitorGroupId/monitor/:monitorId')+ @Get(':projectId/monitor/:monitorId')@Auth([], true, true)public async getMonitor(@Param() { projectId }: ProjectIdDto,- @Param() { monitorGroupId }: MonitorGroupIdDto,@Param('monitorId') monitorId: number,@CurrentUserId() userId: string,): Promise<MonitorEntity> {@@ -2407,15 +2256,6 @@ export class ProjectController {this.projectService.allowedToManage(project, userId, user.roles)- const monitorGroup = await this.projectService.findMonitorGroup(- monitorGroupId,- projectId,- )-- if (!monitorGroup) {- throw new NotFoundException('Monitor group not found.')- }-const monitor = await this.projectService.getMonitor(monitorId)if (!monitor) {@@ -2428,11 +2268,10 @@ export class ProjectController {@ApiOperation({ summary: 'Update monitor for the project' })@ApiBearerAuth()@ApiOkResponse({ type: MonitorEntity })- @Patch(':projectId/monitor-groups/:monitorGroupId/monitor/:monitorId')+ @Patch(':projectId/monitor/:monitorId')@Auth([], true, true)public async updateMonitor(@Param() { projectId }: ProjectIdDto,- @Param() { monitorGroupId }: MonitorGroupIdDto,@Param('monitorId') monitorId: number,@Body() body: UpdateMonitorHttpRequestDTO,@CurrentUserId() userId: string,@@ -2454,15 +2293,6 @@ export class ProjectController {this.projectService.allowedToManage(project, userId, user.roles)- const monitorGroup = await this.projectService.findMonitorGroup(- monitorGroupId,- projectId,- )-- if (!monitorGroup) {- throw new NotFoundException('Monitor group not found.')- }-const monitor = await this.projectService.getMonitor(monitorId)if (!monitor) {@@ -2481,11 +2311,10 @@ export class ProjectController {@ApiOperation({ summary: 'Delete monitor from the project' })@ApiBearerAuth()@ApiOkResponse({ description: 'Monitor deleted successfully' })- @Delete(':projectId/monitor-groups/:monitorGroupId/monitor/:monitorId')+ @Delete(':projectId/monitor/:monitorId')@Auth([], true, true)public async deleteMonitor(@Param() { projectId }: ProjectIdDto,- @Param() { monitorGroupId }: MonitorGroupIdDto,@Param('monitorId') monitorId: number,@CurrentUserId() userId: string,): Promise<void> {@@ -2505,15 +2334,6 @@ export class ProjectController {this.projectService.allowedToManage(project, userId, user.roles)- const monitorGroup = await this.projectService.findMonitorGroup(- monitorGroupId,- projectId,- )-- if (!monitorGroup) {- throw new NotFoundException('Monitor group not found.')- }-const monitor = await this.projectService.getMonitor(monitorId)if (!monitor) {diff --git a/apps/production/src/project/project.module.ts b/apps/production/src/project/project.module.tsindex 972b49d51..f370df0c7 100644--- a/apps/production/src/project/project.module.ts+++ b/apps/production/src/project/project.module.ts@@ -16,7 +16,6 @@ import { ProjectsViewsRepository } from './repositories/projects-views.repositorimport { ProjectViewEntity } from './entity/project-view.entity'import { ProjectViewCustomEventEntity } from './entity/project-view-custom-event.entity'import { MonitorConsumer } from './consumers/monitor.consumer'-import { MonitorGroupEntity } from './entity/monitor-group.entity'import { MonitorEntity } from './entity/monitor.entity'@Module({@@ -28,7 +27,6 @@ import { MonitorEntity } from './entity/monitor.entity'Funnel,ProjectViewEntity,ProjectViewCustomEventEntity,- MonitorGroupEntity,MonitorEntity,]),forwardRef(() => UserModule),diff --git a/apps/production/src/project/project.service.ts b/apps/production/src/project/project.service.tsindex c85d9c9ff..be9299cec 100644--- a/apps/production/src/project/project.service.ts+++ b/apps/production/src/project/project.service.ts@@ -80,9 +80,6 @@ import { browserArgs } from '../og-image/og-image.service'import { CreateProjectViewDto } from './dto/create-project-view.dto'import { AppLoggerService } from '../logger/logger.service'import { CreateMonitorHttpRequestDTO } from './dto/create-monitor.dto'-import { CreateMonitorGroupDto } from './dto/create-monitor-group.dto'-import { MonitorGroupEntity } from './entity/monitor-group.entity'-import { UpdateMonitorGroupDto } from './dto/update-monitor-group.dto'import { MonitorEntity } from './entity/monitor.entity'import { UpdateMonitorHttpRequestDTO } from './dto/update-monitor.dto'import { HttpRequestOptions } from './interfaces/http-request-options.interface'@@ -302,8 +299,6 @@ export class ProjectService {private readonly projectSubscriberRepository: Repository<ProjectSubscriber>,@InjectRepository(Funnel)private readonly funnelRepository: Repository<Funnel>,- @InjectRepository(MonitorGroupEntity)- private readonly monitorGroupRepository: Repository<MonitorGroupEntity>,@InjectRepository(MonitorEntity)private readonly monitorRepository: Repository<MonitorEntity>,private readonly actionTokens: ActionTokensService,@@ -1407,104 +1402,23 @@ export class ProjectService {}}- async createMonitorGroup(projectId: string, { name }: CreateMonitorGroupDto) {- const group = this.monitorGroupRepository.create({- name,- project: { id: projectId },- })-- await this.monitorGroupRepository.save(group)-- return group- }-- async getMonitorGroupsByProjectId(- projectId: string,- ): Promise<MonitorGroupEntity[]> {- return this.monitorGroupRepository.find({- where: { project: { id: projectId } },- })- }-- async getMonitorGroupById(- projectId: string,- monitorGroupId: string,- ): Promise<MonitorGroupEntity> {- return this.monitorGroupRepository.findOne({- where: { id: monitorGroupId, project: { id: projectId } },- })- }-- // Update a monitor group- async updateMonitorGroup(- projectId: string,- monitorGroupId: string,- updateMonitorGroupDto: UpdateMonitorGroupDto,- ): Promise<any> {- await this.monitorGroupRepository.update(- { id: monitorGroupId, project: { id: projectId } },- updateMonitorGroupDto,- )- // await this.monitorGroupRepository.update(monitorGroupId, updateMonitorGroupDto)- }-- async deleteMonitorGroup(- projectId: string,- monitorGroupId: string,- ): Promise<void> {- await this.monitorGroupRepository.delete({- id: monitorGroupId,- project: { id: projectId },- })- }-- async findMonitorGroupByProjectIdAndName(- projectId: string,- name: string,- ): Promise<MonitorGroupEntity | undefined> {- return this.monitorGroupRepository.findOne({- where: {- name,- project: { id: projectId },- },- })- }-- async findMonitorGroup(- id: string,- projectId: string,- options?: Omit<FindOneOptions<MonitorGroupEntity>, 'where'>,- ): Promise<MonitorGroupEntity | undefined> {- return this.monitorGroupRepository.findOne({- where: {- id,- project: { id: projectId },- },- ...options,- })- }-async findMonitorById(id: string,- groupId: string,projectId: string,options?: Omit<FindOneOptions<MonitorEntity>, 'where'>,): Promise<MonitorEntity | undefined> {return this.monitorRepository.findOne({where: {id,- group: {- id: groupId,- project: {- id: projectId,- },+ project: {+ id: projectId,},},...options,})}- async createMonitorInGroup(+ async createMonitor({type,name,@@ -1517,7 +1431,7 @@ export class ProjectService {description,httpOptions,}: CreateMonitorHttpRequestDTO,- group: string,+ projectId: string,): Promise<MonitorEntity> {const monitor = this.monitorRepository.create({type,@@ -1530,7 +1444,7 @@ export class ProjectService {acceptedStatusCodes,description,httpOptions,- group: { id: group },+ project: { id: projectId },})return this.monitorRepository.save(monitor)@@ -1545,6 +1459,26 @@ export class ProjectService {})}+ async paginateMonitors(+ options: PaginationOptionsInterface,+ where: Record<string, unknown> | undefined,+ ): Promise<Pagination<MonitorEntity>> {+ const [results, total] = await this.monitorRepository.findAndCount({+ take: options.take || 100,+ skip: options.skip || 0,+ where,+ order: {+ name: 'ASC',+ },+ relations: ['project'],+ })++ return new Pagination<MonitorEntity>({+ results,+ total,+ })+ }+async updateMonitor(monitorId: number,{diff --git a/migrations/mysql/2024_09_08.sql b/migrations/mysql/2024_08_08.sqlsimilarity index 100%rename from migrations/mysql/2024_09_08.sqlrename to migrations/mysql/2024_08_08.sqldiff --git a/migrations/mysql/2024_08_21.sql b/migrations/mysql/2024_08_21.sqlnew file mode 100644index 000000000..804a4eea6--- /dev/null+++ b/migrations/mysql/2024_08_21.sql@@ -0,0 +1,21 @@+DROP TABLE IF EXISTS monitor;+DROP TABLE IF EXISTS monitor_groups;++CREATE TABLE `monitor` (+ `id` bigint NOT NULL AUTO_INCREMENT,+ `type` varchar(255) NOT NULL,+ `name` varchar(255) NOT NULL,+ `url` varchar(255) NOT NULL,+ `interval` int NOT NULL,+ `retries` int NOT NULL,+ `retryInterval` int NOT NULL,+ `timeout` int NOT NULL,+ `acceptedStatusCodes` json NOT NULL,+ `description` text,+ `createdAt` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),+ `updatedAt` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),+ `httpOptions` json DEFAULT NULL,+ `projectId` varchar(12) DEFAULT NULL,+ PRIMARY KEY (`id`),+ FOREIGN KEY (`projectId`) REFERENCES `project` (`id`) ON DELETE CASCADE+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;