Skip to content

Commit 1088382

Browse files
committed
style: reformat
1 parent 12f9ba2 commit 1088382

6 files changed

Lines changed: 177 additions & 169 deletions

File tree

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,49 @@
1-
import { Body, Controller, Get, Param, Post, Request, UseGuards } from '@nestjs/common';
2-
import { CreateBenchmarkDto } from 'src/benchmarks/dto/create-benchmark.dto';
3-
import { BenchmarkService } from 'src/benchmarks/benchmark.service';
4-
import { Benchmark } from './benchmark.entity';
5-
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
6-
import { ValidatedJWTReq } from '../auth/dto/validated-jwt-req';
7-
import { ApiOkResponse, ApiOperation } from '@nestjs/swagger';
8-
import { BenchmarkIdDto } from './dto/benchmarkId.dto';
9-
10-
11-
@Controller('benchmarks')
12-
export class BenchmarkController {
13-
constructor(private readonly benchmarkService: BenchmarkService) {
14-
}
15-
16-
@ApiOperation({ summary: 'Create a benchmark' })
17-
@ApiOkResponse({type: Benchmark, description: 'Created benchmark'})
18-
19-
@Post()
20-
@UseGuards(JwtAuthGuard)
21-
async createBenchmark(
22-
@Request() req: ValidatedJWTReq,
23-
@Body()
24-
benchmark: CreateBenchmarkDto
25-
) : Promise<Benchmark>{
26-
return this.benchmarkService.create(benchmark, req.user);
27-
}
28-
29-
@ApiOperation({ summary: 'Get all benchmarks' })
30-
@ApiOkResponse({type: [Benchmark], description: 'Array of benchmarks'})
31-
@Get()
32-
async getEveryBenchMarks() : Promise<Benchmark[]> {
33-
return this.benchmarkService.getAll();
34-
}
35-
36-
@ApiOperation({ summary: 'Get benchmark by id' })
37-
@ApiOkResponse({type: Benchmark, description: 'Requested benchmark'})
38-
@Get(':id')
39-
async getBenchmarkById(@Param() id: BenchmarkIdDto): Promise<Benchmark | undefined> {
40-
return this.benchmarkService.findOne(id);
41-
}
42-
43-
44-
}
1+
import {
2+
Body,
3+
Controller,
4+
Get,
5+
Param,
6+
Post,
7+
Request,
8+
UseGuards,
9+
} from '@nestjs/common';
10+
import { ApiOkResponse, ApiOperation } from '@nestjs/swagger';
11+
import { BenchmarkService } from 'src/benchmarks/benchmark.service';
12+
import { CreateBenchmarkDto } from 'src/benchmarks/dto/create-benchmark.dto';
13+
import { ValidatedJWTReq } from '../auth/dto/validated-jwt-req';
14+
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
15+
import { Benchmark } from './benchmark.entity';
16+
import { BenchmarkIdDto } from './dto/benchmarkId.dto';
17+
18+
@Controller('benchmarks')
19+
export class BenchmarkController {
20+
constructor(private readonly benchmarkService: BenchmarkService) {}
21+
22+
@ApiOperation({ summary: 'Create a benchmark' })
23+
@ApiOkResponse({ type: Benchmark, description: 'Created benchmark' })
24+
@Post()
25+
@UseGuards(JwtAuthGuard)
26+
async createBenchmark(
27+
@Request() req: ValidatedJWTReq,
28+
@Body()
29+
benchmark: CreateBenchmarkDto,
30+
): Promise<Benchmark> {
31+
return this.benchmarkService.create(benchmark, req.user);
32+
}
33+
34+
@ApiOperation({ summary: 'Get all benchmarks' })
35+
@ApiOkResponse({ type: [Benchmark], description: 'Array of benchmarks' })
36+
@Get()
37+
async getEveryBenchMarks(): Promise<Benchmark[]> {
38+
return this.benchmarkService.getAll();
39+
}
40+
41+
@ApiOperation({ summary: 'Get benchmark by id' })
42+
@ApiOkResponse({ type: Benchmark, description: 'Requested benchmark' })
43+
@Get(':id')
44+
async getBenchmarkById(
45+
@Param() id: BenchmarkIdDto,
46+
): Promise<Benchmark | undefined> {
47+
return this.benchmarkService.findOne(id);
48+
}
49+
}

