add new module
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
describe('AppController', () => {
|
||||
let appController: AppController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const app: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
}).compile();
|
||||
|
||||
appController = app.get<AppController>(AppController);
|
||||
});
|
||||
|
||||
describe('root', () => {
|
||||
it('should return "Hello World!"', () => {
|
||||
expect(appController.getHello()).toBe('Hello World!');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,13 +0,0 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
|
||||
import { AppService } from './app.service';
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor(private readonly appService: AppService) {}
|
||||
|
||||
@Get()
|
||||
getHello(): string {
|
||||
return this.appService.getHello();
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -3,9 +3,11 @@ import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { ContentModule } from './modules/content/content.module';
|
||||
import { CoreModule } from './modules/core/core.module';
|
||||
import { DatabaseModule } from './modules/database/database.module';
|
||||
|
||||
@Module({
|
||||
imports: [ContentModule],
|
||||
imports: [ContentModule, CoreModule, DatabaseModule],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
})
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { IsNotEmpty, IsOptional, MaxLength } from 'class-validator';
|
||||
|
||||
@Injectable()
|
||||
export class CreatePostDto {
|
||||
@MaxLength(255, { always: true, message: 'the max length of content title is $constraint1' })
|
||||
@IsNotEmpty({ groups: ['create'], message: 'the title of content should not be empty' })
|
||||
@IsOptional({ groups: ['update'] })
|
||||
title: string;
|
||||
|
||||
@IsNotEmpty({ groups: ['create'], message: 'the body of content should not be empty' })
|
||||
@IsOptional({ groups: ['update'] })
|
||||
body: string;
|
||||
|
||||
@MaxLength(500, { always: true, message: 'the max length of content summary is $constraint1' })
|
||||
@IsOptional({ always: true })
|
||||
summary?: string;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PartialType } from '@nestjs/swagger';
|
||||
|
||||
import { IsDefined, IsNumber } from 'class-validator';
|
||||
|
||||
import { CreatePostDto } from './create-post.dto';
|
||||
|
||||
@Injectable()
|
||||
export class UpdatePostDto extends PartialType(CreatePostDto) {
|
||||
@IsNumber(undefined, { groups: ['update'], message: 'The format of the post ID is incorrect.' })
|
||||
@IsDefined({ groups: ['update'], message: 'The post ID must be specified' })
|
||||
id: number;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
export interface PostEntity {
|
||||
id: number;
|
||||
title: string;
|
||||
summary?: string;
|
||||
body: string;
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
import { DynamicModule, Global, Injectable, Module } from '@nestjs/common';
|
||||
import { get } from 'lodash';
|
||||
|
||||
import { AppController } from '@/app.controller';
|
||||
import { AppService } from '@/app.service';
|
||||
import { ContentModule } from '@/modules/content/content.module';
|
||||
|
||||
const config: Record<string, any> = {
|
||||
name: 'ray',
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class ConfigService {
|
||||
protected config: RecordAny = {};
|
||||
|
||||
constructor(data: RecordAny) {
|
||||
this.config = data;
|
||||
}
|
||||
|
||||
get<T>(key: string, defaultValue?: T): T | undefined {
|
||||
return get(config, key, defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
providers: [ConfigService],
|
||||
exports: [ConfigService],
|
||||
})
|
||||
export class CoreModule {
|
||||
static forRoot(options: { config: RecordAny }): DynamicModule {
|
||||
return {
|
||||
module: CoreModule,
|
||||
global: true,
|
||||
providers: [
|
||||
{
|
||||
provide: ConfigService,
|
||||
useFactory() {
|
||||
return new ConfigService(options.config);
|
||||
},
|
||||
},
|
||||
],
|
||||
exports: [ConfigService],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Module({
|
||||
imports: [ContentModule, CoreModule.forRoot({ config: { name: 'ray' } })],
|
||||
providers: [AppService],
|
||||
controllers: [AppController],
|
||||
})
|
||||
export class AppModule {}
|
||||
Reference in New Issue
Block a user