Skip to content

Commit

Permalink
[#152] feat: 페이지 리스트 갱신 시 현재 페이지 정보를 동봉하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
domino8788 committed Dec 20, 2020
1 parent f7fcddf commit 1e94f36
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions backend/src/controllers/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ export const create = transactionHandler(
async (req: Request, res: Response): Promise<void> => {
const page = await pageService.create(req.body.page);
const pages = await pageService.readAll();
req.app.get('io').of('/pageList').emit('PageListUpdate', pages);
req.app
.get('io')
.of('/pageList')
.emit('PageListUpdate', {
currentPageId: (req.session as any).pageId,
pages,
});
res.status(StatusCode.CREATED).json({ page, pages });
},
);
Expand All @@ -25,15 +31,27 @@ export const readAll = async (req: Request, res: Response): Promise<void> => {
export const update = async (req: Request, res: Response): Promise<void> => {
const page = await pageService.update(req.params.pageId, req.body.page);
const pages = await pageService.readAll();
req.app.get('io').of('/pageList').emit('PageListUpdate', pages);
req.app
.get('io')
.of('/pageList')
.emit('PageListUpdate', {
currentPageId: (req.session as any).pageId,
pages,
});
res.status(StatusCode.OK).json({ page });
};

export const deleteOne = transactionHandler(
async (req: Request, res: Response): Promise<void> => {
await pageService.deleteOne(req.params.pageId);
const pages = await pageService.readAll();
req.app.get('io').of('/pageList').emit('PageListUpdate', pages);
req.app
.get('io')
.of('/pageList')
.emit('PageListUpdate', {
currentPageId: (req.session as any).pageId,
pages,
});
res.status(StatusCode.OK).json({ pages });
},
);

0 comments on commit 1e94f36

Please sign in to comment.