Commit b913277a authored by nanahira's avatar nanahira

add statusIn, and updated edit rules

parent 6caf4810
Pipeline #36512 passed with stages
in 6 minutes and 30 seconds
......@@ -22,7 +22,7 @@
"lodash": "^4.17.21",
"nesties": "^1.1.1",
"nestjs-mycard": "^4.0.2",
"nicot": "^1.1.17",
"nicot": "^1.1.21",
"pg": "^8.14.1",
"pg-native": "^3.3.0",
"reflect-metadata": "^0.2.2",
......@@ -9067,9 +9067,9 @@
}
},
"node_modules/nicot": {
"version": "1.1.17",
"resolved": "https://registry.npmjs.org/nicot/-/nicot-1.1.17.tgz",
"integrity": "sha512-80Bj537a/KJZNbK5RyAf0NNzrmtygQuX0OOAkLGlmYwaTxmSqNTJ/NyWiao+ObUIu6GG3HM68erhcxSgK6ihhA==",
"version": "1.1.21",
"resolved": "https://registry.npmjs.org/nicot/-/nicot-1.1.21.tgz",
"integrity": "sha512-25OSyXQ7WCjj/UXg0CvYa01+kZj5dGDTalUAL9bAr1/1Qt/swN6tPyEPss9h66+UIizHAR4OvOw54dW7KS5yHQ==",
"license": "MIT",
"dependencies": {
"lodash": "^4.17.21",
......
......@@ -18,6 +18,7 @@ import {
NotQueryable,
NotWritable,
QueryColumn,
QueryCondition,
QueryEqual,
QueryGreaterEqual,
QueryLessEqual,
......@@ -41,6 +42,7 @@ import { Match } from '../../match/entities/match.entity';
import { TournamentRules } from '../../tournament-rules/rule-map';
import _ from 'lodash';
import { RenameClass } from 'nicot/dist/src/utility/rename-class';
import { QueryIn } from '../../utility/decorators/query-in';
export enum TournamentRule {
SingleElimination = 'SingleElimination',
......@@ -79,7 +81,7 @@ export class RuleSettings {
@Entity()
export class Tournament extends DescBase {
@QueryEqual()
@NotChangeable()
// @NotChangeable()
@EnumColumn(TournamentRule, {
default: TournamentRule.SingleElimination,
description: '规则',
......@@ -91,7 +93,8 @@ export class Tournament extends DescBase {
return new ruleClass(this, repo);
}
@NotChangeable()
// @NotChangeable()
@NotQueryable()
@JsonColumn(RenameClass(PartialType(RuleSettings), 'RuleSettingsPartial'), {
description: '比赛规则参数',
})
......@@ -111,6 +114,10 @@ export class Tournament extends DescBase {
})
status: TournamentStatus;
@QueryColumn()
@QueryIn('status')
statusIn: string;
@NotWritable()
@Index()
@IntColumn('int', {
......
......@@ -43,12 +43,24 @@ export class TournamentService extends CrudService(Tournament, {
return this.create(tournament);
}
private readyEditableFields: (keyof Tournament)[] = ['rule', 'ruleSettings'];
async updateTournament(
id: number,
dto: Partial<Tournament>,
user: MycardUser,
) {
await this.checkPermissionOfTournament(id, user);
const tournament = await this.checkPermissionOfTournament(id, user);
if (tournament.status !== TournamentStatus.Ready) {
for (const field of this.readyEditableFields) {
if (dto[field] !== undefined) {
throw new BlankReturnMessageDto(
403,
'比赛已经开始,不能修改规则。',
).toException();
}
}
}
return this.update(id, dto);
}
......
import { QueryCondition } from 'nicot';
export const QueryIn = (field: string) =>
QueryCondition((obj, qb, entityName, key) => {
if (obj[key]) {
const values = (obj[key] as string).split(',');
qb.andWhere(`${entityName}.${field} IN (:...${key})`, { [key]: values });
}
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment