Добавил в таблицу поле с никнеймом

This commit is contained in:
Dhaverd 2026-05-08 00:10:35 +08:00
parent 5334968810
commit fe77b55275
8 changed files with 95 additions and 1 deletions

23
config/config.json Normal file
View File

@ -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"
}
}

View File

@ -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');
}
};

43
models/index.js Normal file
View File

@ -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;

View File

@ -2,10 +2,10 @@ import {
BadRequestException,
Body,
Controller,
Delete,
Get,
Param,
Post,
Delete,
Put,
Query,
} from '@nestjs/common';

View File

@ -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;
}

View File

@ -1,6 +1,7 @@
export type BlacklistReportDto = {
id: number;
steam_link: string;
steam_nickname: string;
comment: string;
toxic: boolean;
cheater: boolean;

View File

@ -5,6 +5,9 @@ export class BlacklistReport extends Model {
@Column
declare steam_link: string;
@Column
declare steam_nickname: string;
@Column
declare comment: string;

View File

@ -1,5 +1,6 @@
export type BlacklistItem = {
link: string;
nicknames: Array<string>;
comments: Array<string>;
toxic: number;
cheater: number;