Showing
1 changed file
with
41 additions
and
0 deletions
... | @@ -196,12 +196,53 @@ exports.adminDeleteDockerfile = async (req, res) => { | ... | @@ -196,12 +196,53 @@ exports.adminDeleteDockerfile = async (req, res) => { |
196 | return sendError(res, 500, error.message) | 196 | return sendError(res, 500, error.message) |
197 | } | 197 | } |
198 | } | 198 | } |
199 | + | ||
199 | exports.adminListImage = async (req, res) => { | 200 | exports.adminListImage = async (req, res) => { |
201 | + try{ | ||
202 | + let images = await Image.findAndCountAll({ | ||
203 | + order: [ | ||
204 | + ['createdAt', 'desc'] | ||
205 | + ] | ||
206 | + }) | ||
200 | 207 | ||
208 | + const result = { | ||
209 | + count: images.count, | ||
210 | + data: images.rows | ||
211 | + } | ||
212 | + return sendResponse(res, result, 200) | ||
213 | + } catch(error) { | ||
214 | + logging('image', 'error', { code: 500, message: error.message }, req) | ||
215 | + return sendError(res, 500, error.message) | ||
216 | + } | ||
201 | } | 217 | } |
202 | exports.adminDeleteImage = async (req, res) => { | 218 | exports.adminDeleteImage = async (req, res) => { |
219 | + const requiredKey = ['id'] | ||
220 | + const required = checkRequiredExist(req.body, requiredKey) | ||
221 | + if (required) { | ||
222 | + logging('image', 'error', { code: 400, message: 'missingKey:${required}' }, req) | ||
223 | + return sendError(res, 400, `missingKey:${required}`) | ||
224 | + } | ||
225 | + try { | ||
226 | + const imageId = req.body.id | ||
227 | + let image = await Image.findByPk(imageId) | ||
228 | + if (!image) { | ||
229 | + logging('image', 'error', { code: 404, message: 'NoImageFound' }, req) | ||
230 | + return sendError(res, 404, 'NoImageFound') | ||
231 | + } | ||
203 | 232 | ||
233 | + await Image.destroy({ | ||
234 | + where: { | ||
235 | + id: image.id | ||
236 | + } | ||
237 | + }) | ||
238 | + logging('image', 'delete', null, req) | ||
239 | + return sendResponse(res, true, 201) | ||
240 | + } catch (error) { | ||
241 | + logging('image', 'error', { code: 500, message: error.message }, req) | ||
242 | + return sendError(res, 500, error.message) | ||
243 | + } | ||
204 | } | 244 | } |
245 | + | ||
205 | exports.adminListContainer = async (req, res) => { | 246 | exports.adminListContainer = async (req, res) => { |
206 | 247 | ||
207 | } | 248 | } | ... | ... |
-
Please register or login to post a comment