Initial commit
This commit is contained in:
22
apps/backend/src/app.controller.spec.ts
Normal file
22
apps/backend/src/app.controller.spec.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
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!');
|
||||
});
|
||||
});
|
||||
});
|
||||
12
apps/backend/src/app.controller.ts
Normal file
12
apps/backend/src/app.controller.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
11
apps/backend/src/app.module.ts
Normal file
11
apps/backend/src/app.module.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { HelloController } from './hello/hello.controller';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
controllers: [AppController, HelloController],
|
||||
providers: [AppService],
|
||||
})
|
||||
export class AppModule {}
|
||||
8
apps/backend/src/app.service.ts
Normal file
8
apps/backend/src/app.service.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
}
|
||||
}
|
||||
18
apps/backend/src/hello/hello.controller.spec.ts
Normal file
18
apps/backend/src/hello/hello.controller.spec.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { HelloController } from './hello.controller';
|
||||
|
||||
describe('HelloController', () => {
|
||||
let controller: HelloController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [HelloController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<HelloController>(HelloController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
20
apps/backend/src/hello/hello.controller.ts
Normal file
20
apps/backend/src/hello/hello.controller.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Controller } from '@nestjs/common';
|
||||
import { tsRestHandler, TsRestHandler } from '@ts-rest/nest';
|
||||
import { contracts } from '@my-monorepo/common';
|
||||
|
||||
@Controller()
|
||||
export class HelloController {
|
||||
@TsRestHandler(contracts)
|
||||
handler(): unknown {
|
||||
return tsRestHandler(contracts, {
|
||||
hello: () => {
|
||||
return Promise.resolve({
|
||||
status: 200,
|
||||
body: {
|
||||
payload: 'hello',
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
8
apps/backend/src/main.ts
Normal file
8
apps/backend/src/main.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
await app.listen(process.env.PORT ?? 3000);
|
||||
}
|
||||
bootstrap();
|
||||
Reference in New Issue
Block a user