add search #619
This commit is contained in:
parent
f8a91f60ba
commit
aa3bbac5a5
1 changed files with 27 additions and 14 deletions
|
|
@ -12,6 +12,7 @@ import {
|
||||||
SuccessResponse,
|
SuccessResponse,
|
||||||
Response,
|
Response,
|
||||||
Get,
|
Get,
|
||||||
|
Query,
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
|
|
@ -21,6 +22,7 @@ import { Not } from "typeorm";
|
||||||
import { CreatePortfolio, Portfolio } from "../entities/Portfolio";
|
import { CreatePortfolio, Portfolio } from "../entities/Portfolio";
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
import { setLogDataDiff } from "../interfaces/utils";
|
import { setLogDataDiff } from "../interfaces/utils";
|
||||||
|
import { Brackets } from "typeorm";
|
||||||
|
|
||||||
@Route("api/v1/development/portfolio")
|
@Route("api/v1/development/portfolio")
|
||||||
@Tags("Portfolio")
|
@Tags("Portfolio")
|
||||||
|
|
@ -40,20 +42,31 @@ export class PortfolioController extends Controller {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Get()
|
@Get()
|
||||||
async GetResult(@Request() request: RequestWithUser) {
|
async GetResult(@Request() request: RequestWithUser, @Query("keyword") keyword?: string) {
|
||||||
const _portfolio = await this.portfolioRepository.find({
|
const _portfolio = await this.portfolioRepository
|
||||||
where: { createdUserId: request.user.sub },
|
.createQueryBuilder("portfolio")
|
||||||
select: [
|
.select([
|
||||||
"id",
|
"portfolio.id",
|
||||||
"name",
|
"portfolio.name",
|
||||||
"detail",
|
"portfolio.detail",
|
||||||
"createdAt",
|
"portfolio.createdAt",
|
||||||
"lastUpdatedAt",
|
"portfolio.lastUpdatedAt",
|
||||||
"createdFullName",
|
"portfolio.createdFullName",
|
||||||
"lastUpdateFullName",
|
"portfolio.lastUpdateFullName",
|
||||||
],
|
])
|
||||||
order: { name: "ASC" },
|
.where("portfolio.createdUserId = :userId", { userId: request.user.sub })
|
||||||
});
|
.andWhere(
|
||||||
|
new Brackets((qb) => {
|
||||||
|
qb.where(keyword != null && keyword != "" ? "portfolio.name LIKE :keyword" : "1=1", {
|
||||||
|
keyword: `%${keyword}%`,
|
||||||
|
}).orWhere(keyword != null && keyword != "" ? "portfolio.detail LIKE :keyword" : "1=1", {
|
||||||
|
keyword: `%${keyword}%`,
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.getMany();
|
||||||
|
|
||||||
|
|
||||||
return new HttpSuccess(_portfolio);
|
return new HttpSuccess(_portfolio);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue