Skip to content

Commit

Permalink
refactor(v2): 반환 데이터를 리스트에서 오브젝트로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
nyj001012 committed Oct 28, 2023
1 parent 9e60d43 commit e4a0ea0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions backend/src/v2/lendings/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const lendings = s.router(contract.lendings, {
middleware: [authValidate(roleSet.all)],
handler: async ({ query, req: { user } }) => {

Check failure on line 12 in backend/src/v2/lendings/mod.ts

View workflow job for this annotation

GitHub Actions / Test PR

Binding element 'query' implicitly has an 'any' type.

Check failure on line 12 in backend/src/v2/lendings/mod.ts

View workflow job for this annotation

GitHub Actions / Test PR

Binding element 'user' implicitly has an 'any' type.
const { nickname: login } = getUser.parse(user);
const [items, count] = await getHistoriesByUser({ ...query, login });
const { items, count } = await getHistoriesByUser({ ...query, login });
const meta = {
totalItems: count,
itemCount: items.length,
Expand All @@ -27,7 +27,7 @@ export const lendings = s.router(contract.lendings, {
get: {
middleware: [authValidate(roleSet.librarian)],
handler: async ({ query }) => {

Check failure on line 29 in backend/src/v2/lendings/mod.ts

View workflow job for this annotation

GitHub Actions / Test PR

Binding element 'query' implicitly has an 'any' type.
const [items, count] = await getHistoriesByQuery(query);
const { items, count } = await getHistoriesByQuery(query);

const meta = {
totalItems: count,
Expand Down
10 changes: 5 additions & 5 deletions backend/src/v2/lendings/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export const getHistoriesByQuery = async ({ query, type, page, limit }: Args & O
let countSql = db.selectFrom('v_histories')
.select(({fn}) => [ fn.count<number>('id').as('count') ]);
countSql = getSearchCondition(countSql, {query, type});
const {count} = (await countSql.execute())[0];
return [items, count];
const [{count}] = await countSql.execute();
return { items, count };
}

type MyPageArgs = {
Expand All @@ -69,9 +69,9 @@ export const getHistoriesByUser = async ({login, page, limit}: MyPageArgs & Offs
.limit(limit)
.offset(limit * page)
.execute();
const {count} = (await db.selectFrom('v_histories')
const [{count}] = await db.selectFrom('v_histories')
.where('login', '=', login)
.select(({fn}) => [ fn.count<number>('id').as('count') ])
.execute())[0];
return [ items, count ];
.execute();
return { items, count };
}

0 comments on commit e4a0ea0

Please sign in to comment.