Skip to content

Commit

Permalink
Update GET /trades
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemKolodko committed Nov 3, 2024
1 parent ffc39ed commit 7a4f90a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/dto/trade.dto.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import {ApiProperty} from "@nestjs/swagger";
import {Transform, Type} from "class-transformer";
import {IsString} from "class-validator";
import {IsOptional, IsString} from "class-validator";

export class GetTradesDto {
@ApiProperty({ type: String, required: true })
@Transform((address) => address.value.trim().toLowerCase())
@ApiProperty({ type: String, required: false })
@Transform((address) => address ? address.value.trim().toLowerCase() : address)
@Type(() => String)
@IsString()
tokenAddress: string;
@IsOptional()
tokenAddress?: string;

@ApiProperty({ type: Number, required: false, default: '100' })
// @Transform((limit) => limit.value.toNumber())
@Type(() => String)
@IsString()
@IsOptional()
limit: number;

@ApiProperty({ type: Number, required: false, default: '0' })
// @Transform((offset) => offset.value.toNumber())
@Type(() => String)
@IsString()
@IsOptional()
offset: number;
}
5 changes: 5 additions & 0 deletions src/entities/token.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ApiProperty } from '@nestjs/swagger';
import {Comment} from "./comment.entity";
import {UserAccount} from "./user-account.entity";
import {TokenMetadata} from "../types";
import {Trade} from "./trade.entity";

@Entity({ name: 'tokens' })
export class Token {
Expand Down Expand Up @@ -60,6 +61,10 @@ export class Token {
@JoinTable()
comments: Comment[]

@OneToMany(() => Trade, (trade) => trade.token)
@JoinTable()
trades: Trade[]

@ApiProperty()
@CreateDateColumn({ name: 'createdAt' })
createdAt: Date;
Expand Down
4 changes: 3 additions & 1 deletion src/entities/trade.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export class Trade {
})
user: UserAccount

@ManyToOne(() => Token, (token) => token.comments)
@ManyToOne(() => Token, (token) => token.trades, {
eager: true
})
token: Token

@ApiProperty()
Expand Down

0 comments on commit 7a4f90a

Please sign in to comment.