forked from Gitlink/forgeplus-react-v2
114 lines
2.7 KiB
JavaScript
114 lines
2.7 KiB
JavaScript
/**
|
||
* 通用评论 API 调用器
|
||
* 根据 type 参数调用不同的业务接口
|
||
*/
|
||
|
||
import { COMMENT_TYPE } from './constants';
|
||
import {
|
||
getJournalList,
|
||
addJournal,
|
||
editJournal,
|
||
deleteJournal,
|
||
uploadFileBySourceJournal
|
||
} from '../../forge/Information/api';
|
||
|
||
/**
|
||
* 获取评论列表
|
||
* @param {string} type - 评论类型
|
||
* @param {string|number} id - 资源 ID
|
||
* @param {Object} params - 分页参数
|
||
* @returns {Promise}
|
||
*/
|
||
export async function getCommentList(type, id, page, limit) {
|
||
switch (type) {
|
||
case COMMENT_TYPE.RESOURCE:
|
||
return await getJournalList({
|
||
journalized_id: id,
|
||
journalized_type: type,
|
||
pageNum: page,
|
||
pageSize: limit
|
||
})
|
||
default:
|
||
throw new Error(`Unsupported comment type: ${type}`);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 新增评论
|
||
* @param {string} type - 评论类型
|
||
* @param {string|number} id - 资源 ID
|
||
* @param {Object} data - 评论数据
|
||
* @returns {Promise}
|
||
*/
|
||
export async function addComment(type, id, data) {
|
||
switch (type) {
|
||
case COMMENT_TYPE.RESOURCE:
|
||
return await addJournal({
|
||
journalized_id: id,
|
||
journalized_type: type,
|
||
...data
|
||
})
|
||
default:
|
||
throw new Error(`Unsupported comment type: ${type}`);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 编辑评论
|
||
* @param {string} type - 评论类型
|
||
* @param {string|number} id - 资源 ID
|
||
* @param {Object} data - 评论数据(包含 id 字段)
|
||
* @returns {Promise}
|
||
*/
|
||
export async function editComment(type, id, data) {
|
||
switch (type) {
|
||
case COMMENT_TYPE.RESOURCE:
|
||
return await editJournal({
|
||
id: id,
|
||
...data
|
||
})
|
||
default:
|
||
throw new Error(`Unsupported comment type: ${type}`);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 删除评论
|
||
* @param {string} type - 评论类型
|
||
* @param {string|number} id - 资源 ID
|
||
* @param {string|number} commentId - 评论 ID
|
||
* @returns {Promise}
|
||
*/
|
||
export async function deleteComment(type, id, commentId) {
|
||
switch (type) {
|
||
case COMMENT_TYPE.RESOURCE:
|
||
return await deleteJournal(commentId)
|
||
default:
|
||
throw new Error(`Unsupported comment type: ${type}`);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @获取文件上传路径
|
||
* pms-gitlink会传到ruby的文件服务
|
||
* contentType: 如果文件上传路径为/api/file/common/upload,需要指定内容属于哪个模块,eg:products/projects/docs/ docs/{projectId}
|
||
*/
|
||
export async function uploadCommentFile(type, data) {
|
||
switch (type) {
|
||
case COMMENT_TYPE.RESOURCE:
|
||
return await uploadFileBySourceJournal(data)
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
export function uploadCommentFileData(type) {
|
||
switch (type) {
|
||
case COMMENT_TYPE.RESOURCE:
|
||
return {
|
||
hierarchy: "Journals",
|
||
type: "ai-resource"
|
||
}
|
||
default:
|
||
break;
|
||
}
|
||
} |