|
|
@ -8,7 +8,6 @@ import {
|
|
|
|
call,
|
|
|
|
call,
|
|
|
|
} from 'tailchat-server-sdk';
|
|
|
|
} from 'tailchat-server-sdk';
|
|
|
|
import type { GroupTopicDocument, GroupTopicModel } from '../models/topic';
|
|
|
|
import type { GroupTopicDocument, GroupTopicModel } from '../models/topic';
|
|
|
|
const { Types } = db;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 群组话题
|
|
|
|
* 群组话题
|
|
|
@ -24,6 +23,14 @@ class GroupTopicService extends TcService {
|
|
|
|
onInit(): void {
|
|
|
|
onInit(): void {
|
|
|
|
this.registerLocalDb(require('../models/topic').default);
|
|
|
|
this.registerLocalDb(require('../models/topic').default);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.registerAction('list', this.list, {
|
|
|
|
|
|
|
|
params: {
|
|
|
|
|
|
|
|
groupId: 'string',
|
|
|
|
|
|
|
|
panelId: 'string',
|
|
|
|
|
|
|
|
page: { type: 'number', optional: true },
|
|
|
|
|
|
|
|
size: { type: 'number', optional: true },
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
this.registerAction('create', this.create, {
|
|
|
|
this.registerAction('create', this.create, {
|
|
|
|
params: {
|
|
|
|
params: {
|
|
|
|
groupId: 'string',
|
|
|
|
groupId: 'string',
|
|
|
@ -33,6 +40,42 @@ class GroupTopicService extends TcService {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 获取所有Topic
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
async list(
|
|
|
|
|
|
|
|
ctx: TcContext<{
|
|
|
|
|
|
|
|
groupId: string;
|
|
|
|
|
|
|
|
panelId: string;
|
|
|
|
|
|
|
|
page?: number;
|
|
|
|
|
|
|
|
size?: number;
|
|
|
|
|
|
|
|
}>
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
const { groupId, panelId, page = 1, size = 20 } = ctx.params;
|
|
|
|
|
|
|
|
const userId = ctx.meta.userId;
|
|
|
|
|
|
|
|
const t = ctx.meta.t;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 鉴权
|
|
|
|
|
|
|
|
const group = await call(ctx).getGroupInfo(groupId);
|
|
|
|
|
|
|
|
const isMember = group.members.some((member) => member.userId === userId);
|
|
|
|
|
|
|
|
if (!isMember) {
|
|
|
|
|
|
|
|
throw new Error(t('不是该群组成员'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const topic = await this.adapter.model
|
|
|
|
|
|
|
|
.find({
|
|
|
|
|
|
|
|
groupId,
|
|
|
|
|
|
|
|
panelId,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.limit(size)
|
|
|
|
|
|
|
|
.skip((page - 1) * 20)
|
|
|
|
|
|
|
|
.exec();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const json = await this.transformDocuments(ctx, {}, topic);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return json;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 创建一条Topic
|
|
|
|
* 创建一条Topic
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -59,18 +102,12 @@ class GroupTopicService extends TcService {
|
|
|
|
if (!targetPanel) {
|
|
|
|
if (!targetPanel) {
|
|
|
|
throw new Error(t('面板不存在'));
|
|
|
|
throw new Error(t('面板不存在'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const isPanelValid =
|
|
|
|
|
|
|
|
targetPanel.type === GroupPanelType.TEXT &&
|
|
|
|
|
|
|
|
_.get(targetPanel, ['meta', 'variant']) === 'topic';
|
|
|
|
|
|
|
|
if (!isPanelValid) {
|
|
|
|
|
|
|
|
throw new Error(t('面板类型不合法'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const topic = await this.adapter.model.create({
|
|
|
|
const topic = await this.adapter.model.create({
|
|
|
|
groupId: new Types.ObjectId(groupId),
|
|
|
|
groupId,
|
|
|
|
panelId,
|
|
|
|
panelId,
|
|
|
|
content,
|
|
|
|
content,
|
|
|
|
author: new Types.ObjectId(userId),
|
|
|
|
author: userId,
|
|
|
|
comment: [],
|
|
|
|
comment: [],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|