-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'bugfix/issue-153_token_revalidation' of github.com-dsma…
…bulage:dsmabulage/scholarx-backend into bugfix/issue-153_token_revalidation
- Loading branch information
Showing
4 changed files
with
32 additions
and
58 deletions.
There are no files selected for viewing
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,10 +1,8 @@ | ||
import express from 'express' | ||
import { getCategories } from '../../controllers/category.controller' | ||
import { requestQueryValidator } from '../../middlewares/requestValidator' | ||
import { paginationSchema } from '../../schemas/common/pagination-request.schema' | ||
|
||
const categoryRouter = express.Router() | ||
|
||
categoryRouter.get('/', requestQueryValidator(paginationSchema), getCategories) | ||
categoryRouter.get('/', getCategories) | ||
|
||
export default categoryRouter |
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,47 +1,35 @@ | ||
import { dataSource } from '../configs/dbConfig' | ||
import Category from '../entities/category.entity' | ||
import { type PaginatedApiResponse } from '../types' | ||
|
||
export const getAllCategories = async ( | ||
pageNumber: number, | ||
pageSize: number | ||
): Promise<PaginatedApiResponse<Pick<Category, 'uuid' | 'category'>>> => { | ||
export const getAllCategories = async (): Promise<{ | ||
statusCode: number | ||
categories?: Array<Pick<Category, 'uuid' | 'category'>> | null | ||
message: string | ||
}> => { | ||
try { | ||
const categoryRepository = dataSource.getRepository(Category) | ||
const allCategories: Category[] = await categoryRepository.find({ | ||
select: ['category', 'uuid'] | ||
}) | ||
|
||
const [allCategories, totalItemCount] = | ||
await categoryRepository.findAndCount({ | ||
select: ['category', 'uuid'], | ||
skip: (pageNumber - 1) * pageSize, | ||
take: pageSize | ||
}) | ||
const categories = allCategories.map((category) => { | ||
return { category: category.category, uuid: category.uuid } | ||
}) | ||
|
||
const items = allCategories.map((category) => ({ | ||
category: category.category, | ||
uuid: category.uuid | ||
})) | ||
|
||
if (items.length === 0) { | ||
if (!categories) { | ||
return { | ||
pageNumber, | ||
pageSize, | ||
totalItemCount, | ||
items: [], | ||
statusCode: 404, | ||
message: 'No categories found' | ||
message: 'Categories not found' | ||
} | ||
} | ||
|
||
return { | ||
pageNumber, | ||
pageSize, | ||
totalItemCount, | ||
items, | ||
statusCode: 200, | ||
message: 'Categories retrieved successfully' | ||
categories, | ||
message: 'All Categories found' | ||
} | ||
} catch (err) { | ||
console.error('Error getting categories', err) | ||
throw new Error('Error getting categories') | ||
console.error('Error getting mentor', err) | ||
throw new Error('Error getting mentor') | ||
} | ||
} |