You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							128 lines
						
					
					
						
							3.0 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							128 lines
						
					
					
						
							3.0 KiB
						
					
					
				| 'use strict'; | |
| 
 | |
| const moment = require('moment') | |
| 
 | |
| async function inspection (ctx) { | |
|    try { | |
|       const models = ctx.fs.dc.models; | |
|       const { projectAppId, screenshot = [] } = ctx.request.body | |
| 
 | |
|       const now = moment().format() | |
|       const storageData = screenshot.map(s => { | |
|          return { | |
|             projectAppId, | |
|             screenshot: [s], | |
|             createTime: now, | |
|          } | |
|       }) | |
| 
 | |
|       await models.AppInspection.bulkCreate(storageData) | |
| 
 | |
|       ctx.status = 204; | |
|    } catch (error) { | |
|       ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); | |
|       ctx.status = 400; | |
|       ctx.body = { | |
|          message: typeof error == 'string' ? error : undefined | |
|       } | |
|    } | |
| } | |
| 
 | |
| async function notedInspection (ctx) { | |
|    try { | |
|       const models = ctx.fs.dc.models; | |
|       const { inspectionId } = ctx.request.body | |
|       const { userId } = ctx.fs.api | |
| 
 | |
|       await models.AppInspection.update({ | |
|          notedPepUserId: userId, | |
|          notedTime: moment().format() | |
|       }, { | |
|          where: { | |
|             id: inspectionId | |
|          } | |
|       }) | |
| 
 | |
|       ctx.status = 204; | |
|    } catch (error) { | |
|       ctx.fs.logger.error(`path: ${ctx.path}, error: error`); | |
|       ctx.status = 400; | |
|       ctx.body = { | |
|          message: typeof error == 'string' ? error : undefined | |
|       } | |
|    } | |
| } | |
| 
 | |
| async function apiError (ctx) { | |
|    try { | |
|       const models = ctx.fs.dc.models; | |
|       const { projectAppId, alarmContent, router, statusCode } = ctx.request.body | |
|       const now = moment().format() | |
| 
 | |
|       let storageData = { | |
|          projectAppId, alarmContent, router, statusCode | |
|       } | |
|       const existRes = await models.AppAlarm.findOne({ | |
|          where: { | |
|             projectAppId, alarmContent, router, statusCode, | |
|             confirm: null | |
|          } | |
|       }) | |
|       if (existRes) { | |
|          await models.AppAlarm.update({ | |
|             updateTime: now | |
|          }, { | |
|             where: { | |
|                id: existRes.id | |
|             } | |
|          }) | |
|       } else { | |
|          const existCount = await models.AppAlarm.count({ | |
|             where: { | |
| 
 | |
|             } | |
|          }) | |
|          storageData.serialNumber = 'WEB' + (existCount < 9 ? '0' + (existCount + 1) : existCount) | |
|          storageData.createTime = now | |
|          await models.AppAlarm.create(storageData) | |
|       } | |
| 
 | |
|       ctx.status = 200; | |
|    } catch (error) { | |
|       ctx.fs.logger.error(`path: ${ctx.path}, error: error`); | |
|       ctx.status = 400; | |
|       ctx.body = { | |
|          message: typeof error == 'string' ? error : undefined | |
|       } | |
|    } | |
| } | |
| 
 | |
| async function confirmApiError (ctx) { | |
|    try { | |
|       const models = ctx.fs.dc.models; | |
|       const { confirm, appAlarmId } = ctx.request.body | |
| 
 | |
|       await models.AppAlarm.update({ | |
|          confirm, | |
|       }, { | |
|          where: { | |
|             id: appAlarmId | |
|          } | |
|       }) | |
| 
 | |
|       ctx.status = 204; | |
|    } catch (error) { | |
|       ctx.fs.logger.error(`path: ${ctx.path}, error: error`); | |
|       ctx.status = 400; | |
|       ctx.body = { | |
|          message: typeof error == 'string' ? error : undefined | |
|       } | |
|    } | |
| } | |
| 
 | |
| module.exports = { | |
|    inspection, | |
|    notedInspection, | |
|    apiError, | |
|    confirmApiError, | |
| }; |