Showing
1 changed file
with
33 additions
and
2 deletions
| ... | @@ -85,8 +85,8 @@ exports.removeDockerfile = async (req, res) => { | ... | @@ -85,8 +85,8 @@ exports.removeDockerfile = async (req, res) => { |
| 85 | return sendError(res, 404, 'NoDockerfileFound') | 85 | return sendError(res, 404, 'NoDockerfileFound') |
| 86 | } | 86 | } |
| 87 | if (!user || user.id !== dockerfile.userId) { | 87 | if (!user || user.id !== dockerfile.userId) { |
| 88 | - logging('dockerfile', 'error', { code: 403, message: 'Unauthoirzed' }, req) | 88 | + logging('dockerfile', 'error', { code: 403, message: 'Unauthorized' }, req) |
| 89 | - return sendError(res, 403, 'Unauthoirzed') | 89 | + return sendError(res, 403, 'Unauthorized') |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | await Dockerfile.destroy({ | 92 | await Dockerfile.destroy({ |
| ... | @@ -131,7 +131,38 @@ exports.buildImage = async (req, res) => { | ... | @@ -131,7 +131,38 @@ exports.buildImage = async (req, res) => { |
| 131 | 131 | ||
| 132 | } | 132 | } |
| 133 | exports.removeImage = async (req, res) => { | 133 | exports.removeImage = async (req, res) => { |
| 134 | + const requiredKey = ['id'] | ||
| 135 | + const required = checkRequiredExist(req.body, requiredKey) | ||
| 136 | + if (required) { | ||
| 137 | + logging('image', 'error', { code: 400, message: 'missingKey:${required}' }, req) | ||
| 138 | + return sendError(res, 400, `missingKey:${required}`) | ||
| 139 | + } | ||
| 140 | + try { | ||
| 141 | + const user = await currentUser(req.headers.authorization) | ||
| 134 | 142 | ||
| 143 | + const imageId = req.body.id | ||
| 144 | + let image = await Image.findByPk(imageId) | ||
| 145 | + if (!image) { | ||
| 146 | + logging('image', 'error', { code: 404, message: 'NoDockerfileFound' }, req) | ||
| 147 | + return sendError(res, 404, 'NoDockerfileFound') | ||
| 148 | + } | ||
| 149 | + let dockerfile = await Dockerfile.findByPk(image.dockerfileId) | ||
| 150 | + if (!user || user.id !== dockerfile.userId) { | ||
| 151 | + logging('image', 'error', { code: 403, message: 'Unauthorized' }, req) | ||
| 152 | + return sendError(res, 403, 'Unauthorized') | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + await Image.destroy({ | ||
| 156 | + where: { | ||
| 157 | + id: image.id | ||
| 158 | + } | ||
| 159 | + }) | ||
| 160 | + logging('image', 'delete', null, req) | ||
| 161 | + return sendResponse(res, true, 201) | ||
| 162 | + } catch (error) { | ||
| 163 | + logging('image', 'error', { code: 500, message: error.message }, req) | ||
| 164 | + return sendError(res, 500, error.message) | ||
| 165 | + } | ||
| 135 | } | 166 | } |
| 136 | 167 | ||
| 137 | exports.listContainer = async (req, res) => { | 168 | exports.listContainer = async (req, res) => { | ... | ... |
-
Please register or login to post a comment