From 9aeea7f22c85194928e4d4b1b567f5d1cc1eec5c Mon Sep 17 00:00:00 2001 From: Dhaverd Date: Tue, 21 Jul 2026 14:47:19 +0800 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B0=D0=BB=20=D0=BF=D1=80=D0=BE=D1=81=D1=82=D0=BE?= =?UTF-8?q?=20=D0=BE=D1=82=D0=BC=D0=B5=D1=82=D0=BA=D0=B8=20=D0=BA=D0=B0?= =?UTF-8?q?=D1=87=D0=B5=D1=81=D1=82=D0=B2=20=D0=B2=20=D1=80=D0=B5=D0=B9?= =?UTF-8?q?=D1=82=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1030413-add_rating_to_blacklist_reports.js | 45 ++++++++++++++ src/modules/blacklist/blacklist.service.ts | 41 +++++++++++- src/modules/blacklist/dto/blacklistReport.ts | 12 ++-- .../blacklist/models/blacklistReport.model.ts | 62 +++++++++++++++---- .../blacklist/types/blacklistItemList.ts | 5 +- 5 files changed, 142 insertions(+), 23 deletions(-) create mode 100644 migrations/20260721030413-add_rating_to_blacklist_reports.js diff --git a/migrations/20260721030413-add_rating_to_blacklist_reports.js b/migrations/20260721030413-add_rating_to_blacklist_reports.js new file mode 100644 index 0000000..2b7e66b --- /dev/null +++ b/migrations/20260721030413-add_rating_to_blacklist_reports.js @@ -0,0 +1,45 @@ +'use strict'; + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + async up (queryInterface, Sequelize) { + const tableName = 'BlacklistReports'; // Убедитесь, что имя таблицы совпадает + const columns = ['toxic', 'cheater', 'afk', 'useless', 'griefer', 'smurf']; + + for (const column of columns) { + // 1. Сначала конвертируем данные внутри колонки через SQL-запрос. + // В MySQL true — это 1, а false — это 0. + await queryInterface.sequelize.query(` + UPDATE \`${tableName}\` + SET \`${column}\` = CASE WHEN \`${column}\` = 1 THEN 10 ELSE 0 END + `); + + // 2. Теперь безопасно меняем тип самой колонки на TINYINT + await queryInterface.changeColumn(tableName, column, { + type: Sequelize.TINYINT, + allowNull: false, + defaultValue: 0 + }); + } + }, + + async down (queryInterface, Sequelize) { + const tableName = 'BlacklistReports'; + const columns = ['toxic', 'cheater', 'afk', 'useless', 'griefer', 'smurf']; + + for (const column of columns) { + // Откат: если оценка меньше 5, возвращаем 1 (true), иначе 0 (false) + await queryInterface.sequelize.query(` + UPDATE \`${tableName}\` + SET \`${column}\` = CASE WHEN \`${column}\` < 5 THEN 1 ELSE 0 END + `); + + // Возвращаем тип BOOLEAN + await queryInterface.changeColumn(tableName, column, { + type: Sequelize.BOOLEAN, + allowNull: false, + defaultValue: false + }); + } + } +}; diff --git a/src/modules/blacklist/blacklist.service.ts b/src/modules/blacklist/blacklist.service.ts index ffd9bea..9e6eade 100644 --- a/src/modules/blacklist/blacklist.service.ts +++ b/src/modules/blacklist/blacklist.service.ts @@ -78,7 +78,7 @@ export class BlacklistService { const result: BlacklistItemList = {}; for (const record of records) { if (result[record.steam_link]) { - const item: BlacklistItem = result[record.steam_link]; + const item: BlacklistItem = result[record.steam_link].blacklistItem; if (record.steam_nickname !== null) { item.nicknames.push(record.steam_nickname); } @@ -89,7 +89,10 @@ export class BlacklistService { item.useless += Number(record.useless); item.griefer += Number(record.griefer); item.smurf += Number(record.smurf); - result[record.steam_link] = item; + result[record.steam_link] = { + blacklistItem: item, + reportCount: result[record.steam_link].reportCount + 1, + }; } else { const item: BlacklistItem = { link: record.steam_link, @@ -106,9 +109,41 @@ export class BlacklistService { item.nicknames.push(record.steam_nickname); } item.comments.push(record.comment); - result[record.steam_link] = item; + result[record.steam_link] = { + blacklistItem: item, + reportCount: 1, + }; } } + for (const res in result) { + result[res].blacklistItem.toxic = + Math.round( + (result[res].blacklistItem.toxic / 2 / result[res].reportCount) * 100, + ) / 100; + result[res].blacklistItem.cheater = + Math.round( + (result[res].blacklistItem.cheater / 2 / result[res].reportCount) * + 100, + ) / 100; + result[res].blacklistItem.afk = + Math.round( + (result[res].blacklistItem.afk / 2 / result[res].reportCount) * 100, + ) / 100; + result[res].blacklistItem.useless = + Math.round( + (result[res].blacklistItem.useless / 2 / result[res].reportCount) * + 100, + ) / 100; + result[res].blacklistItem.griefer = + Math.round( + (result[res].blacklistItem.griefer / 2 / result[res].reportCount) * + 100, + ) / 100; + result[res].blacklistItem.smurf = + Math.round( + (result[res].blacklistItem.smurf / 2 / result[res].reportCount) * 100, + ) / 100; + } return result; } diff --git a/src/modules/blacklist/dto/blacklistReport.ts b/src/modules/blacklist/dto/blacklistReport.ts index 243ead0..8f78e11 100644 --- a/src/modules/blacklist/dto/blacklistReport.ts +++ b/src/modules/blacklist/dto/blacklistReport.ts @@ -3,10 +3,10 @@ export type BlacklistReportDto = { steam_link: string; steam_nickname: string; comment: string; - toxic: boolean; - cheater: boolean; - afk: boolean; - useless: boolean; - griefer: boolean; - smurf: boolean; + toxic: number; + cheater: number; + afk: number; + useless: number; + griefer: number; + smurf: number; }; diff --git a/src/modules/blacklist/models/blacklistReport.model.ts b/src/modules/blacklist/models/blacklistReport.model.ts index 9bec0e0..d2c1cbe 100644 --- a/src/modules/blacklist/models/blacklistReport.model.ts +++ b/src/modules/blacklist/models/blacklistReport.model.ts @@ -1,4 +1,4 @@ -import { Column, DataType, Model, Table } from 'sequelize-typescript'; +import { Column, DataType, Max, Min, Model, Table } from 'sequelize-typescript'; @Table export class BlacklistReport extends Model { @@ -11,23 +11,59 @@ export class BlacklistReport extends Model { @Column declare comment: string; - @Column({ defaultValue: false }) - declare toxic: boolean; + @Min(0) + @Max(10) + @Column({ + type: DataType.TINYINT, + allowNull: false, + defaultValue: false, + }) + declare toxic: number; - @Column({ defaultValue: false }) - declare cheater: boolean; + @Min(0) + @Max(10) + @Column({ + type: DataType.TINYINT, + allowNull: false, + defaultValue: false, + }) + declare cheater: number; - @Column({ defaultValue: false }) - declare afk: boolean; + @Min(0) + @Max(10) + @Column({ + type: DataType.TINYINT, + allowNull: false, + defaultValue: false, + }) + declare afk: number; - @Column({ defaultValue: false }) - declare useless: boolean; + @Min(0) + @Max(10) + @Column({ + type: DataType.TINYINT, + allowNull: false, + defaultValue: false, + }) + declare useless: number; - @Column({ defaultValue: false }) - declare griefer: boolean; + @Min(0) + @Max(10) + @Column({ + type: DataType.TINYINT, + allowNull: false, + defaultValue: false, + }) + declare griefer: number; - @Column({ defaultValue: false }) - declare smurf: boolean; + @Min(0) + @Max(10) + @Column({ + type: DataType.TINYINT, + allowNull: false, + defaultValue: false, + }) + declare smurf: number; @Column({ type: DataType.DATE, diff --git a/src/modules/blacklist/types/blacklistItemList.ts b/src/modules/blacklist/types/blacklistItemList.ts index 76e9c70..a46003f 100644 --- a/src/modules/blacklist/types/blacklistItemList.ts +++ b/src/modules/blacklist/types/blacklistItemList.ts @@ -1,5 +1,8 @@ import { BlacklistItem } from './blacklistItem'; export type BlacklistItemList = { - [index: string]: BlacklistItem; + [index: string]: { + blacklistItem: BlacklistItem; + reportCount: number; + }; };