Skip to content

Commit c98fdb1

Browse files
Mikadowsangristan
authored andcommitted
feat: add GET /benchmarks
1 parent d48e638 commit c98fdb1

File tree

6 files changed

+43
-8
lines changed

6 files changed

+43
-8
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"build": "nest build",
1414
"start": "nest start",
1515
"dev": "nest start --watch",
16+
"start:dev": "nest start --watch",
1617
"start:debug": "nest start --debug --watch",
1718
"start:prod": "node dist/main",
1819
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",

src/benchmarks/benchmark.controller.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Body, Controller, Post, Request, UseGuards } from '@nestjs/common';
1+
import { Body, Controller, Get, Post, Request, UseGuards } from '@nestjs/common';
22
import { CreateBenchmarkDto } from 'src/benchmarks/dto/create-benchmark.dto';
33
import { BenchmarkService } from 'src/benchmarks/benchmark.service';
44
import { Benchmark } from './benchmark.entity';
@@ -18,8 +18,13 @@ export class BenchmarkController {
1818
@Body()
1919
benchmark: CreateBenchmarkDto
2020
) : Promise<Benchmark>{
21-
console.log(benchmark);
2221
return this.benchmarkService.create(benchmark, req.user);
2322
}
2423

24+
@Get()
25+
async getEveryBenchMarks() : Promise<Benchmark[]> {
26+
return this.benchmarkService.getAll();
27+
}
28+
29+
2530
}

src/benchmarks/benchmark.entity.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export class Benchmark extends BaseEntity {
2323
subject: string;
2424

2525
@ApiProperty()
26-
@Column()
27-
giturl: string;
26+
@Column('text', { nullable: true })
27+
gitUrl?: string;
2828

2929
@ApiProperty()
3030
@CreateDateColumn()

src/benchmarks/benchmark.service.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
import { Injectable } from '@nestjs/common';
2+
import { Repository } from 'typeorm';
3+
import { InjectRepository } from '@nestjs/typeorm';
24
import { CreateBenchmarkDto } from './dto/create-benchmark.dto';
35
import { Benchmark } from './benchmark.entity';
46
import { User } from '../users/user.entity';
57

68
@Injectable()
79
export class BenchmarkService {
10+
constructor(
11+
@InjectRepository(Benchmark)
12+
private benchmarkRepository: Repository<Benchmark>,
13+
) {
14+
15+
}
816

917
async create(benchmarkData: CreateBenchmarkDto, user: User): Promise<Benchmark> {
1018
const benchmark = new Benchmark(benchmarkData);
1119
benchmark.creator = user;
1220
return benchmark.save();
1321
}
22+
23+
async getAll() : Promise<Benchmark[]> {
24+
return this.benchmarkRepository.find({});
25+
}
1426
}

src/benchmarks/dto/create-benchmark.dto.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { IsNotEmpty, IsString } from 'class-validator';
2-
import { ApiProperty } from '@nestjs/swagger';
1+
import { IsNotEmpty, IsOptional, IsString } from 'class-validator';
2+
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
33

44
export class CreateBenchmarkDto {
55
@IsNotEmpty()
@@ -12,10 +12,11 @@ export class CreateBenchmarkDto {
1212
@ApiProperty()
1313
subject: string;
1414

15+
@IsOptional()
1516
@IsNotEmpty()
1617
@IsString()
17-
@ApiProperty()
18-
giturl: string;
18+
@ApiPropertyOptional()
19+
giturl?: string;
1920

2021
@IsNotEmpty()
2122
@IsString()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {MigrationInterface, QueryRunner} from "typeorm";
2+
3+
export class AddBenchmarkGitUrlNullable1621805244904 implements MigrationInterface {
4+
name = 'AddBenchmarkGitUrlNullable1621805244904'
5+
6+
public async up(queryRunner: QueryRunner): Promise<void> {
7+
await queryRunner.query(`ALTER TABLE "benchmarks" DROP COLUMN "gitUrl"`);
8+
await queryRunner.query(`ALTER TABLE "benchmarks" ADD "gitUrl" text`);
9+
}
10+
11+
public async down(queryRunner: QueryRunner): Promise<void> {
12+
await queryRunner.query(`ALTER TABLE "benchmarks" DROP COLUMN "gitUrl"`);
13+
await queryRunner.query(`ALTER TABLE "benchmarks" ADD "gitUrl" character varying NOT NULL`);
14+
}
15+
16+
}

0 commit comments

Comments
 (0)