Skip to content

Instantly share code, notes, and snippets.

@nishabe
Last active January 7, 2021 15:10
Show Gist options
  • Save nishabe/81e382ffa1a42b7f71a14fecb9f12f19 to your computer and use it in GitHub Desktop.
Save nishabe/81e382ffa1a42b7f71a14fecb9f12f19 to your computer and use it in GitHub Desktop.
app.controller.ts
import { Controller, Get, HttpException, Query } from '@nestjs/common';
import { AppService } from './app.service';
import { StudentService } from './student/student.service';
@Controller('student')
export class AppController {
constructor(
private readonly appService: AppService,
private readonly studentService: StudentService,
) {}
@Get()
getHello(): string {
return this.appService.getHello();
}
@Get('/gpa')
async getStudentGpa(
@Query('firstName') firstName: string,
@Query('lastName') lastName: string,
): Promise<number> {
if (!firstName || !lastName) {
throw new HttpException('Incomplete student information', 400);
}
return await this.studentService.getGpa(firstName, lastName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment