import { _authUser } from "../utils/utils" ; import { ReportInterface } from "../interface/interface" ; import { isObject , isString } from "../utils/check" ; import { getHash } from "../redis/redis" ; import { _pushError , _pushSuccess } from "../app" ; import { logSocket } from "./socket" ; import { getTime } from 'date-fns' ; import { insertMany , insertOne } from "../mongo/curd" ; desc author veaba
 *  date param socket param sid param data param channel param eventName export const report = async ( socket , sid , data , channel , eventName ) => { await _authUser ( socket , sid , data , channel , eventName , 'noAuth' ) ; const reqData = data ; let logType = '' ; if ( isObject ( reqData ) ) { if ( reqData . country && reqData . province && reqData . reportDate && isString ( reqData . reportDate ) && reqData . newsUrl && ( reqData . count || reqData . cure || reqData . dead || reqData . suspected ) ) { logType = 'success' ; let redisObj = await getHash ( sid ) ; const passObj = { } ; redisObj = { } ; if ( ! redisObj ) { return ; } else { reqData . githubName = redisObj . name ; if ( isString ( reqData . reportDate ) ) { reqData . reportDate = getTime ( new Date ( reqData . reportDate ) ) ; } let auditData = await insertOne ( { ... data , sid , count : reqData . count || 0 , cure : reqData . dead || 0 , suspected : reqData . cure || 0 , dead : reqData . suspected || 0 } , 'audits' ) ; await insertForReport ( reqData . count , { ... reqData , sid , auditId : auditData . _id , isConfirm : true , ... passObj } , sid , 'reports' , redisObj . name ) ; await insertForReport ( reqData . dead , { ... reqData , sid , auditId : auditData . _id , isDead : true , ... passObj } , sid , 'reports' , redisObj . name ) ; await insertForReport ( reqData . cure , { ... reqData , sid , auditId : auditData . _id , isCure : true , ... passObj } , sid , 'reports' , redisObj . name ) ; await insertForReport ( reqData . suspected , { ... reqData , sid , auditId : auditData . _id , isSuspected : true , ... passObj } , sid , 'reports' , redisObj . name ) ; await _pushSuccess ( 'broadcast' , 'console' , data , '下发审核数据' ) ; await logSocket ( socket , data , channel , eventName , logType ) ; return await _pushSuccess ( channel , eventName , [ ] , '已收录，谢谢你的贡献，管理员审核通过后将采用' , 0 ) ; } } await logSocket ( socket , data , channel , eventName , logType ) ; return await _pushError ( channel , eventName , reqData , '无效数据' ) ; } } ; desc how const insertForReport = async ( num = 0 , data , sid , collection_name , username ) => { if ( ! num ) { return ; } let insertArray = [ ] ; for ( let i = 0 ; i <= num ; i ++ ) { insertArray . push ( { ... data , sid , } ) ; } await insertMany ( insertArray , 'reports' ) ; } ;