This commit is contained in:
AdisakKanthawilang 2024-09-30 17:01:31 +07:00
parent aa3bbac5a5
commit a5b57f287d

View file

@ -42,31 +42,44 @@ export class PortfolioController extends Controller {
*
*/
@Get()
async GetResult(@Request() request: RequestWithUser, @Query("keyword") keyword?: string) {
const _portfolio = await this.portfolioRepository
.createQueryBuilder("portfolio")
.select([
"portfolio.id",
"portfolio.name",
"portfolio.detail",
"portfolio.createdAt",
"portfolio.lastUpdatedAt",
"portfolio.createdFullName",
"portfolio.lastUpdateFullName",
])
.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();
async GetResult(@Request() request: RequestWithUser) {
const _portfolio = await this.portfolioRepository.find({
where: { createdUserId: request.user.sub },
select: [
"id",
"name",
"detail",
"createdAt",
"lastUpdatedAt",
"createdFullName",
"lastUpdateFullName",
],
order: { name: "ASC" },
});
// const _portfolio = await this.portfolioRepository
// .createQueryBuilder("portfolio")
// .select([
// "portfolio.id",
// "portfolio.name",
// "portfolio.detail",
// "portfolio.createdAt",
// "portfolio.lastUpdatedAt",
// "portfolio.createdFullName",
// "portfolio.lastUpdateFullName",
// ])
// .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);
}