This commit is contained in:
lightings 2023-07-24 17:53:28 +08:00
parent d1d5a765f9
commit a6f260a6e6
4 changed files with 13 additions and 13 deletions

View File

@ -51,16 +51,16 @@ class UserDao {
if (limit>20) {
throw new Error(`limit too large: ${limit}`);
}
const query = `SELECT idx, account_id, CAST(name as CHAR) as name FROM t_user WHERE idx>? AND (CAST(account_id as CHAR) LIKE ? OR CAST(name as CHAR) LIKE ?) LIMIT ?`;
const query = `SELECT idx, account_id, CAST(name as CHAR) as name FROM t_user WHERE idx>? AND (CAST(account_id as CHAR) = ? OR CAST(name as CHAR) LIKE ?) LIMIT ?`;
const results = await query_game(query, [
last_idx,
"%" + name + "%",
name,
"%" + name + "%",
limit,
]);
if (results.length === 0) {
throw new Error(`User not found: ${name}`);
return { users: [], last_idx: last_idx };
}
const users = results.map((user) => {

View File

@ -181,7 +181,7 @@ class FriendHandler {
msg: "User added to blacklist successfully.",
});
} catch (err) {
next(null, { code: Code.FAIL, msg: "Failed to add user to blacklist." });
next(null, { code: Code.FAIL, msg: err.message });
}
}
@ -411,7 +411,7 @@ class FriendHandler {
* }
*
*/
async findUser({ name, last_idx, limit }, { uid }, next) {
async findUser({ name, last_idx = 0, limit = 10 }, { uid }, next) {
try {
const users = await this.friendService.findUser(
name,

View File

@ -5,11 +5,11 @@ const { Message } = require("./Message");
const port = 4999;
// const host = "192.168.100.173";
// const host = "62.234.46.11";
const host = "r2.cebggame.com";
// const host = "192.168.100.83";
//const test_uuid = "6516_2006_0xef59f6cc4d190a0ae576c46d4583e92b61174340";
// const host = "r2.cebggame.com";
const host = "192.168.100.83";
const test_uuid = "6516_2006_0xef59f6cc4d190a0ae576c46d4583e92b61174340";
// const test_uuid = "6516_2006_0xa5069f54f2ed021e0ac47dbb385420a0d5f41be3";
const test_uuid = "6517_2006_0_104162729566475397176";
// const test_uuid = "6517_2006_0_104162729566475397176";
const stick = new Stick(1024);
stick.setMaxBodyLen(MaxBodyLen["32K"], true);
@ -151,8 +151,8 @@ describe("client", () => {
});
test("find User", async () => {
msg = await rpc("friend.friendHandler.findUser", { name: "xiao" });
console.log(msg);
msg = await rpc("friend.friendHandler.findUser", { name: "6513_2006_md9nVaGIooStTM1D56NLblLosFhWhgxB3", last_idx: 0, limit: 5 });
console.log(JSON.stringify(msg, null, 2));
expect(msg.code).toBe(200);
});

View File

@ -46,7 +46,7 @@ describe('add friend self', () => {
test('add a black', async () => {
const msg = await tbc.rpc("friend.friendHandler.addToBlackList", { bid: userA, });
console.log(msg);
expect(msg.code).toBe(200);
expect(msg.code).toBe(500);
});
test('end', async()=>{
@ -158,7 +158,7 @@ describe("accept friend", () => {
});
test("delete a friend", async () => {
msg = await rpc("friend.friendHandler.deleteFriend", { fid: userB, });
msg = await rpc("friend.friendHandler.deleteFriend", { fid: userA, });
console.log(msg);
expect(msg.code).toBe(200);
});