move to module info logic
This commit is contained in:
parent
f56be16064
commit
82c87e9358
@ -1,22 +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,18 +0,0 @@
|
|||||||
import { Controller, Post, Get, Body } from '@nestjs/common';
|
|
||||||
import { AppService } from './app.service';
|
|
||||||
import { BaseResponse, UpdateInfoRequest } from './interfaces';
|
|
||||||
|
|
||||||
@Controller()
|
|
||||||
export class AppController {
|
|
||||||
constructor(private readonly appService: AppService) {}
|
|
||||||
|
|
||||||
@Get()
|
|
||||||
getHello(): string {
|
|
||||||
return this.appService.getHello();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post('/validate-info')
|
|
||||||
getConfig(@Body() bodyRequest: UpdateInfoRequest): Promise<BaseResponse> {
|
|
||||||
return this.appService.validateInfo(bodyRequest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,10 +1,9 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { AppController } from './app.controller';
|
import { InfoModule } from './info/info.module';
|
||||||
import { AppService } from './app.service';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [],
|
imports: [InfoModule],
|
||||||
controllers: [AppController],
|
controllers: [],
|
||||||
providers: [AppService],
|
providers: [],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|||||||
14
src/info/info.controller.ts
Normal file
14
src/info/info.controller.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { Controller, Post, Body } from '@nestjs/common';
|
||||||
|
import { InfoService } from './info.service';
|
||||||
|
import { UpdateInfoRequest } from './interfaces';
|
||||||
|
import { BaseResponse } from '../interfaces';
|
||||||
|
|
||||||
|
@Controller('info')
|
||||||
|
export class InfoController {
|
||||||
|
constructor(private readonly infoService: InfoService) {}
|
||||||
|
|
||||||
|
@Post('/validate')
|
||||||
|
getConfig(@Body() bodyRequest: UpdateInfoRequest): Promise<BaseResponse> {
|
||||||
|
return this.infoService.validateInfo(bodyRequest);
|
||||||
|
}
|
||||||
|
}
|
||||||
10
src/info/info.module.ts
Normal file
10
src/info/info.module.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { InfoController } from './info.controller';
|
||||||
|
import { InfoService } from './info.service';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [],
|
||||||
|
controllers: [InfoController],
|
||||||
|
providers: [InfoService],
|
||||||
|
})
|
||||||
|
export class InfoModule {}
|
||||||
@ -1,18 +1,12 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { plainToClass } from 'class-transformer';
|
import { plainToClass } from 'class-transformer';
|
||||||
import { validate } from 'class-validator';
|
import { validate } from 'class-validator';
|
||||||
import {
|
import { UpdateInfoRequest as UpdateInfoRequestInterface } from './interfaces';
|
||||||
BaseResponse,
|
import { BaseResponse } from '../interfaces';
|
||||||
UpdateInfoRequest as UpdateInfoRequestInterface,
|
|
||||||
} from './interfaces';
|
|
||||||
import { UpdateInfoRequest } from './models';
|
import { UpdateInfoRequest } from './models';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AppService {
|
export class InfoService {
|
||||||
getHello(): string {
|
|
||||||
return 'Hello World!';
|
|
||||||
}
|
|
||||||
|
|
||||||
async validateInfo(
|
async validateInfo(
|
||||||
rawData: UpdateInfoRequestInterface,
|
rawData: UpdateInfoRequestInterface,
|
||||||
): Promise<BaseResponse> {
|
): Promise<BaseResponse> {
|
||||||
3
src/info/interfaces/index.ts
Normal file
3
src/info/interfaces/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export interface UpdateInfoRequest {
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
@ -1,9 +1,5 @@
|
|||||||
import { ValidationError } from 'class-validator';
|
import { ValidationError } from 'class-validator';
|
||||||
|
|
||||||
export interface UpdateInfoRequest {
|
|
||||||
name: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface BaseResponseInteface {
|
interface BaseResponseInteface {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
data?: any;
|
data?: any;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user