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.
		
		
		
		
		
			
		
			
				
					
					
						
							86 lines
						
					
					
						
							2.0 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							86 lines
						
					
					
						
							2.0 KiB
						
					
					
				| 'use strict'; | |
| const moment = require('moment') | |
| 
 | |
| async function assessGet (ctx) { | |
|     try { | |
|         const models = ctx.fs.dc.models; | |
|         const { unit, month } = ctx.query; | |
| 
 | |
|         let findOption = { | |
|             where: { | |
| 
 | |
|             }, | |
|             order: [['id', 'DESC']] | |
|         } | |
|         if (month) { | |
|             findOption.where.month = { | |
|                 $between: [moment(month).startOf('month').format(), moment(month).endOf('month').format()] | |
|             } | |
|         } | |
|         if (unit) { | |
|             findOption.where.unit = unit | |
|         } | |
| 
 | |
|         const roadRes = await models.Assess.findAll(findOption) | |
| 
 | |
|         ctx.status = 200; | |
|         ctx.body = roadRes | |
|     } catch (error) { | |
|         ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); | |
|         ctx.status = 400; | |
|         ctx.body = { | |
|             message: typeof error == 'string' ? error : undefined | |
|         } | |
|     } | |
| } | |
| 
 | |
| async function assessEdit (ctx) { | |
|     try { | |
|         const models = ctx.fs.dc.models; | |
|         const data = ctx.request.body; | |
| 
 | |
|         if (!data.assessId) { | |
|             await models.Assess.create(data) | |
|         } else { | |
|             await models.Assess.update( | |
|                 data, { | |
|                 where: { | |
|                     id: data.assessId | |
|                 } | |
|             }) | |
|         } | |
| 
 | |
|         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 assessDel (ctx) { | |
|     try { | |
|         const models = ctx.fs.dc.models; | |
|         const { assessId } = ctx.params; | |
| 
 | |
|         await models.Assess.destroy({ | |
|             where: { | |
|                 id: assessId | |
|             } | |
|         }) | |
| 
 | |
|         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 = { | |
|     assessGet, assessEdit, assessDel, | |
| }; |