Merge branch 'backend-docker' into 'master'
[Add] container Admin 추가 See merge request !13
Showing
1 changed file
with
39 additions
and
0 deletions
... | @@ -244,8 +244,47 @@ exports.adminDeleteImage = async (req, res) => { | ... | @@ -244,8 +244,47 @@ exports.adminDeleteImage = async (req, res) => { |
244 | } | 244 | } |
245 | 245 | ||
246 | exports.adminListContainer = async (req, res) => { | 246 | exports.adminListContainer = async (req, res) => { |
247 | + try{ | ||
248 | + let containers = await Container.findAndCountAll({ | ||
249 | + order: [ | ||
250 | + ['createdAt', 'desc'] | ||
251 | + ] | ||
252 | + }) | ||
247 | 253 | ||
254 | + const result = { | ||
255 | + count: containers.count, | ||
256 | + data: containers.rows | ||
257 | + } | ||
258 | + return sendResponse(res, result, 200) | ||
259 | + } catch(error) { | ||
260 | + logging('container', 'error', { code: 500, message: error.message }, req) | ||
261 | + return sendError(res, 500, error.message) | ||
262 | + } | ||
248 | } | 263 | } |
249 | exports.adminDeleteContainer = async (req, res) => { | 264 | exports.adminDeleteContainer = async (req, res) => { |
265 | + const requiredKey = ['id'] | ||
266 | + const required = checkRequiredExist(req.body, requiredKey) | ||
267 | + if (required) { | ||
268 | + logging('container', 'error', { code: 400, message: 'missingKey:${required}' }, req) | ||
269 | + return sendError(res, 400, `missingKey:${required}`) | ||
270 | + } | ||
271 | + try { | ||
272 | + const containerId = req.body.id | ||
273 | + let container = await Image.findByPk(containerId) | ||
274 | + if (!container) { | ||
275 | + logging('container', 'error', { code: 404, message: 'NoContainerFound' }, req) | ||
276 | + return sendError(res, 404, 'NoContainerFound') | ||
277 | + } | ||
250 | 278 | ||
279 | + await Container.destroy({ | ||
280 | + where: { | ||
281 | + id: container.id | ||
282 | + } | ||
283 | + }) | ||
284 | + logging('container', 'delete', null, req) | ||
285 | + return sendResponse(res, true, 201) | ||
286 | + } catch (error) { | ||
287 | + logging('container', 'error', { code: 500, message: error.message }, req) | ||
288 | + return sendError(res, 500, error.message) | ||
289 | + } | ||
251 | } | 290 | } | ... | ... |
-
Please register or login to post a comment