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 { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { InfoModule } from './info/info.module';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
imports: [InfoModule],
|
||||
controllers: [],
|
||||
providers: [],
|
||||
})
|
||||
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 { plainToClass } from 'class-transformer';
|
||||
import { validate } from 'class-validator';
|
||||
import {
|
||||
BaseResponse,
|
||||
UpdateInfoRequest as UpdateInfoRequestInterface,
|
||||
} from './interfaces';
|
||||
import { UpdateInfoRequest as UpdateInfoRequestInterface } from './interfaces';
|
||||
import { BaseResponse } from '../interfaces';
|
||||
import { UpdateInfoRequest } from './models';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
}
|
||||
|
||||
export class InfoService {
|
||||
async validateInfo(
|
||||
rawData: UpdateInfoRequestInterface,
|
||||
): 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';
|
||||
|
||||
export interface UpdateInfoRequest {
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface BaseResponseInteface {
|
||||
success: boolean;
|
||||
data?: any;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user