scaffolding for calendar/query endpoint

main
Inga 🏳‍🌈 6 days ago
parent 81da0f2766
commit 7af426c262
  1. 9
      service/src/app.module.ts
  2. 2
      service/src/app/app.controller.spec.ts
  3. 0
      service/src/app/app.controller.ts
  4. 2
      service/src/app/app.service.ts
  5. 20
      service/src/calendar/calendar.controller.spec.ts
  6. 24
      service/src/calendar/calendar.controller.ts
  7. 48
      service/src/calendar/calendar.dto.ts
  8. 18
      service/src/calendar/calendar.service.spec.ts
  9. 10
      service/src/calendar/calendar.service.ts

@ -1,12 +1,14 @@
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AppController } from './app/app.controller';
import { AppService } from './app/app.service';
import { createDbClient } from './db';
import { CalendarController } from './calendar/calendar.controller';
import { CalendarService } from './calendar/calendar.service';
@Module({
imports: [ConfigModule.forRoot({ ignoreEnvFile: true })],
controllers: [AppController],
controllers: [AppController, CalendarController],
providers: [
{
provide: 'dbClient',
@ -18,6 +20,7 @@ import { createDbClient } from './db';
inject: [ConfigService],
},
AppService,
CalendarService,
],
})
// eslint-disable-next-line @typescript-eslint/no-extraneous-class

@ -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…
Cancel
Save