-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from Boost-Coder/feature/Transaction-#89
[#89] 트랜잭션 적용 및 리펙토링
- Loading branch information
Showing
20 changed files
with
190 additions
and
175 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,69 +1,23 @@ | ||
import { Inject, Injectable, Scope } from '@nestjs/common'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { DataSource } from 'typeorm'; | ||
import { REQUEST } from '@nestjs/core'; | ||
import { Algorithm } from '../../Entity/algorithm'; | ||
import { RankListOptionDto } from '../dto/rank-list-option.dto'; | ||
import { User } from '../../Entity/user'; | ||
import { PointFindDto } from '../dto/rank-find.dto'; | ||
import { StatRepository } from '../../utils/stat.repository'; | ||
|
||
@Injectable({ scope: Scope.REQUEST }) | ||
@Injectable() | ||
export class AlgorithmRepository extends StatRepository { | ||
constructor(dataSource: DataSource, @Inject(REQUEST) req: Request) { | ||
super(dataSource, req, Algorithm); | ||
} | ||
|
||
async save(algorithm: Algorithm) { | ||
await this.repository.save(algorithm); | ||
constructor(dataSource: DataSource) { | ||
super(dataSource, Algorithm); | ||
} | ||
|
||
async findOneById(userId: string) { | ||
return await this.repository.findOneBy({ userId: userId }); | ||
} | ||
public async findIndividualAlgorithmRank( | ||
userId: string, | ||
options: PointFindDto, | ||
) { | ||
const queryBuilder = this.repository | ||
.createQueryBuilder() | ||
.select(['b.rank', 'b.user_id', 'b.major']) | ||
.distinct(true) | ||
.from((sub) => { | ||
return sub | ||
.select('RANK() OVER (ORDER BY a.point DESC)', 'rank') | ||
.addSelect('a.user_id', 'user_id') | ||
.addSelect('a.point', 'point') | ||
.from(Algorithm, 'a') | ||
.innerJoin(User, 'u', 'a.user_id = u.user_id') | ||
.addSelect('u.major', 'major') | ||
.where(this.createClassificationOption(options)); | ||
}, 'b') | ||
.where(`b.user_id = '${userId}'`); | ||
|
||
return await queryBuilder.getRawOne(); | ||
} | ||
|
||
createCursorOption(options: RankListOptionDto) { | ||
if (!options.cursorPoint && !options.cursorUserId) { | ||
return 'b.point > -1'; | ||
} else { | ||
return `b.point < ${options.cursorPoint} or b.point = ${options.cursorPoint} AND b.user_id > '${options.cursorUserId}'`; | ||
} | ||
} | ||
|
||
createClassificationOption(options: PointFindDto) { | ||
if (options.major != null) { | ||
return `u.major like '${options.major}'`; | ||
} else { | ||
return `u.id > 0`; | ||
} | ||
return await this.findOneBy({ userId: userId }); | ||
} | ||
|
||
async update(userId: string, algorithm: Algorithm) { | ||
await this.repository.update({ userId: userId }, algorithm); | ||
async updateAlgorithm(userId: string, algorithm: Algorithm) { | ||
await this.update({ userId: userId }, algorithm); | ||
} | ||
|
||
async delete(userId: string) { | ||
await this.repository.delete({ userId: userId }); | ||
async deleteAlgorithm(userId: string) { | ||
await this.delete({ userId: userId }); | ||
} | ||
} |
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,19 @@ | ||
import { DataSource } from 'typeorm'; | ||
import { Inject } from '@nestjs/common'; | ||
import { REQUEST } from '@nestjs/core'; | ||
import { TotalPoint } from '../../Entity/totalPoint'; | ||
import { StatRepository } from '../../utils/stat.repository'; | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class TotalRepository extends StatRepository { | ||
constructor(dataSource: DataSource, @Inject(REQUEST) req: Request) { | ||
super(dataSource, req, TotalPoint); | ||
constructor(private dataSource: DataSource) { | ||
super(dataSource, TotalPoint); | ||
} | ||
|
||
async findOneById(userId: string) { | ||
return await this.repository.findOneBy({ userId: userId }); | ||
return await this.findOneBy({ userId: userId }); | ||
} | ||
|
||
async update(total: TotalPoint, userId: string) { | ||
return await this.repository.update({ userId: userId }, total); | ||
} | ||
|
||
async save(total: TotalPoint) { | ||
return await this.repository.save(total); | ||
async updateTotal(total: TotalPoint, userId: string) { | ||
return await this.update({ userId: userId }, total); | ||
} | ||
} |
Oops, something went wrong.