... guild add searchGuild handler
This commit is contained in:
parent
2d208bd1ea
commit
2d444146f9
@ -4,7 +4,7 @@ const userDao = require("./userDao");
|
||||
|
||||
class GuildDao {
|
||||
async listGuild() {
|
||||
const ql = "SELECT idx, gname, logo, gowner, gownername, gmaxmember FROM t_guilds";
|
||||
const ql = "SELECT idx, gname, logo, gowner, gownername, gmaxmember FROM t_guilds LIMIT 10";
|
||||
const rl = await query_guild(ql);
|
||||
if (rl) {
|
||||
for (let i = 0; i < rl.length; i++) {
|
||||
@ -16,6 +16,15 @@ class GuildDao {
|
||||
return rl;
|
||||
}
|
||||
|
||||
async searchGuild(gName) {
|
||||
const q = `SELECT idx, gname, logo, gowner, gownername, gmaxmember FROM t_guilds WHERE gname LIKE ? LIMIT 10`;
|
||||
const r = await query_guild(q, ["%"+gName+"%"]);
|
||||
if (r) {
|
||||
return r;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async createGuild(gName, logo, uId) {
|
||||
const egId = await this.getGuildIdByUID(uId);
|
||||
if (egId) {
|
||||
|
@ -5,7 +5,11 @@ class GuildService {
|
||||
async listGuild() {
|
||||
return await guildDao.listGuild();
|
||||
}
|
||||
// 实现一个函数
|
||||
|
||||
async searchGuild(guildName) {
|
||||
return await guildDao.searchGuild(guildName);
|
||||
}
|
||||
|
||||
async createGuild(guildName, logo, creator) {
|
||||
const guildId = await guildDao.createGuild(guildName, logo, creator);
|
||||
return guildId;
|
||||
|
@ -39,6 +39,47 @@ class Handler {
|
||||
next(null, { code: Code.OK, guilds });
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} guild.guildHandler.searchGuild searchGuild 搜索工会
|
||||
* @apiGroup Guild
|
||||
*
|
||||
* @apiParam {String} guildName 工会名称
|
||||
*
|
||||
* @apiSuccess {Number} code 状态码
|
||||
* @apiSuccess {Object[]} guilds 工会列表
|
||||
*
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* {
|
||||
* "code": 200,
|
||||
* "guilds": [
|
||||
* {
|
||||
* "idx": 1,
|
||||
* "gname": "guild_1", // 工会名称 (String(48))
|
||||
* "logo": "logo_1", // 工会logo (String(32))
|
||||
* "gowner": "6516_2006_0xef59f6cc4d190a0ae576c46d4583e92b61174340", // 工会创建者ID (String(64))
|
||||
* "gownername": "owner_1", // 工会创建者名称 (String(32))
|
||||
* "gmaxmember": 100, // 工会最大成员数 (Number)
|
||||
* "countmember": 1 // 工会成员数 (Number)
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample {json} Error-Response:
|
||||
* {
|
||||
* "code": 4001,
|
||||
* "msg": "Failed to search guild."
|
||||
* }
|
||||
*
|
||||
*/
|
||||
async searchGuild({ guildName }, session, next) {
|
||||
try {
|
||||
const guilds = (await this.guildService.searchGuild(guildName)) || [];
|
||||
next(null, { code: Code.OK, guilds });
|
||||
} catch (err) {
|
||||
next(null, { code: Code.FAIL, msg: "Failed to search guild." });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} guild.guildHandler.createGuild createGuild 创建工会
|
||||
* @apiGroup Guild
|
||||
|
25
proxy/guild.test.js
Normal file
25
proxy/guild.test.js
Normal file
@ -0,0 +1,25 @@
|
||||
const TestBaseClient = require("./testbase");
|
||||
|
||||
describe("guild", () => {
|
||||
let msg;
|
||||
const tbc = new TestBaseClient();
|
||||
|
||||
test("entry", async () => {
|
||||
await tbc.init("6516_2006_0xef59f6cc4d190a0ae576c46d4583e92b61174340");
|
||||
msg = await tbc.rpc("connector.entryHandler.entry", {
|
||||
uid: "6516_2006_0xef59f6cc4d190a0ae576c46d4583e92b61174340",
|
||||
});
|
||||
console.log(msg);
|
||||
expect(msg.code).toBe(200);
|
||||
});
|
||||
|
||||
test("search", async () => {
|
||||
msg = await tbc.rpc("guild.guildHandler.searchGuild", { guildName: "new", });
|
||||
console.log(msg);
|
||||
expect(msg.code).toBe(200);
|
||||
});
|
||||
|
||||
test("end", async () => {
|
||||
tbc.destroy();
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user