src/benchmarks/benchmark.entity.ts

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,47 @@
1-
/* eslint-disable @typescript-eslint/no-unused-vars */
2-
import { BaseEntity, Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
3-
import { ApiProperty } from '@nestjs/swagger';
4-
import { User } from 'src/users/user.entity';
5-
6-
@Entity('benchmarks')
7-
export class Benchmark extends BaseEntity {
8-
constructor(partial: Partial<Benchmark>) {
9-
super();
10-
Object.assign(this, partial);
11-
}
12-
13-
@ApiProperty()
14-
@PrimaryGeneratedColumn('uuid')
15-
id: string;
16-
17-
@ApiProperty()
18-
@Column()
19-
title: string;
20-
21-
@ApiProperty()
22-
@Column()
23-
subject: string;
24-
25-
@ApiProperty()
26-
@Column('text', { nullable: true })
27-
gitUrl?: string;
28-
29-
@ApiProperty()
30-
@CreateDateColumn()
31-
createdAt: Date;
32-
33-
@ApiProperty()
34-
@Column()
35-
difficulty: string;
36-
37-
@ManyToOne((type) => User, (user) => user.benchmarks, {eager: true})
38-
@ApiProperty({type: () => User})
39-
creator: User;
40-
41-
}
1+
/* eslint-disable @typescript-eslint/no-unused-vars */
2+
import {
3+
BaseEntity,
4+
Column,
5+
CreateDateColumn,
6+
Entity,
7+
ManyToOne,
8+
PrimaryGeneratedColumn,
9+
} from 'typeorm';
10+
import { ApiProperty } from '@nestjs/swagger';
11+
import { User } from 'src/users/user.entity';
12+
13+
@Entity('benchmarks')
14+
export class Benchmark extends BaseEntity {
15+
constructor(partial: Partial<Benchmark>) {
16+
super();
17+
Object.assign(this, partial);
18+
}
19+
20+
@ApiProperty()
21+
@PrimaryGeneratedColumn('uuid')
22+
id: string;
23+
24+
@ApiProperty()
25+
@Column()
26+
title: string;
27+
28+
@ApiProperty()
29+
@Column()
30+
subject: string;
31+
32+
@ApiProperty()
33+
@Column('text', { nullable: true })
34+
gitUrl?: string;
35+
36+
@ApiProperty()
37+
@CreateDateColumn()
38+
createdAt: Date;
39+
40+
@ApiProperty()
41+
@Column()
42+
difficulty: string;
43+
44+
@ManyToOne((type) => User, (user) => user.benchmarks, { eager: true })
45+
@ApiProperty({ type: () => User })
46+
creator: User;
47+
}

src/benchmarks/benchmark.module.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
import {
2-
Module,
3-
forwardRef,
4-
} from '@nestjs/common';
5-
import { UsersModule } from 'src/users/users.module';
6-
import { TypeOrmModule } from '@nestjs/typeorm';
7-
import { Benchmark } from './benchmark.entity';
8-
import { BenchmarkService } from './benchmark.service';
9-
import { BenchmarkController } from './benchmark.controller';
10-
11-
@Module({
12-
imports: [TypeOrmModule.forFeature([Benchmark]),
13-
forwardRef(() => UsersModule),
14-
],
15-
providers: [BenchmarkService],
16-
controllers: [BenchmarkController],
17-
exports: [BenchmarkService],
18-
19-
})
20-
export class BenchmarkModule {
21-
}
1+
import { Module, forwardRef } from '@nestjs/common';
2+
import { UsersModule } from 'src/users/users.module';
3+
import { TypeOrmModule } from '@nestjs/typeorm';
4+
import { Benchmark } from './benchmark.entity';
5+
import { BenchmarkService } from './benchmark.service';
6+
import { BenchmarkController } from './benchmark.controller';
7+
8+
@Module({
9+
imports: [
10+
TypeOrmModule.forFeature([Benchmark]),
11+
forwardRef(() => UsersModule),
12+
],
13+
providers: [BenchmarkService],
14+
controllers: [BenchmarkController],
15+
exports: [BenchmarkService],
16+
})
17+
export class BenchmarkModule {}
Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1-
import { Injectable } from '@nestjs/common';
2-
import { Repository } from 'typeorm';
3-
import { InjectRepository } from '@nestjs/typeorm';
4-
import { CreateBenchmarkDto } from './dto/create-benchmark.dto';
5-
import { Benchmark } from './benchmark.entity';
6-
import { User } from '../users/user.entity';
7-
8-
@Injectable()
9-
export class BenchmarkService {
10-
constructor(
11-
@InjectRepository(Benchmark)
12-
private benchmarkRepository: Repository<Benchmark>,
13-
) {
14-
15-
}
16-
17-
async create(benchmarkData: CreateBenchmarkDto, user: User): Promise<Benchmark> {
18-
const benchmark = new Benchmark(benchmarkData);
19-
benchmark.creator = user;
20-
return benchmark.save();
21-
}
22-
23-
async getAll() : Promise<Benchmark[]> {
24-
return this.benchmarkRepository.find({});
25-
}
26-
27-
async findOne(id: { id: string }): Promise<Benchmark | undefined> {
28-
return this.benchmarkRepository.findOne(id);
29-
}
30-
}
1+
import { Injectable } from '@nestjs/common';
2+
import { Repository } from 'typeorm';
3+
import { InjectRepository } from '@nestjs/typeorm';
4+
import { CreateBenchmarkDto } from './dto/create-benchmark.dto';
5+
import { Benchmark } from './benchmark.entity';
6+
import { User } from '../users/user.entity';
7+
8+
@Injectable()
9+
export class BenchmarkService {
10+
constructor(
11+
@InjectRepository(Benchmark)
12+
private benchmarkRepository: Repository<Benchmark>,
13+
) {}
14+
15+
async create(
16+
benchmarkData: CreateBenchmarkDto,
17+
user: User,
18+
): Promise<Benchmark> {
19+
const benchmark = new Benchmark(benchmarkData);
20+
benchmark.creator = user;
21+
return benchmark.save();
22+
}
23+
24+
async getAll(): Promise<Benchmark[]> {
25+
return this.benchmarkRepository.find({});
26+
}
27+
28+
async findOne(id: { id: string }): Promise<Benchmark | undefined> {
29+
return this.benchmarkRepository.findOne(id);
30+
}
31+
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { IsUUID } from 'class-validator';
2-
import { ApiProperty } from '@nestjs/swagger';
3-
4-
export class BenchmarkIdDto {
5-
@IsUUID('all')
6-
@ApiProperty()
7-
id: string;
8-
}
1+
import { IsUUID } from 'class-validator';
2+
import { ApiProperty } from '@nestjs/swagger';
3+
4+
export class BenchmarkIdDto {
5+
@IsUUID('all')
6+
@ApiProperty()
7+
id: string;
8+
}
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import { IsNotEmpty, IsOptional, IsString } from 'class-validator';
2-
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
3-
4-
export class CreateBenchmarkDto {
5-
@IsNotEmpty()
6-
@IsString()
7-
@ApiProperty()
8-
title: string;
9-
10-
@IsNotEmpty()
11-
@IsString()
12-
@ApiProperty()
13-
subject: string;
14-
15-
@IsOptional()
16-
@IsNotEmpty()
17-
@IsString()
18-
@ApiPropertyOptional()
19-
giturl?: string;
20-
21-
@IsNotEmpty()
22-
@IsString()
23-
@ApiProperty()
24-
difficulty: string;
25-
}
1+
import { IsNotEmpty, IsOptional, IsString } from 'class-validator';
2+
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
3+
4+
export class CreateBenchmarkDto {
5+
@IsNotEmpty()
6+
@IsString()
7+
@ApiProperty()
8+
title: string;
9+
10+
@IsNotEmpty()
11+
@IsString()
12+
@ApiProperty()
13+
subject: string;
14+
15+
@IsOptional()
16+
@IsNotEmpty()
17+
@IsString()
18+
@ApiPropertyOptional()
19+
giturl?: string;
20+
21+
@IsNotEmpty()
22+
@IsString()
23+
@ApiProperty()
24+
difficulty: string;
25+
}

0 commit comments

Comments
 (0)