Commit 23862051 authored by nanahira's avatar nanahira

new

parent a9c2bb68
Pipeline #36478 passed with stages
in 6 minutes and 9 seconds
...@@ -12,6 +12,9 @@ import { HttpModule } from '@nestjs/axios'; ...@@ -12,6 +12,9 @@ import { HttpModule } from '@nestjs/axios';
import { AdService } from './ad/ad.service'; import { AdService } from './ad/ad.service';
import { AdController } from './ad/ad.controller'; import { AdController } from './ad/ad.controller';
import { Ad } from './entities/ad.entity'; import { Ad } from './entities/ad.entity';
import { WhitelistAccountService } from './whitelist-account/whitelist-account.service';
import { WhitelistAccountController } from './whitelist-account/whitelist-account.controller';
import { WhitelistAccount } from './entities/whitelist-account.entity';
@Module({ @Module({
imports: [ imports: [
...@@ -25,11 +28,17 @@ import { Ad } from './entities/ad.entity'; ...@@ -25,11 +28,17 @@ import { Ad } from './entities/ad.entity';
inject: [ConfigService], inject: [ConfigService],
useFactory: async (config: ConfigService) => config.get('http') || {}, useFactory: async (config: ConfigService) => config.get('http') || {},
}), }),
TypeOrmModule.forFeature([
Blacklist,
BlacklistAccount,
Ad,
WhitelistAccount,
]),
TypeOrmModule.forRootAsync({ TypeOrmModule.forRootAsync({
inject: [ConfigService], inject: [ConfigService],
useFactory: async (config: ConfigService) => ({ useFactory: async (config: ConfigService) => ({
type: 'postgres', type: 'postgres',
entities: [Blacklist, BlacklistAccount, Ad], entities: [],
autoLoadEntities: true, autoLoadEntities: true,
synchronize: !config.get('DB_NO_INIT') || !!config.get('REFETCH'), synchronize: !config.get('DB_NO_INIT') || !!config.get('REFETCH'),
dropSchema: !!config.get('REFETCH'), dropSchema: !!config.get('REFETCH'),
...@@ -48,7 +57,12 @@ import { Ad } from './entities/ad.entity'; ...@@ -48,7 +57,12 @@ import { Ad } from './entities/ad.entity';
BlacklistService, BlacklistService,
FetchService, FetchService,
AdService, AdService,
WhitelistAccountService,
],
controllers: [
BlacklistAccountController,
AdController,
WhitelistAccountController,
], ],
controllers: [BlacklistAccountController, AdController],
}) })
export class AppModule {} export class AppModule {}
...@@ -6,7 +6,7 @@ import { RestfulFactory } from 'nicot'; ...@@ -6,7 +6,7 @@ import { RestfulFactory } from 'nicot';
const dec = new RestfulFactory(BlacklistAccount, { const dec = new RestfulFactory(BlacklistAccount, {
relations: ['blacklist'], relations: ['blacklist'],
}); });
class FindAllDto extends dec.findAllDto {} class FindAllBlacklistAccountDto extends dec.findAllDto {}
@Controller('blacklist') @Controller('blacklist')
export class BlacklistAccountController { export class BlacklistAccountController {
...@@ -19,7 +19,7 @@ export class BlacklistAccountController { ...@@ -19,7 +19,7 @@ export class BlacklistAccountController {
'Cache-Control', 'Cache-Control',
'public, max-age=600, stale-while-revalidate=600, stale-if-error=604800', 'public, max-age=600, stale-while-revalidate=600, stale-if-error=604800',
) )
findAll(@dec.findAllParam() param: FindAllDto) { findAll(@dec.findAllParam() param: FindAllBlacklistAccountDto) {
return this.blacklistAccountService.findAll(param); return this.blacklistAccountService.findAll(param);
} }
} }
import {
BoolColumn,
IdBase,
NotQueryable,
QueryColumn,
QueryCondition,
QueryEqual,
RestfulFactory,
StringColumn,
} from 'nicot';
import { Entity, Index } from 'typeorm';
@Entity()
export class WhitelistAccount extends IdBase() {
@NotQueryable()
@StringColumn(255, {
required: true,
description: 'name',
})
name: string;
@Index()
@QueryEqual()
@StringColumn(11, {
required: true,
description: 'QQ account number.',
})
account: string;
@NotQueryable()
@StringColumn(255, {
description: 'Twitter ID',
required: true,
})
twitter: string;
@NotQueryable()
@StringColumn(255, {
description: 'Fee',
})
fee: string;
@NotQueryable()
@StringColumn(255, {
description: 'type',
})
type: string;
@NotQueryable()
@StringColumn(255, {
description: 'forbidden',
})
forbidden: string;
@BoolColumn({
description: 'false => not active',
default: true,
})
@NotQueryable()
enabled: boolean;
@QueryColumn()
@QueryCondition((obj, qb, entityName, key) => {
if (obj[key] === 1) {
qb.orderBy('RANDOM()');
}
})
random: number;
getRecordsPerPage() {
return this.recordsPerPage || 5;
}
}
export const WhitelistAccountFactory = new RestfulFactory(WhitelistAccount, {
relations: [],
});
import { Test, TestingModule } from '@nestjs/testing';
import { WhitelistAccountController } from './whitelist-account.controller';
describe('WhitelistAccountController', () => {
let controller: WhitelistAccountController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [WhitelistAccountController],
}).compile();
controller = module.get<WhitelistAccountController>(WhitelistAccountController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});
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 {}
@Controller('whitelist-account')
export class WhitelistAccountController {
constructor(private service: WhitelistAccountService) {}
@WhitelistAccountFactory.findAll()
async findAll(
@WhitelistAccountFactory.findAllParam() dto: FindWhitelistAccountDto,
) {
return this.service.findAll(dto);
}
}
import { Test, TestingModule } from '@nestjs/testing';
import { WhitelistAccountService } from './whitelist-account.service';
describe('WhitelistAccountService', () => {
let service: WhitelistAccountService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [WhitelistAccountService],
}).compile();
service = module.get<WhitelistAccountService>(WhitelistAccountService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
import { Injectable } from '@nestjs/common';
import {
WhitelistAccount,
WhitelistAccountFactory,
} from '../entities/whitelist-account.entity';
import { InjectRepository } from '@nestjs/typeorm';
@Injectable()
export class WhitelistAccountService extends WhitelistAccountFactory.crudService(
{
extraGetQuery: (qb) => qb.andWhere('whitelistAccount.enabled = TRUE'),
},
) {
constructor(@InjectRepository(WhitelistAccount) repo) {
super(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