import { _authUser } from "../utils/utils" ; import { ReportInterface } from "../interface/interface" ; import { _pushError , _pushSuccess } from "../app" ; import { deleteMany , deleteOneById , getKeysDB , isHasOne , taskChannelList , updateMany , updateOne } from "../mongo/curd" ; import { getHash } from "../redis/redis" ; import { _saveTimeline } from "./timeline" ; desc export const applyAudit = async ( socket , sid , data , channel , eventName ) => { await _authUser ( socket , sid , data , channel , eventName , 'noAuth' ) ; const applyReq = data ; if ( ! applyReq . _id ) { return await _pushError ( channel , eventName , applyReq , '参数错误' , 1 ) ; } const canAudit = await isHasOne ( { _id : applyReq . _id , pass : true } , 'audits' ) ; const redisObj = await getHash ( sid ) || { } ; if ( ! redisObj . isAdmin ) { return await _pushError ( channel , eventName , applyReq , '权限不够' ) ; } if ( ! canAudit ) { await updateOne ( { _id : applyReq . _id } , { pass : true } , 'audits' ) ; const { githubName } = await getKeysDB ( { id : applyReq . _id } , [ 'githubName' ] , 'audits' ) ; await updateOne ( { name : githubName } , { $inc : { passCount : 1 } } , 'users' ) ; await updateMany ( { auditId : applyReq . _id } , { pass : true } , 'reports' ) ; await updateOne ( { _id : redisObj . _id } , { $inc : { auditCount : 1 } } , 'users' ) ; const reportData = await getKeysDB ( { _id : applyReq . _id , pass : true } , [ ] , 'audits' ) ; await _saveTimeline ( socket , sid , reportData , channel , eventName ) ; return await _pushSuccess ( channel , 'auditStatus' , { _id : applyReq . _id } , '审核成功' ) ; } else { return await _pushError ( channel , 'auditStatus' , { _id : applyReq . _id } , '已被审核过' ) ; } } ; desc export const deleteAudit = async ( socket , sid , data , channel , eventName ) => { await _authUser ( socket , sid , data , channel , eventName , 'noAuth' ) ; const applyReq = data ; if ( ! applyReq . _id ) { return await _pushError ( channel , eventName , applyReq , '参数错误' , 1 ) ; } const canAudit = await isHasOne ( { _id : applyReq . _id , pass : true } , 'audits' ) ; const redisObj = await getHash ( sid ) || { } ; if ( ! redisObj . isAdmin ) { return await _pushError ( channel , eventName , applyReq , '权限不够' ) ; } if ( ! canAudit ) { await deleteOneById ( applyReq . _id , 'audits' ) ; const { githubName } = await getKeysDB ( { id : applyReq . _id } , [ 'githubName' ] , 'audits' ) ; await updateOne ( { name : githubName } , { $inc : { passCount : - 1 } } , 'users' ) ; await deleteMany ( { auditId : applyReq . _id } , 'reports' ) ; await updateOne ( { _id : redisObj . _id } , { $inc : { refuseCount : 1 } } , 'users' ) ; return await _pushSuccess ( channel , 'auditStatus' , { _id : applyReq . _id } , '驳回成功' ) ; } else { return await _pushError ( channel , 'auditStatus' , { _id : applyReq . _id } , '已通过审核，无法被驳回' ) ; } } ; desc export const getAudit = async ( socket , sid , data , channel , eventName ) => { await _authUser ( socket , sid , data , channel , eventName , 'noAuth' ) ; const redisObj = await getHash ( sid ) || { } ; if ( redisObj ) { const auditList = await taskChannelList ( 'audits' , 5 , { pass : { $ne : true } } ) ; return await _pushSuccess ( channel , 'getAudit' , auditList || [ ] , '下发待审核列表' ) ; } return await _pushError ( channel , eventName , [ ] , '权限不够' ) ; } ;