Skip to content

Commit

Permalink
Merge pull request #39 from GDSC-PKNU-21-22/fix/#38
Browse files Browse the repository at this point in the history
Fix/#38: 공지사항 요청 하는 함수 에러 핸들링 추가
  • Loading branch information
pp449 authored Jul 18, 2023
2 parents ac8c672 + 406bedf commit d962561
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/apis/notice/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const router = express.Router();
router.get('/', async (req: Request, res: Response) => {
try {
const major = req.query.major as string;
if (major === undefined) {
res.status(404).json('학과를 입력해주세요');
}
const notices = await getNotices(major);
res.json(notices);
} catch (err) {
Expand Down
3 changes: 2 additions & 1 deletion src/apis/notice/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const getNotices = async (department: string): Promise<Notice[]> => {
const getNoticesQuery = `SELECT * FROM ${tableName}`;
db.query(getNoticesQuery, (err: Error, res: Notice[]) => {
if (err) reject(err);
notices.push(...res);
if (res !== undefined && res.length > 0) notices.push(...res);
resolve();
});
});
Expand All @@ -19,5 +19,6 @@ export const getNotices = async (department: string): Promise<Notice[]> => {
getNoticesFromTable(`${department}고정`),
getNoticesFromTable(`${department}일반`),
]);

return notices;
};

0 comments on commit d962561

Please sign in to comment.