Commit a08408f6 authored by nanahira's avatar nanahira

add refId and api

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