Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge dev into main #539

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 23 additions & 26 deletions src/controllers/Perfume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ const LikePerfume: LikePerfumeService = new LikePerfumeService();
* description: Perfume not found
* x-swagger-router-controller: Perfume
* */
const getPerfume: RequestHandler = (
const getPerfume: RequestHandler = async (
req: Request | any,
res: Response,
next: NextFunction
): any => {
) => {
const perfumeIdx: number = req.params['perfumeIdx'];
if (isNaN(perfumeIdx)) {
next();
Expand All @@ -109,30 +109,27 @@ const getPerfume: RequestHandler = (
req.params
)})`
);
Promise.all([
Perfume.getPerfumeById(perfumeIdx, loginUserIdx),
SearchHistory.recordInquire(
loginUserIdx,
perfumeIdx,
'' /* 향후 경로가 다양화 되면 경로 기록 용 */
),
])
.then(([result, _]: [PerfumeIntegralDTO, void]) => {
return PerfumeDetailResponse.createByPerfumeIntegralDTO(result);
})
.then((response: PerfumeDetailResponse) => {
LoggerHelper.logTruncated(
logger.debug,
`${LOG_TAG} getPerfume's result = ${response}`
);
res.status(StatusCode.OK).json(
new ResponseDTO<PerfumeDetailResponse>(
MSG_GET_PERFUME_DETAIL_SUCCESS,
response
)
);
})
.catch((err: Error) => next(err));

try {
const [result, _]: [PerfumeIntegralDTO, void] = await Promise.all([
Perfume.getPerfumeById(perfumeIdx, loginUserIdx),
SearchHistory.recordInquire(
loginUserIdx,
perfumeIdx,
'' /* 향후 경로가 다양화 되면 경로 기록 용 */
),
]);
const response: PerfumeDetailResponse =
PerfumeDetailResponse.createByPerfumeIntegralDTO(result);
res.status(StatusCode.OK).json(
new ResponseDTO<PerfumeDetailResponse>(
MSG_GET_PERFUME_DETAIL_SUCCESS,
response
)
);
} catch (err) {
next(err);
}
};

/**
Expand Down
82 changes: 46 additions & 36 deletions src/dao/PerfumeDao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,43 +188,51 @@ class PerfumeDao {
logger.debug(
`${LOG_TAG} recentSearchPerfumeList(userIdx = ${userIdx}, pagingDTO = ${pagingDTO})`
);
return InquireHistory.findAndCountAll(
_.merge({}, pagingDTO.sequelizeOption(), {
attributes: {
include: [
[
Sequelize.fn(
'max',
Sequelize.col('InquireHistory.created_at')
),
'inquireAt',
],
],
},
where: {
userIdx,
},
include: [
{
model: Perfume,
as: 'Perfume',
required: true,
try {
const result: {
rows: InquireHistory[];
// todo: count에 배열이 아닌 number이 오게끔 수정
count: { perfume_idx: number; count: number }[];
} = (await InquireHistory.findAndCountAll(
_.merge({}, pagingDTO.sequelizeOption(), {
raw: true,
nest: true,
attributes: {
include: [
{
model: Brand,
as: 'Brand',
required: true,
},
[
Sequelize.fn(
'max',
Sequelize.col('InquireHistory.created_at')
),
'inquireAt',
],
],
raw: true,
nest: true,
},
],
order: [[sequelize.col('inquireAt'), 'desc']],
group: ['InquireHistory.perfume_idx'],
})
).then((it: any) => {
const rows: PerfumeInquireHistoryDTO[] = it.rows
where: {
userIdx,
},
include: [
{
model: Perfume,
as: 'Perfume',
required: true,
include: [
{
model: Brand,
as: 'Brand',
required: true,
},
],
raw: true,
nest: true,
},
],
order: [[sequelize.col('inquireAt'), 'desc']],
group: ['InquireHistory.perfume_idx'],
})
)) as any;

const rows: PerfumeInquireHistoryDTO[] = result.rows
.map((json: any) => {
return {
perfumeIdx: json.Perfume.perfumeIdx,
Expand All @@ -243,8 +251,10 @@ class PerfumeDao {
};
})
.map(PerfumeInquireHistoryDTO.createByJson);
return new ListAndCountDTO(it.count.length, rows);
});
return new ListAndCountDTO(result.count.length as number, rows);
} catch (err) {
throw err;
}
}

/**
Expand Down
Loading