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 @@ ...@@ -22,7 +22,7 @@
"lodash": "^4.17.21", "lodash": "^4.17.21",
"nesties": "^1.1.1", "nesties": "^1.1.1",
"nestjs-mycard": "^4.0.2", "nestjs-mycard": "^4.0.2",
"nicot": "^1.1.17", "nicot": "^1.1.21",
"pg": "^8.14.1", "pg": "^8.14.1",
"pg-native": "^3.3.0", "pg-native": "^3.3.0",
"reflect-metadata": "^0.2.2", "reflect-metadata": "^0.2.2",
...@@ -9067,9 +9067,9 @@ ...@@ -9067,9 +9067,9 @@
} }
}, },
"node_modules/nicot": { "node_modules/nicot": {
"version": "1.1.17", "version": "1.1.21",
"resolved": "https://registry.npmjs.org/nicot/-/nicot-1.1.17.tgz", "resolved": "https://registry.npmjs.org/nicot/-/nicot-1.1.21.tgz",
"integrity": "sha512-80Bj537a/KJZNbK5RyAf0NNzrmtygQuX0OOAkLGlmYwaTxmSqNTJ/NyWiao+ObUIu6GG3HM68erhcxSgK6ihhA==", "integrity": "sha512-25OSyXQ7WCjj/UXg0CvYa01+kZj5dGDTalUAL9bAr1/1Qt/swN6tPyEPss9h66+UIizHAR4OvOw54dW7KS5yHQ==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"lodash": "^4.17.21", "lodash": "^4.17.21",
......
...@@ -18,6 +18,7 @@ import { ...@@ -18,6 +18,7 @@ import {
NotQueryable, NotQueryable,
NotWritable, NotWritable,
QueryColumn, QueryColumn,
QueryCondition,
QueryEqual, QueryEqual,
QueryGreaterEqual, QueryGreaterEqual,
QueryLessEqual, QueryLessEqual,
...@@ -41,6 +42,7 @@ import { Match } from '../../match/entities/match.entity'; ...@@ -41,6 +42,7 @@ import { Match } from '../../match/entities/match.entity';
import { TournamentRules } from '../../tournament-rules/rule-map'; import { TournamentRules } from '../../tournament-rules/rule-map';
import _ from 'lodash'; import _ from 'lodash';
import { RenameClass } from 'nicot/dist/src/utility/rename-class'; import { RenameClass } from 'nicot/dist/src/utility/rename-class';
import { QueryIn } from '../../utility/decorators/query-in';
export enum TournamentRule { export enum TournamentRule {
SingleElimination = 'SingleElimination', SingleElimination = 'SingleElimination',
...@@ -79,7 +81,7 @@ export class RuleSettings { ...@@ -79,7 +81,7 @@ export class RuleSettings {
@Entity() @Entity()
export class Tournament extends DescBase { export class Tournament extends DescBase {
@QueryEqual() @QueryEqual()
@NotChangeable() // @NotChangeable()
@EnumColumn(TournamentRule, { @EnumColumn(TournamentRule, {
default: TournamentRule.SingleElimination, default: TournamentRule.SingleElimination,
description: '规则', description: '规则',
...@@ -91,7 +93,8 @@ export class Tournament extends DescBase { ...@@ -91,7 +93,8 @@ export class Tournament extends DescBase {
return new ruleClass(this, repo); return new ruleClass(this, repo);
} }
@NotChangeable() // @NotChangeable()
@NotQueryable()
@JsonColumn(RenameClass(PartialType(RuleSettings), 'RuleSettingsPartial'), { @JsonColumn(RenameClass(PartialType(RuleSettings), 'RuleSettingsPartial'), {
description: '比赛规则参数', description: '比赛规则参数',
}) })
...@@ -111,6 +114,10 @@ export class Tournament extends DescBase { ...@@ -111,6 +114,10 @@ export class Tournament extends DescBase {
}) })
status: TournamentStatus; status: TournamentStatus;
@QueryColumn()
@QueryIn('status')
statusIn: string;
@NotWritable() @NotWritable()
@Index() @Index()
@IntColumn('int', { @IntColumn('int', {
......
...@@ -43,12 +43,24 @@ export class TournamentService extends CrudService(Tournament, { ...@@ -43,12 +43,24 @@ export class TournamentService extends CrudService(Tournament, {
return this.create(tournament); return this.create(tournament);
} }
private readyEditableFields: (keyof Tournament)[] = ['rule', 'ruleSettings'];
async updateTournament( async updateTournament(
id: number, id: number,
dto: Partial<Tournament>, dto: Partial<Tournament>,
user: MycardUser, 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); 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