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') |
@Controller('seasons') |
||||
export class SeasonsController { |
export class SeasonsController { |
||||
|
constructor( |
||||
|
private seasonsService: SeasonsService |
||||
|
) {} |
||||
|
|
||||
@Get() |
@Get() |
||||
findAll(): string { |
findAll() { |
||||
return '' |
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 { Injectable } from '@nestjs/common'; |
||||
import { InjectModel } from '@nestjs/sequelize'; |
import { InjectModel } from '@nestjs/sequelize'; |
||||
import { Season } from './season.model'; |
import { Season } from './season.model'; |
||||
//import { SeasonStanding } from 'src/season-standings/season-standing.model';
|
import { SeasonStanding } from 'src/season-standings/season-standing.model'; |
||||
//import { Race } from 'src/races/race.model';
|
import { Race } from 'src/races/race.model'; |
||||
|
import { Sequelize } from 'sequelize-typescript'; |
||||
|
|
||||
@Injectable() |
@Injectable() |
||||
export class SeasonsService { |
export class SeasonsService { |
||||
constructor( |
constructor( |
||||
@InjectModel(Season) private seasonModel: typeof Season, |
@InjectModel(Season) private seasonModel: typeof Season, |
||||
|
private sequelize: Sequelize |
||||
) |
) |
||||
{} |
{} |
||||
|
|
||||
async findAll() { |
async findAll() { |
||||
//return this.seasonModel.findAll();
|
return this.seasonModel.findAll(); |
||||
} |
} |
||||
|
|
||||
async findOne(id: number) { |
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