Commit a08408f6 authored by nanahira's avatar nanahira

add refId and api

parent 23862051
This diff is collapsed.
...@@ -21,51 +21,52 @@ ...@@ -21,51 +21,52 @@
"test:e2e": "jest --config ./test/jest-e2e.json" "test:e2e": "jest --config ./test/jest-e2e.json"
}, },
"dependencies": { "dependencies": {
"@nestjs/axios": "^0.1.0", "@nestjs/axios": "^4.0.1",
"@nestjs/common": "^9.0.0", "@nestjs/common": "^11.1.10",
"@nestjs/config": "^2.2.0", "@nestjs/config": "^4.0.2",
"@nestjs/core": "^9.0.0", "@nestjs/core": "^11.1.10",
"@nestjs/platform-express": "^9.0.0", "@nestjs/platform-express": "^11.1.10",
"@nestjs/swagger": "^6.0.3", "@nestjs/swagger": "^11.2.3",
"@nestjs/typeorm": "^9.0.0", "@nestjs/typeorm": "^11.0.0",
"axios": "^1.13.2",
"class-transformer": "^0.5.1", "class-transformer": "^0.5.1",
"class-validator": "^0.14.2", "class-validator": "^0.14.3",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"moment": "^2.29.4", "moment": "^2.30.1",
"nicot": "^1.1.21", "nicot": "^1.2.12",
"node-schedule": "^2.1.0", "node-schedule": "^2.1.1",
"pg": "^8.7.3", "pg": "^8.16.3",
"pg-native": "^3.5.0", "pg-native": "^3.5.2",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.2.2",
"rimraf": "^3.0.2", "rimraf": "^6.1.2",
"rxjs": "^7.2.0", "rxjs": "^7.8.2",
"typeorm": "^0.3.24", "typeorm": "^0.3.28",
"yaml": "^2.1.1" "yaml": "^2.8.2"
}, },
"devDependencies": { "devDependencies": {
"@nestjs/cli": "^9.0.0", "@nestjs/cli": "^11.0.14",
"@nestjs/schematics": "^9.0.0", "@nestjs/schematics": "^11.0.9",
"@nestjs/testing": "^9.0.0", "@nestjs/testing": "^11.1.10",
"@types/express": "^4.17.13", "@types/express": "^5.0.6",
"@types/jest": "28.1.4", "@types/jest": "30.0.0",
"@types/lodash": "^4.14.182", "@types/lodash": "^4.17.21",
"@types/node": "^18.11.9", "@types/node": "^25.0.3",
"@types/node-schedule": "^2.1.0", "@types/node-schedule": "^2.1.8",
"@types/supertest": "^2.0.11", "@types/supertest": "^6.0.3",
"@typescript-eslint/eslint-plugin": "^5.0.0", "@typescript-eslint/eslint-plugin": "^8.50.1",
"@typescript-eslint/parser": "^5.0.0", "@typescript-eslint/parser": "^8.50.1",
"eslint": "^8.0.1", "eslint": "^9.39.2",
"eslint-config-prettier": "^8.3.0", "eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^4.0.0", "eslint-plugin-prettier": "^5.5.4",
"jest": "28.1.2", "jest": "30.2.0",
"prettier": "^2.3.2", "prettier": "^3.7.4",
"source-map-support": "^0.5.20", "source-map-support": "^0.5.21",
"supertest": "^6.1.3", "supertest": "^7.1.4",
"ts-jest": "28.0.5", "ts-jest": "29.4.6",
"ts-loader": "^9.2.3", "ts-loader": "^9.5.4",
"ts-node": "^10.0.0", "ts-node": "^10.9.2",
"tsconfig-paths": "4.0.0", "tsconfig-paths": "4.2.0",
"typescript": "^4.9.3" "typescript": "^5.9.3"
}, },
"jest": { "jest": {
"moduleFileExtensions": [ "moduleFileExtensions": [
......
import { import {
BoolColumn, BoolColumn,
IdBase, IdBase,
IntColumn,
NotColumn,
NotQueryable, NotQueryable,
QueryColumn, QueryColumn,
QueryCondition, QueryCondition,
...@@ -8,7 +10,7 @@ import { ...@@ -8,7 +10,7 @@ import {
RestfulFactory, RestfulFactory,
StringColumn, StringColumn,
} from 'nicot'; } from 'nicot';
import { Entity, Index } from 'typeorm'; import { Entity, Index, ManyToOne, OneToMany } from 'typeorm';
@Entity() @Entity()
export class WhitelistAccount extends IdBase() { export class WhitelistAccount extends IdBase() {
...@@ -53,7 +55,7 @@ export class WhitelistAccount extends IdBase() { ...@@ -53,7 +55,7 @@ export class WhitelistAccount extends IdBase() {
forbidden: string; forbidden: string;
@BoolColumn({ @BoolColumn({
description: 'false => not active', description: 'false => not available in random',
default: true, default: true,
}) })
@NotQueryable() @NotQueryable()
...@@ -62,7 +64,8 @@ export class WhitelistAccount extends IdBase() { ...@@ -62,7 +64,8 @@ export class WhitelistAccount extends IdBase() {
@QueryColumn() @QueryColumn()
@QueryCondition((obj, qb, entityName, key) => { @QueryCondition((obj, qb, entityName, key) => {
if (obj[key] === 1) { if (obj[key] === 1) {
qb.orderBy('RANDOM()'); qb.orderBy('RANDOM()')
.andWhere(`${entityName}.enabled = TRUE`);
} }
}) })
random: number; random: number;
...@@ -70,8 +73,31 @@ export class WhitelistAccount extends IdBase() { ...@@ -70,8 +73,31 @@ export class WhitelistAccount extends IdBase() {
getRecordsPerPage() { getRecordsPerPage() {
return this.recordsPerPage || 5; return this.recordsPerPage || 5;
} }
@NotQueryable()
@IntColumn('bigint', {
unsigned: true,
description: 'Reference ID',
})
refId: number;
@NotColumn({
description: 'Referenced account',
})
@ManyToOne(() => WhitelistAccount, e => e.refs)
ref: WhitelistAccount;
@NotColumn({
description: 'Referenced by these accounts',
})
@OneToMany(() => WhitelistAccount, e => e.ref)
refs: WhitelistAccount[];
} }
export const WhitelistAccountFactory = new RestfulFactory(WhitelistAccount, { export const WhitelistAccountFactory = new RestfulFactory(WhitelistAccount, {
relations: [], relations: [
'ref',
'ref.refs',
'refs',
],
}); });
import { Controller } from '@nestjs/common'; import { Controller } from '@nestjs/common';
import { WhitelistAccountService } from './whitelist-account.service'; import { WhitelistAccountService } from './whitelist-account.service';
import { WhitelistAccountFactory } from '../entities/whitelist-account.entity'; import { WhitelistAccountFactory } from '../entities/whitelist-account.entity';
import { factory } from 'ts-jest/dist/transformers/hoist-jest';
class FindWhitelistAccountDto extends WhitelistAccountFactory.findAllDto {} class FindWhitelistAccountDto extends WhitelistAccountFactory.findAllDto {}
......
...@@ -8,7 +8,7 @@ import { InjectRepository } from '@nestjs/typeorm'; ...@@ -8,7 +8,7 @@ import { InjectRepository } from '@nestjs/typeorm';
@Injectable() @Injectable()
export class WhitelistAccountService extends WhitelistAccountFactory.crudService( export class WhitelistAccountService extends WhitelistAccountFactory.crudService(
{ {
extraGetQuery: (qb) => qb.andWhere('whitelistAccount.enabled = TRUE'), // extraGetQuery: (qb) => qb.andWhere('whitelistAccount.enabled = TRUE'),
}, },
) { ) {
constructor(@InjectRepository(WhitelistAccount) repo) { constructor(@InjectRepository(WhitelistAccount) repo) {
......
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