Commit b320dae1 authored by nanahira's avatar nanahira

add createdAtSinceDaysAgo

parent 983f0333
Pipeline #35525 passed with stages
in 6 minutes and 29 seconds
...@@ -20,9 +20,10 @@ ...@@ -20,9 +20,10 @@
"class-validator": "^0.14.1", "class-validator": "^0.14.1",
"crypto-random-string": "3.3.1", "crypto-random-string": "3.3.1",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"moment": "^2.30.1",
"nesties": "^1.1.1", "nesties": "^1.1.1",
"nestjs-mycard": "^4.0.2", "nestjs-mycard": "^4.0.2",
"nicot": "^1.1.9", "nicot": "^1.1.11",
"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",
...@@ -5631,6 +5632,21 @@ ...@@ -5631,6 +5632,21 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/copy-anything": {
"version": "3.0.5",
"resolved": "https://registry.npmjs.org/copy-anything/-/copy-anything-3.0.5.tgz",
"integrity": "sha512-yCEafptTtb4bk7GLEQoM8KVJpxAfdBJYaXyzQEgQQQgYrZiDp8SJmGKlYza6CYjEDNstAdNdKA3UuoULlEbS6w==",
"license": "MIT",
"dependencies": {
"is-what": "^4.1.8"
},
"engines": {
"node": ">=12.13"
},
"funding": {
"url": "https://github.com/sponsors/mesqueeb"
}
},
"node_modules/core-util-is": { "node_modules/core-util-is": {
"version": "1.0.3", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
...@@ -7587,6 +7603,18 @@ ...@@ -7587,6 +7603,18 @@
"url": "https://github.com/sponsors/sindresorhus" "url": "https://github.com/sponsors/sindresorhus"
} }
}, },
"node_modules/is-what": {
"version": "4.1.16",
"resolved": "https://registry.npmjs.org/is-what/-/is-what-4.1.16.tgz",
"integrity": "sha512-ZhMwEosbFJkA0YhFnNDgTM4ZxDRsS6HqTo7qsZM08fehyRYIYa0yHu5R6mgo1n/8MgaPBXiPimPD77baVFYg+A==",
"license": "MIT",
"engines": {
"node": ">=12.13"
},
"funding": {
"url": "https://github.com/sponsors/mesqueeb"
}
},
"node_modules/isarray": { "node_modules/isarray": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
...@@ -8901,6 +8929,15 @@ ...@@ -8901,6 +8929,15 @@
"mkdirp": "bin/cmd.js" "mkdirp": "bin/cmd.js"
} }
}, },
"node_modules/moment": {
"version": "2.30.1",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.30.1.tgz",
"integrity": "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==",
"license": "MIT",
"engines": {
"node": "*"
}
},
"node_modules/ms": { "node_modules/ms": {
"version": "2.1.3", "version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
...@@ -9008,14 +9045,14 @@ ...@@ -9008,14 +9045,14 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/nesties": { "node_modules/nesties": {
"version": "1.1.1", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/nesties/-/nesties-1.1.1.tgz", "resolved": "https://registry.npmjs.org/nesties/-/nesties-1.1.2.tgz",
"integrity": "sha512-M8G3MPQKaxgRHK9UkGc1BtPZC1n37SNMAmVH9EIzaXxyMzXNOMR7Aqu/9ikXc6IDcF1VB3JKYpcDyZYG+EtZKw==", "integrity": "sha512-fzSToGOcde+rjXWpCoEUdEEIpTm59rl7d9SpsPqc6OnmdAiY9nfV3JOeymkBkjrTOhK7yN7U7NPDDZZ6GX40+A==",
"license": "MIT", "license": "MIT",
"peerDependencies": { "peerDependencies": {
"@nestjs/common": "^9.4.0 || ^10.0.0 || ^11.0.0", "@nestjs/common": "^11.0.0 || ^9.4.0 || ^10.0.0",
"@nestjs/config": "^3.0.0 || ^4.0.0", "@nestjs/config": "^4.0.0 || ^3.0.0",
"@nestjs/swagger": "^7.1.8 || ^6.3.0 || ^11.0.0" "@nestjs/swagger": "^11.0.0 || ^7.1.8 || ^6.3.0"
} }
}, },
"node_modules/nestjs-mycard": { "node_modules/nestjs-mycard": {
...@@ -9034,18 +9071,20 @@ ...@@ -9034,18 +9071,20 @@
} }
}, },
"node_modules/nicot": { "node_modules/nicot": {
"version": "1.1.9", "version": "1.1.11",
"resolved": "https://registry.npmjs.org/nicot/-/nicot-1.1.9.tgz", "resolved": "https://registry.npmjs.org/nicot/-/nicot-1.1.11.tgz",
"integrity": "sha512-DG4SK6E0DQ8JBKn8xGL6cbpXBQxTfUdC2d6r6Pu2OSKM6yyz7EmhBHcviSGbNUNArShljmc06YCaj7sqqqRSyw==", "integrity": "sha512-ttZayz/JbVaJ4R4MA3bPht1+qGAC/DJ6/9sPw72wICuWakSFSMaxJbX4yQxdZ1TP8+fDYxt2UGEtrtkMbpbdrA==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"lodash": "^4.17.21", "lodash": "^4.17.21",
"nesties": "^1.1.1", "nesties": "^1.1.2",
"superjson": "1.13.3",
"typed-reflector": "^1.0.11" "typed-reflector": "^1.0.11"
}, },
"peerDependencies": { "peerDependencies": {
"@nestjs/common": "^9.4.0 || ^10.0.0 || ^11.0.14", "@nestjs/common": "^11.0.0 || ^9.4.0 || ^10.0.0",
"@nestjs/swagger": "^7.1.8 || ^6.3.0 || ^11.1.1", "@nestjs/config": "^4.0.0 || ^3.0.0",
"@nestjs/swagger": "^11.0.0 || ^7.1.8 || ^6.3.0",
"class-transformer": "^0.5.1", "class-transformer": "^0.5.1",
"class-validator": "^0.14.0", "class-validator": "^0.14.0",
"typeorm": "^0.3.16" "typeorm": "^0.3.16"
...@@ -10855,6 +10894,18 @@ ...@@ -10855,6 +10894,18 @@
"node": ">=14.18.0" "node": ">=14.18.0"
} }
}, },
"node_modules/superjson": {
"version": "1.13.3",
"resolved": "https://registry.npmjs.org/superjson/-/superjson-1.13.3.tgz",
"integrity": "sha512-mJiVjfd2vokfDxsQPOwJ/PtanO87LhpYY88ubI5dUB1Ab58Txbyje3+jpm+/83R/fevaq/107NNhtYBLuoTrFg==",
"license": "MIT",
"dependencies": {
"copy-anything": "^3.0.2"
},
"engines": {
"node": ">=10"
}
},
"node_modules/supertest": { "node_modules/supertest": {
"version": "7.1.0", "version": "7.1.0",
"resolved": "https://registry.npmjs.org/supertest/-/supertest-7.1.0.tgz", "resolved": "https://registry.npmjs.org/supertest/-/supertest-7.1.0.tgz",
......
...@@ -14,6 +14,7 @@ import { ...@@ -14,6 +14,7 @@ import {
JsonColumn, JsonColumn,
NotChangeable, NotChangeable,
NotColumn, NotColumn,
NotInResult,
NotQueryable, NotQueryable,
NotWritable, NotWritable,
QueryEqual, QueryEqual,
...@@ -31,6 +32,7 @@ import { Match } from '../../match/entities/match.entity'; ...@@ -31,6 +32,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 { QuerySinceDaysAgo } from '../../utility/query-since-days-ago';
export enum TournamentRule { export enum TournamentRule {
SingleElimination = 'SingleElimination', SingleElimination = 'SingleElimination',
...@@ -126,6 +128,17 @@ export class Tournament extends DescBase { ...@@ -126,6 +128,17 @@ export class Tournament extends DescBase {
@DateColumn({ description: '创建时间', columnExtras: { nullable: false } }) @DateColumn({ description: '创建时间', columnExtras: { nullable: false } })
createdAt: Date; createdAt: Date;
@NotWritable()
@NotInResult()
@IsInt()
@IsPositive()
@QuerySinceDaysAgo('createdAt')
@ApiProperty({
description: '查询最多创建时间在多少天前的比赛',
required: false,
})
createdAtSinceDaysAgo: number;
@NotColumn() @NotColumn()
@OneToMany(() => Participant, (participant) => participant.tournament) @OneToMany(() => Participant, (participant) => participant.tournament)
participants: Participant[]; participants: Participant[];
......
import { QueryCondition } from 'nicot';
import moment from 'moment';
export const QuerySinceDaysAgo = (dateField: string) =>
QueryCondition((obj, qb, entityName, key) => {
if (!obj[key]) return;
const since = moment().subtract(obj[key], 'days').toDate();
const typeormKey = `since_${entityName}_${dateField}_${key}`;
qb.andWhere(`${entityName}.${dateField} > :${typeormKey}`, {
[typeormKey]: since,
});
});
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