정민우

[Add] container Admin 추가

......@@ -244,8 +244,47 @@ exports.adminDeleteImage = async (req, res) => {
}
exports.adminListContainer = async (req, res) => {
try{
let containers = await Container.findAndCountAll({
order: [
['createdAt', 'desc']
]
})
const result = {
count: containers.count,
data: containers.rows
}
return sendResponse(res, result, 200)
} catch(error) {
logging('container', 'error', { code: 500, message: error.message }, req)
return sendError(res, 500, error.message)
}
}
exports.adminDeleteContainer = async (req, res) => {
const requiredKey = ['id']
const required = checkRequiredExist(req.body, requiredKey)
if (required) {
logging('container', 'error', { code: 400, message: 'missingKey:${required}' }, req)
return sendError(res, 400, `missingKey:${required}`)
}
try {
const containerId = req.body.id
let container = await Image.findByPk(containerId)
if (!container) {
logging('container', 'error', { code: 404, message: 'NoContainerFound' }, req)
return sendError(res, 404, 'NoContainerFound')
}
await Container.destroy({
where: {
id: container.id
}
})
logging('container', 'delete', null, req)
return sendResponse(res, true, 201)
} catch (error) {
logging('container', 'error', { code: 500, message: error.message }, req)
return sendError(res, 500, error.message)
}
}
......