Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 에러 로그 생성 - http status code, message 전달 - 404 페이지 응답
- Loading branch information
Showing
5 changed files
with
122 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,28 +1,56 @@ | ||
const achievements = require('../model/achievements'); | ||
|
||
module.exports = { | ||
async all(req, res) { | ||
const [allAchievements] = await achievements.get(req.pool); | ||
res.send(allAchievements); | ||
async all(req, res, next) { | ||
try { | ||
const [allAchievements] = await achievements.get(req.pool); | ||
const mainAchievements = allAchievements.filter(({ achievementsId }) => !achievementsId); | ||
const response = mainAchievements.map(achievement => { | ||
const subAchievements = allAchievements.filter(({ achievementsId }) => achievementsId === achievement.id); | ||
return { | ||
...achievement, | ||
subAchievements, | ||
}; | ||
}); | ||
res.status(200).json(response); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}, | ||
|
||
async get(req, res) { | ||
const [achievement] = await achievements.getById(req.pool, req.params.id); | ||
res.send(achievement); | ||
async get(req, res, next) { | ||
try { | ||
const [achievement] = await achievements.getById(req.pool, req.params.id); | ||
res.status(200).json(achievement); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}, | ||
|
||
async store(req, res) { | ||
const [result] = await achievements.create(req.pool, req.body); | ||
res.send(result); | ||
async store(req, res, next) { | ||
try { | ||
const [result] = await achievements.create(req.pool, req.body); | ||
res.status(200).json(result); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}, | ||
|
||
async update(req, res) { | ||
const [result] = await achievements.update(req.pool, req.params.id, req.body); | ||
res.send(result); | ||
async update(req, res, next) { | ||
try { | ||
const [result] = await achievements.update(req.pool, req.params.id, req.body); | ||
res.status(200).json(result); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}, | ||
|
||
async delete(req, res) { | ||
const [result] = await achievements.delete(req.pool, req.params.id); | ||
res.send(result); | ||
async delete(req, res, next) { | ||
try { | ||
const [result] = await achievements.delete(req.pool, req.params.id); | ||
res.status(200).json(result); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}, | ||
}; |
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,23 +1,25 @@ | ||
const categories = require('../model/categories'); | ||
|
||
module.exports = { | ||
async all(req, res) { | ||
const [allCategories] = await categories.get(req.pool); | ||
const mainCategories = allCategories.filter(({is_sub}) => !is_sub); | ||
async all(req, res, next) { | ||
try { | ||
const [allCategories] = await categories.get(req.pool); | ||
const mainCategories = allCategories.filter(({ sub }) => !sub); | ||
|
||
const response = mainCategories.map(({id, name}) => { | ||
const subCategories = allCategories | ||
.filter(({category_id, is_sub}) => is_sub && id === category_id) | ||
.map(({id, name}) => { | ||
return {id, name}; | ||
}); | ||
return { | ||
id, | ||
name, | ||
subCategories, | ||
}; | ||
}); | ||
|
||
res.status(200).send(response); | ||
const response = mainCategories.map(({ id, name, title }) => { | ||
const subCategories = allCategories | ||
.filter(({ categoryId, sub }) => sub && id === categoryId) | ||
.map(({ id, name, title }) => ({ id, name, title })); | ||
return { | ||
id, | ||
name, | ||
title, | ||
subCategories, | ||
}; | ||
}); | ||
res.status(200).json(response); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}, | ||
}; |
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,23 +1,39 @@ | ||
const subAchievements = require('../model/subAchievements'); | ||
|
||
module.exports = { | ||
async get(req, res) { | ||
const [achievements] = await subAchievements.getById(req.pool, req.params.id); | ||
res.send(achievements); | ||
async get(req, res, next) { | ||
try { | ||
const [achievements] = await subAchievements.getById(req.pool, req.params.id); | ||
res.status(200).json(achievements); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}, | ||
|
||
async store(req, res) { | ||
const [result] = await subAchievements.create(req.pool, req.body); | ||
res.send(result); | ||
async store(req, res, next) { | ||
try { | ||
const [result] = await subAchievements.create(req.pool, req.body); | ||
res.send(result); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}, | ||
|
||
async update(req, res) { | ||
const [result] = await subAchievements.update(req.pool, req.params.id, req.body); | ||
res.send(result); | ||
async update(req, res, next) { | ||
try { | ||
const [result] = await subAchievements.update(req.pool, req.params.id, req.body); | ||
res.send(result); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}, | ||
|
||
async delete(req, res) { | ||
const [result] = await subAchievements.delete(req.pool, req.params.id); | ||
res.send(result); | ||
async delete(req, res, next) { | ||
try { | ||
const [result] = await subAchievements.delete(req.pool, req.params.id); | ||
res.send(result); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}, | ||
}; |
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