From a35ee9fdf26af0aa35479dbc35f7eb8a65c4cdcd Mon Sep 17 00:00:00 2001 From: Sergey Elpashev Date: Tue, 2 Jan 2024 14:06:20 +0300 Subject: [PATCH 1/2] Some db fixes --- .env.example | 2 +- backend/src/modules/settings/settings.service.ts | 6 ++++-- docker-compose.yml | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index a61b666..b25f5c8 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,6 @@ DATABASE_PASSWORD=postgres DATABASE_NAME=bot_db -DATABASE_USER=postgres +DATABASE_USERNAME=postgres DATABASE_HOST=localhost DATABASE_PORT=5432 diff --git a/backend/src/modules/settings/settings.service.ts b/backend/src/modules/settings/settings.service.ts index 4353356..bcb744f 100644 --- a/backend/src/modules/settings/settings.service.ts +++ b/backend/src/modules/settings/settings.service.ts @@ -39,8 +39,10 @@ export class SettingsService { editProfile.isActive = data.isActive; if (data.isActive) { const nowActive = await this.botSettingsRepository.findOneBy({ isActive: true }); - nowActive.isActive = false; - await this.botSettingsRepository.save(nowActive); + if (nowActive) { + nowActive.isActive = false; + await this.botSettingsRepository.save(nowActive); + } } } return await this.botSettingsRepository.save(editProfile); diff --git a/docker-compose.yml b/docker-compose.yml index efea673..5fa365f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ services: container_name: neuro_db image: postgres:alpine environment: - - POSTGRES_USER=${DATABASE_USER} + - POSTGRES_USER=${DATABASE_USERNAME} - POSTGRES_PASSWORD=${DATABASE_PASSWORD} - POSTGRES_DB=${DATABASE_NAME} - PGDATA=/var/lib/postgresql/data/pgdata From 38a9e0cbb98a03a93d64e5bf4a5ad89f1bb35108 Mon Sep 17 00:00:00 2001 From: Sergey Elpashev Date: Thu, 4 Jan 2024 21:00:43 +0300 Subject: [PATCH 2/2] Added message/caption entities --- backend/libs/database/post.entity.ts | 3 +++ backend/src/modules/post/post.dto.ts | 4 +++- backend/src/modules/post/post.service.ts | 5 +++-- neuro-reply-bot-reworked | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/backend/libs/database/post.entity.ts b/backend/libs/database/post.entity.ts index 739d593..f2e53de 100644 --- a/backend/libs/database/post.entity.ts +++ b/backend/libs/database/post.entity.ts @@ -34,4 +34,7 @@ export class Post { @OneToMany(() => Image, (image) => image.post) public images: Image[]; + + @Column({ nullable: true }) + public message_entities?: string; } diff --git a/backend/src/modules/post/post.dto.ts b/backend/src/modules/post/post.dto.ts index 9c94994..88856d0 100644 --- a/backend/src/modules/post/post.dto.ts +++ b/backend/src/modules/post/post.dto.ts @@ -3,9 +3,11 @@ import { ApiProperty } from '@nestjs/swagger'; export class ICreatePost { @ApiProperty({ description: 'Post text', example: 'Post text' }) readonly text!: string; - @ApiProperty({ description: 'An id of user that creating post', example: '1234' }) readonly from_user_id!: string; + @ApiProperty({ description: 'The id of user that creating post', example: '1234' }) readonly from_user_id!: string; @ApiProperty({ description: 'Post media group id', example: '123' }) readonly media_group_id?: string; + + @ApiProperty({ description: 'Message entities of text', example: '[]' }) readonly message_entities?: string; } export class IEditPost { diff --git a/backend/src/modules/post/post.service.ts b/backend/src/modules/post/post.service.ts index 08ba6f1..bd72b3d 100644 --- a/backend/src/modules/post/post.service.ts +++ b/backend/src/modules/post/post.service.ts @@ -23,11 +23,12 @@ export class PostService { media_group_id: data.media_group_id, from_user: user, timestamp: new Date(), + message_entities: data.message_entities, }); this.logger.log(`Created new post: ${result.uuid}`); return result; } catch (error) { - this.logger.debug(`[post.newPost] error: ${JSON.stringify(error)}`); + this.logger.debug(`[post.newPost] error: ${error}`); throw new HttpException('No user with this id', HttpStatus.BAD_REQUEST); } } @@ -91,7 +92,7 @@ export class PostService { if (!post) throw new Error("Can't find post"); return post; } catch (error) { - this.logger.debug(`[post.getByMediaGroup] error: ${JSON.stringify(error)}`); + this.logger.debug(`[post.getByMediaGroup] error: ${error}`); throw new HttpException("Can't find post with this media group id", HttpStatus.BAD_REQUEST); } } diff --git a/neuro-reply-bot-reworked b/neuro-reply-bot-reworked index 43b1c5e..230850b 160000 --- a/neuro-reply-bot-reworked +++ b/neuro-reply-bot-reworked @@ -1 +1 @@ -Subproject commit 43b1c5ecf4bc1def0af2bc3750db4644715e7031 +Subproject commit 230850bf65064cfbda318e715741624fecaed5f6