聊天:举报接口及测试
This commit is contained in:
@@ -2,7 +2,7 @@ import { CHANNEL_PREFIX, MSG_SOURCE } from './../../../consts/constModules/chatC
|
|||||||
import {Application, BackendSession} from 'pinus';
|
import {Application, BackendSession} from 'pinus';
|
||||||
import { resResult } from '../../../pubUtils/util';
|
import { resResult } from '../../../pubUtils/util';
|
||||||
import { DEFAULT_MSG_PER_PAGE, STATUS } from '../../../consts';
|
import { DEFAULT_MSG_PER_PAGE, STATUS } from '../../../consts';
|
||||||
import { createGroupMsg, createPrivateMsg, getPrivateMessages, pushGroupMsgToRoom, pushMsgToRole, updatePrivateMsgReadInfo } from '../../../services/chatService';
|
import { createAccuseData, createGroupMsg, createPrivateMsg, getPrivateMessages, pushGroupMsgToRoom, pushMsgToRole, updatePrivateMsgReadInfo } from '../../../services/chatService';
|
||||||
|
|
||||||
|
|
||||||
export default function(app: Application) {
|
export default function(app: Application) {
|
||||||
@@ -148,4 +148,19 @@ export class ChatHandler {
|
|||||||
}
|
}
|
||||||
return resResult(STATUS.SUCCESS, result);
|
return resResult(STATUS.SUCCESS, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 举报玩家的消息
|
||||||
|
* @param {{targetRoleId: string, targetMsgCode: string; reason: number}} msg 被举报玩家的 Id,被举报的消息编号,举报原因
|
||||||
|
* @param {BackendSession} session
|
||||||
|
* @returns
|
||||||
|
* @memberof ChatHandler
|
||||||
|
*/
|
||||||
|
async accuse(msg: {targetRoleId: string, targetMsgCode: string; reason: number}, session: BackendSession) {
|
||||||
|
const roleId = session.get('roleId');
|
||||||
|
const { targetRoleId, targetMsgCode, reason } = msg;
|
||||||
|
const accuseRec = await createAccuseData(roleId, targetRoleId, targetMsgCode, reason);
|
||||||
|
if (!accuseRec) return resResult(STATUS.WRONG_PARMS);
|
||||||
|
return resResult(STATUS.SUCCESS, accuseRec);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { CHANNEL_PREFIX, MSG_CODE_LEN, MSG_STATUS, ON_PRIVATE_MSG_ROUTE, RECENT_
|
|||||||
import { getRoleOnlineInfo } from './redisService';
|
import { getRoleOnlineInfo } from './redisService';
|
||||||
import { ChatInfoModel } from '../db/ChatInfo';
|
import { ChatInfoModel } from '../db/ChatInfo';
|
||||||
import { channelServer } from './chatChannelService';
|
import { channelServer } from './chatChannelService';
|
||||||
|
import { AccuseRecModel, AccueseParam } from '../db/AccuseRec';
|
||||||
|
|
||||||
export * from './chatChannelService';
|
export * from './chatChannelService';
|
||||||
export * from './sysChatService';
|
export * from './sysChatService';
|
||||||
@@ -295,3 +296,11 @@ export async function pushTeamInviteMsg(roleId: string, roleName: string, server
|
|||||||
await pushGroupMsgToRoom(msgData);
|
await pushGroupMsgToRoom(msgData);
|
||||||
return msgData;
|
return msgData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function createAccuseData(roleId: string, targetRoleId: string, targetMsgCode: string, reason: number) {
|
||||||
|
const data: AccueseParam = {
|
||||||
|
roleId, targetRoleId, targetMsgCode, reason
|
||||||
|
};
|
||||||
|
const result = await AccuseRecModel.createRec(data);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|||||||
@@ -368,4 +368,15 @@ describe('聊天测试', function() {
|
|||||||
});
|
});
|
||||||
}, 1000);
|
}, 1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('举报消息', function(done) {
|
||||||
|
pinusClient.request('chat.chatHandler.accuse', {targetRoleId: roleInfoT.roleId, targetMsgCode: 'test', reason: 1}, (res) => {
|
||||||
|
checkSuccessResponse(res);
|
||||||
|
expect(res.data).to.be.an('object');
|
||||||
|
expect(res.data.roleId).to.be.equal(roleInfo.roleId);
|
||||||
|
expect(res.data.targetRoleId).to.be.equal(roleInfoT.roleId);
|
||||||
|
expect(res.data.targetMsgCode).to.be.equal('test');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import BaseModel from './BaseModel';
|
import BaseModel from './BaseModel';
|
||||||
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
|
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
|
||||||
|
import { genCode } from '../pubUtils/util';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 举报记录
|
* 举报记录
|
||||||
@@ -8,25 +9,35 @@ import { index, getModelForClass, prop, DocumentType, modelOptions } from '@type
|
|||||||
@index({ roleId: 1 })
|
@index({ roleId: 1 })
|
||||||
@index({ targetRoleId: 1 })
|
@index({ targetRoleId: 1 })
|
||||||
export default class AccuseRec extends BaseModel {
|
export default class AccuseRec extends BaseModel {
|
||||||
@prop({ required: true, default: '' })
|
@prop({ required: true, default: '' })
|
||||||
roleId: string; // 举报人的 roleId
|
code: string; // 唯一标识
|
||||||
@prop({ required: true, default: '' })
|
@prop({ required: true, default: '' })
|
||||||
roleName: string; // 举报人名字
|
roleId: string; // 举报人的 roleId
|
||||||
@prop({ required: true, default: '' })
|
@prop({ required: true, default: '' })
|
||||||
targetRoleId: string; // 被举报人的 roleId
|
roleName: string; // 举报人名字
|
||||||
@prop({ required: true, default: '' })
|
@prop({ required: true, default: '' })
|
||||||
targetRoleName: string; // 被举报人的名字
|
targetRoleId: string; // 被举报人的 roleId
|
||||||
|
@prop({ required: true, default: '' })
|
||||||
|
targetRoleName: string; // 被举报人的名字
|
||||||
|
|
||||||
@prop({ required: true, default: '' })
|
@prop({ required: true, default: '' })
|
||||||
targetMsgCode: string; // 被举报的消息标识
|
targetMsgCode: string; // 被举报的消息标识
|
||||||
@prop({ required: true, default: 0 })
|
@prop({ required: true, default: 0 })
|
||||||
reason: number; // 举报原因:1,涉政;2,广告;3,辱骂;4,欺诈;5,其它
|
reason: number; // 举报原因:1,涉政;2,广告;3,辱骂;4,欺诈;5,其它
|
||||||
@prop({ required: true, default: 0 })
|
@prop({ required: true, default: 0 })
|
||||||
result: number; // 处理结果:0,默认值,未处理;1,删除;2,忽略
|
result: number; // 处理结果:0,默认值,未处理;1,删除;2,忽略
|
||||||
@prop({ required: true, default: '' })
|
@prop({ required: true, default: '' })
|
||||||
remarks: string; // 处理备注
|
remarks: string; // 处理备注
|
||||||
|
|
||||||
|
public static async createRec(data: AccueseParam) {
|
||||||
|
const code = genCode(8);
|
||||||
|
const docData = new AccuseRecModel();
|
||||||
|
const result: AccuseRecType = await AccuseRecModel.findOneAndUpdate({ code }, { ...docData.toJSON(), ...data, code }, { upsert: true, new: true }).select('-_id').lean();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AccuseRecModel = getModelForClass(AccuseRec);
|
export const AccuseRecModel = getModelForClass(AccuseRec);
|
||||||
|
|
||||||
export interface AccuseRecType extends Pick<DocumentType<AccuseRec>, keyof AccuseRec>{}
|
export interface AccuseRecType extends Pick<DocumentType<AccuseRec>, keyof AccuseRec>{}
|
||||||
|
export type AccueseParam = Partial<AccuseRecType>;
|
||||||
|
|||||||
Reference in New Issue
Block a user