-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e98b455
commit 586cccc
Showing
38 changed files
with
1,216 additions
and
1,130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
import { Asset } from 'src/asset/asset.entity'; | ||
import { User } from 'src/auth/user.entity'; | ||
import { | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
Column, | ||
JoinColumn, | ||
OneToOne, | ||
OneToMany, | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
Column, | ||
JoinColumn, | ||
OneToOne, | ||
OneToMany, | ||
} from 'typeorm'; | ||
|
||
@Entity() | ||
export class Account { | ||
@PrimaryGeneratedColumn() | ||
accountId: string; | ||
@PrimaryGeneratedColumn() | ||
accountId: string; | ||
|
||
@Column('double') | ||
@Column('double') | ||
KRW: number; | ||
|
||
@Column('double') | ||
@Column('double') | ||
USDT: number; | ||
|
||
@Column('double') | ||
@Column('double') | ||
BTC: number; | ||
|
||
@OneToOne(() => User, user => user.account) | ||
@OneToOne(() => User, (user) => user.account) | ||
@JoinColumn() | ||
user: User; | ||
|
||
@OneToMany(() => Asset, (asset) => asset.account, { | ||
cascade: true, | ||
onDelete: 'CASCADE', | ||
}) | ||
assets: Asset[]; | ||
@OneToMany(() => Asset, (asset) => asset.account, { | ||
cascade: true, | ||
onDelete: 'CASCADE', | ||
}) | ||
assets: Asset[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
import { DataSource, Repository } from 'typeorm'; | ||
import { Asset } from './asset.entity'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { INFINITE } from 'common/upbit'; | ||
|
||
@Injectable() | ||
export class AssetRepository extends Repository<Asset> { | ||
constructor(private dataSource: DataSource) { | ||
super(Asset, dataSource.createEntityManager()); | ||
} | ||
async createAsset(buyDto, currentCoinPrice, account, queryRunner){ | ||
try{ | ||
const {typeReceived, receivedPrice, receivedAmount} = buyDto | ||
const asset = new Asset(); | ||
asset.assetName = typeReceived; | ||
asset.price = currentCoinPrice; | ||
asset.quantity = receivedAmount; | ||
asset.account = account; | ||
async createAsset(buyDto, currentCoinPrice, account, queryRunner) { | ||
try { | ||
const { typeReceived, receivedAmount } = buyDto; | ||
const asset = new Asset(); | ||
asset.assetName = typeReceived; | ||
asset.price = currentCoinPrice; | ||
asset.quantity = receivedAmount; | ||
asset.account = account; | ||
|
||
await queryRunner.manager.save(Asset,asset); | ||
}catch(e){console.log(e)} | ||
await queryRunner.manager.save(Asset, asset); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,38 @@ | ||
import { | ||
CanActivate, | ||
ExecutionContext, | ||
Injectable, | ||
UnauthorizedException, | ||
} from '@nestjs/common'; | ||
import { JwtService } from '@nestjs/jwt'; | ||
import { jwtConstants } from './constants'; | ||
import { Request } from 'express'; | ||
|
||
@Injectable() | ||
export class AuthGuard implements CanActivate { | ||
constructor(private jwtService: JwtService) {} | ||
|
||
async canActivate(context: ExecutionContext): Promise<boolean> { | ||
const request = context.switchToHttp().getRequest(); | ||
const token = this.extractTokenFromHeader(request); | ||
if (!token) { | ||
throw new UnauthorizedException(); | ||
} | ||
try { | ||
const payload = await this.jwtService.verifyAsync( | ||
token, | ||
{ | ||
secret: jwtConstants.secret | ||
} | ||
); | ||
// 💡 We're assigning the payload to the request object here | ||
// so that we can access it in our route handlers | ||
request['user'] = payload; | ||
} catch { | ||
throw new UnauthorizedException(); | ||
} | ||
return true; | ||
} | ||
|
||
private extractTokenFromHeader(request: Request): string | undefined { | ||
const [type, token] = request.headers.authorization?.split(' ') ?? []; | ||
return type === 'Bearer' ? token : undefined; | ||
} | ||
import { | ||
CanActivate, | ||
ExecutionContext, | ||
Injectable, | ||
UnauthorizedException, | ||
} from '@nestjs/common'; | ||
import { JwtService } from '@nestjs/jwt'; | ||
import { jwtConstants } from './constants'; | ||
import { Request } from 'express'; | ||
|
||
@Injectable() | ||
export class AuthGuard implements CanActivate { | ||
constructor(private jwtService: JwtService) {} | ||
|
||
async canActivate(context: ExecutionContext): Promise<boolean> { | ||
const request = context.switchToHttp().getRequest(); | ||
const token = this.extractTokenFromHeader(request); | ||
if (!token) { | ||
throw new UnauthorizedException(); | ||
} | ||
|
||
try { | ||
const payload = await this.jwtService.verifyAsync(token, { | ||
secret: jwtConstants.secret, | ||
}); | ||
// 💡 We're assigning the payload to the request object here | ||
// so that we can access it in our route handlers | ||
request['user'] = payload; | ||
} catch { | ||
throw new UnauthorizedException(); | ||
} | ||
return true; | ||
} | ||
|
||
private extractTokenFromHeader(request: Request): string | undefined { | ||
const [type, token] = request.headers.authorization?.split(' ') ?? []; | ||
return type === 'Bearer' ? token : undefined; | ||
} | ||
} |
Oops, something went wrong.