parent
81da0f2766
commit
7af426c262
@ -1,7 +1,7 @@ |
||||
import { Test, TestingModule } from '@nestjs/testing'; |
||||
import { AppController } from './app.controller'; |
||||
import { AppService } from './app.service'; |
||||
import { DbClient } from './db'; |
||||
import { DbClient } from '../db'; |
||||
|
||||
describe('AppController', () => { |
||||
let appController: AppController; |
@ -1,5 +1,5 @@ |
||||
import { Inject, Injectable } from '@nestjs/common'; |
||||
import { DbClient } from './db'; |
||||
import { DbClient } from '../db'; |
||||
|
||||
@Injectable() |
||||
export class AppService { |
@ -0,0 +1,20 @@ |
||||
import { Test, TestingModule } from '@nestjs/testing'; |
||||
import { CalendarController } from './calendar.controller'; |
||||
import { CalendarService } from './calendar.service'; |
||||
|
||||
describe('CalendarController', () => { |
||||
let controller: CalendarController; |
||||
|
||||
beforeEach(async () => { |
||||
const module: TestingModule = await Test.createTestingModule({ |
||||
controllers: [CalendarController], |
||||
providers: [CalendarService], |
||||
}).compile(); |
||||
|
||||
controller = module.get<CalendarController>(CalendarController); |
||||
}); |
||||
|
||||
it('should be defined', () => { |
||||
expect(controller).toBeDefined(); |
||||
}); |
||||
}); |
@ -0,0 +1,24 @@ |
||||
import { |
||||
Body, |
||||
ClassSerializerInterceptor, |
||||
Controller, |
||||
HttpCode, |
||||
Post, |
||||
UseInterceptors, |
||||
} from '@nestjs/common'; |
||||
import { CalendarService } from './calendar.service'; |
||||
import { QueryParamsDto, QueryResponseDto } from './calendar.dto'; |
||||
|
||||
@Controller('calendar') |
||||
export class CalendarController { |
||||
constructor(private readonly calendarService: CalendarService) {} |
||||
|
||||
@Post('query') |
||||
@HttpCode(200) |
||||
@UseInterceptors(ClassSerializerInterceptor) |
||||
async getAvailableSlots( |
||||
@Body() queryParamsDto: QueryParamsDto, |
||||
): Promise<QueryResponseDto[]> { |
||||
return await this.calendarService.getAvailableSlots(queryParamsDto); |
||||
} |
||||
} |
@ -0,0 +1,48 @@ |
||||
import { Expose, Transform } from 'class-transformer'; |
||||
import { IsArray, IsDateString, IsEnum, MaxLength } from 'class-validator'; |
||||
|
||||
export enum ProductType { |
||||
SolarPanels = 'SolarPanels', |
||||
Heatpumps = 'Heatpumps', |
||||
} |
||||
|
||||
export enum Language { |
||||
German = 'German', |
||||
English = 'English', |
||||
} |
||||
|
||||
export enum CustomerRating { |
||||
Gold = 'Gold', |
||||
Silver = 'Silver', |
||||
Bronze = 'Bronze', |
||||
} |
||||
|
||||
export class QueryParamsDto { |
||||
@MaxLength(10) |
||||
@IsDateString({ strict: true }) |
||||
public date!: string; |
||||
|
||||
@IsArray() |
||||
@IsEnum(ProductType, { each: true }) |
||||
public products!: ProductType[]; |
||||
|
||||
@IsEnum(Language) |
||||
public language!: Language; |
||||
|
||||
@IsEnum(CustomerRating) |
||||
public rating!: CustomerRating; |
||||
} |
||||
|
||||
export class QueryResponseDto { |
||||
@Expose({ name: 'available_count' }) |
||||
availableCount: number; |
||||
|
||||
@Expose({ name: 'start_date' }) |
||||
@Transform(({ value }) => (value as Date).toISOString()) |
||||
startDate: Date; |
||||
|
||||
constructor(availableCount: number, startDate: Date) { |
||||
this.availableCount = availableCount; |
||||
this.startDate = startDate; |
||||
} |
||||
} |
@ -0,0 +1,18 @@ |
||||
import { Test, TestingModule } from '@nestjs/testing'; |
||||
import { CalendarService } from './calendar.service'; |
||||
|
||||
describe('CalendarService', () => { |
||||
let service: CalendarService; |
||||
|
||||
beforeEach(async () => { |
||||
const module: TestingModule = await Test.createTestingModule({ |
||||
providers: [CalendarService], |
||||
}).compile(); |
||||
|
||||
service = module.get<CalendarService>(CalendarService); |
||||
}); |
||||
|
||||
it('should be defined', () => { |
||||
expect(service).toBeDefined(); |
||||
}); |
||||
}); |
@ -0,0 +1,10 @@ |
||||
import { Injectable } from '@nestjs/common'; |
||||
import { QueryParamsDto, QueryResponseDto } from './calendar.dto'; |
||||
|
||||
@Injectable() |
||||
export class CalendarService { |
||||
async getAvailableSlots(queryParamsDto: QueryParamsDto) { |
||||
console.log(queryParamsDto); |
||||
return Promise.resolve([new QueryResponseDto(1, new Date())]); |
||||
} |
||||
} |
Loading…
Reference in new issue