MCPcopy Create free account
hub / github.com/bailicangdu/node-elm / updateAvatar

Method updateAvatar

controller/admin/admin.js:241–270  ·  view source on GitHub ↗
(req, res, next)

Source from the content-addressed store, hash-verified

239 }
240 }
241 async updateAvatar(req, res, next){
242 const admin_id = req.params.admin_id;
243 if (!admin_id || !Number(admin_id)) {
244 console.log('admin_id参数错误', admin_id)
245 res.send({
246 status: 0,
247 type: 'ERROR_ADMINID',
248 message: 'admin_id参数错误',
249 })
250 return
251 }
252
253 try{
254 const image_path = await this.getPath(req);
255 await AdminModel.findOneAndUpdate({id: admin_id}, {$set: {avatar: image_path}});
256 res.send({
257 status: 1,
258 image_path,
259 })
260 return
261 }catch(err){
262 console.log('上传图片失败', err);
263 res.send({
264 status: 0,
265 type: 'ERROR_UPLOAD_IMG',
266 message: '上传图片失败'
267 })
268 return
269 }
270 }
271}
272
273export default new Admin()

Callers

nothing calls this directly

Calls 1

getPathMethod · 0.80

Tested by

no test coverage detected