2 changed files with 40 additions and 7 deletions
@ -1,9 +1,26 @@ |
|||
import { Controller, Get } from '@nestjs/common'; |
|||
import { Body, Controller, Get, Param, Post } from '@nestjs/common'; |
|||
import { SeasonsService } from './seasons.service'; |
|||
import { get } from 'http'; |
|||
|
|||
@Controller('seasons') |
|||
export class SeasonsController { |
|||
constructor( |
|||
private seasonsService: SeasonsService |
|||
) {} |
|||
|
|||
@Get() |
|||
findAll(): string { |
|||
return '' |
|||
findAll() { |
|||
return this.seasonsService.findAll(); |
|||
} |
|||
|
|||
@Get(':id') |
|||
findOne(@Param() params: any) { |
|||
return this.seasonsService.findOne(params.id); |
|||
} |
|||
|
|||
@Post() |
|||
create(@Body() body: any) { |
|||
return this.seasonsService.create(body.title, body.subTitle, body.startingDate); |
|||
} |
|||
|
|||
} |
|||
|
|||
@ -1,21 +1,37 @@ |
|||
import { Injectable } from '@nestjs/common'; |
|||
import { InjectModel } from '@nestjs/sequelize'; |
|||
import { Season } from './season.model'; |
|||
//import { SeasonStanding } from 'src/season-standings/season-standing.model';
|
|||
//import { Race } from 'src/races/race.model';
|
|||
import { SeasonStanding } from 'src/season-standings/season-standing.model'; |
|||
import { Race } from 'src/races/race.model'; |
|||
import { Sequelize } from 'sequelize-typescript'; |
|||
|
|||
@Injectable() |
|||
export class SeasonsService { |
|||
constructor( |
|||
@InjectModel(Season) private seasonModel: typeof Season, |
|||
private sequelize: Sequelize |
|||
) |
|||
{} |
|||
|
|||
async findAll() { |
|||
//return this.seasonModel.findAll();
|
|||
return this.seasonModel.findAll(); |
|||
} |
|||
|
|||
async findOne(id: number) { |
|||
//return this.seasonModel.findOne({ where: {id: id}}/*, include:[Race, SeasonStanding] }*/)
|
|||
return this.seasonModel.findOne({ where: {id: id} , include:[Race, SeasonStanding] }) |
|||
} |
|||
|
|||
async create(title: string, subTitle: string, startingDate: Date) { |
|||
try { |
|||
await this.sequelize.transaction( async t => { |
|||
const transactionHost = { transaction: t }; |
|||
await this.seasonModel.create( |
|||
{ title: title, subTitle: subTitle, startingDate: startingDate }, |
|||
transactionHost |
|||
); |
|||
}); |
|||
} catch (error) { |
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue