diff --git a/config/config.json b/config/config.json new file mode 100644 index 0000000..8d7b0e2 --- /dev/null +++ b/config/config.json @@ -0,0 +1,23 @@ +{ + "development": { + "username": "root", + "password": null, + "database": "hunt_blacklist", + "host": "127.0.0.1", + "dialect": "mysql" + }, + "test": { + "username": "root", + "password": null, + "database": "hunt_blacklist", + "host": "127.0.0.1", + "dialect": "mysql" + }, + "production": { + "username": "root", + "password": null, + "database": "hunt_blacklist", + "host": "127.0.0.1", + "dialect": "mysql" + } +} diff --git a/migrations/20260507153118-add-nickname-field-to-report.js b/migrations/20260507153118-add-nickname-field-to-report.js new file mode 100644 index 0000000..0424487 --- /dev/null +++ b/migrations/20260507153118-add-nickname-field-to-report.js @@ -0,0 +1,16 @@ +'use strict'; + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + async up (queryInterface, Sequelize) { + await queryInterface.addColumn('BlacklistReports', 'steam_nickname', { + type: Sequelize.STRING, + allowNull: true, // или false, если есть значение по умолчанию + after: 'steam_link' + }); + }, + + async down (queryInterface, Sequelize) { + await queryInterface.removeColumn('BlacklistReports', 'steam_nickname'); + } +}; diff --git a/models/index.js b/models/index.js new file mode 100644 index 0000000..024200e --- /dev/null +++ b/models/index.js @@ -0,0 +1,43 @@ +'use strict'; + +const fs = require('fs'); +const path = require('path'); +const Sequelize = require('sequelize'); +const process = require('process'); +const basename = path.basename(__filename); +const env = process.env.NODE_ENV || 'development'; +const config = require(__dirname + '/../config/config.json')[env]; +const db = {}; + +let sequelize; +if (config.use_env_variable) { + sequelize = new Sequelize(process.env[config.use_env_variable], config); +} else { + sequelize = new Sequelize(config.database, config.username, config.password, config); +} + +fs + .readdirSync(__dirname) + .filter(file => { + return ( + file.indexOf('.') !== 0 && + file !== basename && + file.slice(-3) === '.js' && + file.indexOf('.test.js') === -1 + ); + }) + .forEach(file => { + const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes); + db[model.name] = model; + }); + +Object.keys(db).forEach(modelName => { + if (db[modelName].associate) { + db[modelName].associate(db); + } +}); + +db.sequelize = sequelize; +db.Sequelize = Sequelize; + +module.exports = db; diff --git a/src/modules/blacklist/blacklist.controller.ts b/src/modules/blacklist/blacklist.controller.ts index 97feb2d..bfd00d9 100644 --- a/src/modules/blacklist/blacklist.controller.ts +++ b/src/modules/blacklist/blacklist.controller.ts @@ -2,10 +2,10 @@ import { BadRequestException, Body, Controller, + Delete, Get, Param, Post, - Delete, Put, Query, } from '@nestjs/common'; diff --git a/src/modules/blacklist/blacklist.service.ts b/src/modules/blacklist/blacklist.service.ts index 94b2fd4..118dd7e 100644 --- a/src/modules/blacklist/blacklist.service.ts +++ b/src/modules/blacklist/blacklist.service.ts @@ -36,6 +36,9 @@ export class BlacklistService { for (const record of records) { if (result[record.steam_link]) { const item: BlacklistItem = result[record.steam_link]; + if (record.steam_nickname !== null) { + item.nicknames.push(record.steam_nickname); + } item.comments.push(record.comment); item.toxic += Number(record.toxic); item.cheater += Number(record.cheater); @@ -46,6 +49,7 @@ export class BlacklistService { } else { const item: BlacklistItem = { link: record.steam_link, + nicknames: [], comments: [], toxic: Number(record.toxic), cheater: Number(record.cheater), @@ -53,6 +57,9 @@ export class BlacklistService { useless: Number(record.useless), griefer: Number(record.griefer), }; + if (record.steam_nickname !== null) { + item.nicknames.push(record.steam_nickname); + } item.comments.push(record.comment); result[record.steam_link] = item; } diff --git a/src/modules/blacklist/dto/blacklistReport.ts b/src/modules/blacklist/dto/blacklistReport.ts index 8157e7d..63ed4dd 100644 --- a/src/modules/blacklist/dto/blacklistReport.ts +++ b/src/modules/blacklist/dto/blacklistReport.ts @@ -1,6 +1,7 @@ export type BlacklistReportDto = { id: number; steam_link: string; + steam_nickname: string; comment: string; toxic: boolean; cheater: boolean; diff --git a/src/modules/blacklist/models/blacklistReport.model.ts b/src/modules/blacklist/models/blacklistReport.model.ts index e4b807e..5c90530 100644 --- a/src/modules/blacklist/models/blacklistReport.model.ts +++ b/src/modules/blacklist/models/blacklistReport.model.ts @@ -5,6 +5,9 @@ export class BlacklistReport extends Model { @Column declare steam_link: string; + @Column + declare steam_nickname: string; + @Column declare comment: string; diff --git a/src/modules/blacklist/types/blacklistItem.ts b/src/modules/blacklist/types/blacklistItem.ts index 4cab007..192ce5a 100644 --- a/src/modules/blacklist/types/blacklistItem.ts +++ b/src/modules/blacklist/types/blacklistItem.ts @@ -1,5 +1,6 @@ export type BlacklistItem = { link: string; + nicknames: Array; comments: Array; toxic: number; cheater: number;