给所有请求都加上jwt,隐藏生成jwt的secret(放到.env中),隐藏app-secret(放在pm2运行配置文件中,后续直接读取环境配置即可)
This commit is contained in:
@@ -129,9 +129,9 @@ interface ScoringProposal {
|
||||
* @param request Remix请求对象,用于获取用户会话
|
||||
* @returns 评查点结果列表和统计数据
|
||||
*/
|
||||
export async function getReviewPoints(fileId: string, request: Request) {
|
||||
export async function getReviewPoints(fileId: string, request: Request) {
|
||||
// 获取用户会话信息
|
||||
const { userInfo } = await getUserSession(request);
|
||||
const { userInfo, frontendJWT } = await getUserSession(request);
|
||||
|
||||
if (!userInfo?.user_id) {
|
||||
console.error("用户身份验证失败");
|
||||
@@ -141,7 +141,7 @@ export async function getReviewPoints(fileId: string, request: Request) {
|
||||
// const userId = userInfo.user_id.toString();
|
||||
|
||||
// 首先先获取这个文档的数据
|
||||
const documentData = await getDocumentWithNoUserId(fileId);
|
||||
const documentData = await getDocumentWithNoUserId(fileId, frontendJWT);
|
||||
if (documentData.error) {
|
||||
console.error("获取文档数据错误:", documentData.error);
|
||||
return Response.json({ error: documentData.error }, { status: documentData.status || 500 });
|
||||
@@ -154,7 +154,8 @@ export async function getReviewPoints(fileId: string, request: Request) {
|
||||
'document_id': `eq.${fileId}`
|
||||
},
|
||||
order: 'id.desc',
|
||||
limit: 1
|
||||
limit: 1,
|
||||
token: frontendJWT
|
||||
};
|
||||
const contractStructureComparisonResponse = await postgrestGet('contract_structure_comparison', contractStructureComparisonParams);
|
||||
|
||||
@@ -195,7 +196,8 @@ export async function getReviewPoints(fileId: string, request: Request) {
|
||||
select: '*',
|
||||
filter: {
|
||||
'document_id': `eq.${fileId}`
|
||||
}
|
||||
},
|
||||
token: frontendJWT
|
||||
};
|
||||
const evaluationResultsResponse = await postgrestGet('evaluation_results', evaluationResultsParams);
|
||||
|
||||
@@ -223,7 +225,8 @@ export async function getReviewPoints(fileId: string, request: Request) {
|
||||
select: '*',
|
||||
filter: {
|
||||
'id': `in.(${evaluationPointIds.join(',')})`
|
||||
}
|
||||
},
|
||||
token: frontendJWT
|
||||
};
|
||||
const evaluationPointsResponse = await postgrestGet('evaluation_points', evaluationPointsParams);
|
||||
|
||||
@@ -249,7 +252,8 @@ export async function getReviewPoints(fileId: string, request: Request) {
|
||||
select: '*',
|
||||
filter: {
|
||||
'id': `in.(${groupIds.join(',')})`
|
||||
}
|
||||
},
|
||||
token: frontendJWT
|
||||
};
|
||||
const groupsResponse = await postgrestGet('evaluation_point_groups', groupsParams);
|
||||
|
||||
@@ -272,7 +276,8 @@ export async function getReviewPoints(fileId: string, request: Request) {
|
||||
filter: {
|
||||
'document_id': `eq.${fileId}`,
|
||||
'evaluation_point_id': `in.(${manualReviewPointsIds.join(',')})`
|
||||
}
|
||||
},
|
||||
token: frontendJWT
|
||||
};
|
||||
const manualReviewPointsResponse = await postgrestGet('audit_status', manualReviewPointsParams);
|
||||
if (manualReviewPointsResponse.error) {
|
||||
@@ -326,7 +331,8 @@ export async function getReviewPoints(fileId: string, request: Request) {
|
||||
filter: {
|
||||
'document_id': `eq.${fileId}`,
|
||||
'deleted_at': `is.null`
|
||||
}
|
||||
},
|
||||
token: frontendJWT
|
||||
};
|
||||
const scoringProposalsResponse = await postgrestGet('cross_scoring_proposals', scoringProposalsParams);
|
||||
|
||||
@@ -754,7 +760,7 @@ export async function updateReviewResult(
|
||||
}> {
|
||||
try {
|
||||
// 获取用户会话信息
|
||||
const { userInfo } = await getUserSession(request);
|
||||
const { userInfo, frontendJWT } = await getUserSession(request);
|
||||
|
||||
if (!userInfo?.user_id) {
|
||||
console.error("用户身份验证失败");
|
||||
@@ -770,7 +776,8 @@ export async function updateReviewResult(
|
||||
// 首先获取当前评查结果数据
|
||||
const currentResultResponse = await postgrestGet('evaluation_results', {
|
||||
select: '*',
|
||||
filter: { id: `eq.${resultId}` }
|
||||
filter: { id: `eq.${resultId}` },
|
||||
token: frontendJWT
|
||||
});
|
||||
|
||||
if (currentResultResponse.error) {
|
||||
@@ -805,7 +812,8 @@ export async function updateReviewResult(
|
||||
const resultResponse = await postgrestPut<unknown, typeof updatedData>(
|
||||
'evaluation_results',
|
||||
updatedData,
|
||||
{ id: resultId }
|
||||
{ id: resultId },
|
||||
frontendJWT
|
||||
);
|
||||
|
||||
if (resultResponse.error) {
|
||||
@@ -830,7 +838,8 @@ export async function updateReviewResult(
|
||||
{
|
||||
id: editAuditStatusId,
|
||||
user_id: userId // 添加用户ID条件,确保只能更新自己的记录
|
||||
}
|
||||
},
|
||||
frontendJWT
|
||||
);
|
||||
|
||||
if (auditStatusResponse.error) {
|
||||
@@ -853,7 +862,7 @@ export async function updateReviewResult(
|
||||
};
|
||||
|
||||
// 使用postgrestPost创建新记录
|
||||
const postResponse = await postgrestPost('audit_status', newAuditStatus);
|
||||
const postResponse = await postgrestPost('audit_status', newAuditStatus, frontendJWT);
|
||||
|
||||
if (postResponse.error) {
|
||||
return { error: postResponse.error, status: postResponse.status || 500 };
|
||||
@@ -889,7 +898,7 @@ export async function confirmReviewResults(documentId: string, request: Request)
|
||||
}> {
|
||||
try {
|
||||
// 获取用户会话信息
|
||||
const { userInfo } = await getUserSession(request);
|
||||
const { userInfo, frontendJWT } = await getUserSession(request);
|
||||
|
||||
if (!userInfo?.user_id) {
|
||||
console.error("用户身份验证失败");
|
||||
@@ -932,7 +941,8 @@ export async function confirmReviewResults(documentId: string, request: Request)
|
||||
{
|
||||
id: documentId,
|
||||
user_id: userId // 添加用户ID条件,确保只能更新自己的文档
|
||||
}
|
||||
},
|
||||
frontendJWT
|
||||
);
|
||||
|
||||
if (response.error) {
|
||||
|
||||
@@ -68,9 +68,10 @@ function extractApiData<T>(responseData: unknown): T | null {
|
||||
|
||||
/**
|
||||
* 获取评查点分组列表
|
||||
* @param token JWT token (可选)
|
||||
* @returns 评查点分组列表
|
||||
*/
|
||||
export async function getRuleGroups(): Promise<{data: RuleGroup[]; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
export async function getRuleGroups(token?: string): Promise<{data: RuleGroup[]; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
try {
|
||||
const params: PostgrestParams = {
|
||||
select: `
|
||||
@@ -84,7 +85,8 @@ export async function getRuleGroups(): Promise<{data: RuleGroup[]; error?: never
|
||||
`,
|
||||
filter: {
|
||||
'pid': 'eq.0'
|
||||
}
|
||||
},
|
||||
token
|
||||
};
|
||||
|
||||
const response = await postgrestGet<{code: number; msg: string; data: Array<{
|
||||
@@ -138,9 +140,10 @@ export async function getRuleGroups(): Promise<{data: RuleGroup[]; error?: never
|
||||
/**
|
||||
* 获取指定分组的子分组
|
||||
* @param parentId 父分组ID
|
||||
* @param token JWT token (可选)
|
||||
* @returns 子分组列表
|
||||
*/
|
||||
export async function getChildGroups(parentId: string): Promise<{data: RuleGroup[]; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
export async function getChildGroups(parentId: string, token?: string): Promise<{data: RuleGroup[]; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
try {
|
||||
// 1. 获取子分组
|
||||
const childGroupsParams: PostgrestParams = {
|
||||
@@ -154,7 +157,8 @@ export async function getChildGroups(parentId: string): Promise<{data: RuleGroup
|
||||
`,
|
||||
filter: {
|
||||
'pid': `eq.${parentId}`
|
||||
}
|
||||
},
|
||||
token
|
||||
};
|
||||
|
||||
const childGroupsResponse = await postgrestGet<{code: number; msg: string; data: Array<{
|
||||
@@ -179,7 +183,8 @@ export async function getChildGroups(parentId: string): Promise<{data: RuleGroup
|
||||
select: 'id',
|
||||
filter: {
|
||||
'evaluation_point_groups_id': `eq.${group.id}`
|
||||
}
|
||||
},
|
||||
token
|
||||
};
|
||||
|
||||
const ruleCountResponse = await postgrestGet<ApiResponse<Array<{id: number}>>>('evaluation_points', ruleCountParams);
|
||||
@@ -203,7 +208,8 @@ export async function getChildGroups(parentId: string): Promise<{data: RuleGroup
|
||||
select: 'id',
|
||||
filter: {
|
||||
'evaluation_point_groups_id': `eq.${group.id}`
|
||||
}
|
||||
},
|
||||
token
|
||||
};
|
||||
|
||||
const ruleCountResponse = await postgrestGet<ApiResponse<Array<{id: number}>>>('evaluation_points', ruleCountParams);
|
||||
@@ -234,9 +240,10 @@ export async function getChildGroups(parentId: string): Promise<{data: RuleGroup
|
||||
|
||||
/**
|
||||
* 获取所有评查点分组(包括一级和二级)
|
||||
* @param token JWT token (可选)
|
||||
* @returns 完整的评查点分组列表
|
||||
*/
|
||||
export async function getAllRuleGroups(): Promise<{data: RuleGroup[]; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
export async function getAllRuleGroups(token?: string): Promise<{data: RuleGroup[]; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
try {
|
||||
// 1. 获取所有分组
|
||||
const allGroupsParams: PostgrestParams = {
|
||||
@@ -245,7 +252,8 @@ export async function getAllRuleGroups(): Promise<{data: RuleGroup[]; error?: ne
|
||||
pid,
|
||||
name,
|
||||
is_enabled
|
||||
`
|
||||
`,
|
||||
token
|
||||
};
|
||||
|
||||
const allGroupsResponse = await postgrestGet<{code: number; msg: string; data: Array<{
|
||||
@@ -292,7 +300,8 @@ export async function getAllRuleGroups(): Promise<{data: RuleGroup[]; error?: ne
|
||||
select: 'id',
|
||||
filter: {
|
||||
'evaluation_point_groups_id': `eq.${child.id}`
|
||||
}
|
||||
},
|
||||
token
|
||||
};
|
||||
|
||||
const ruleCountResponse = await postgrestGet<ApiResponse<Array<{id: number}>>>('evaluation_points', ruleCountParams);
|
||||
@@ -316,9 +325,10 @@ export async function getAllRuleGroups(): Promise<{data: RuleGroup[]; error?: ne
|
||||
/**
|
||||
* 获取单个评查点分组详情
|
||||
* @param id 分组ID
|
||||
* @param token JWT token (可选)
|
||||
* @returns 分组详情
|
||||
*/
|
||||
export async function getRuleGroup(id: string): Promise<{data: RuleGroup; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
export async function getRuleGroup(id: string, token?: string): Promise<{data: RuleGroup; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
try {
|
||||
if (!id) {
|
||||
return { error: '分组ID不能为空', status: 400 };
|
||||
@@ -336,7 +346,8 @@ export async function getRuleGroup(id: string): Promise<{data: RuleGroup; error?
|
||||
`,
|
||||
filter: {
|
||||
'id': `eq.${id}`
|
||||
}
|
||||
},
|
||||
token
|
||||
};
|
||||
|
||||
const response = await postgrestGet<{code: number; msg: string; data: Array<{
|
||||
@@ -389,7 +400,8 @@ export async function getRuleGroup(id: string): Promise<{data: RuleGroup; error?
|
||||
select: 'id',
|
||||
filter: {
|
||||
'evaluation_point_groups_id': `eq.${group.id}`
|
||||
}
|
||||
},
|
||||
token
|
||||
};
|
||||
|
||||
const ruleCountResponse = await postgrestGet<ApiResponse<Array<{id: number}>>>('evaluation_points', ruleCountParams);
|
||||
@@ -412,9 +424,10 @@ export async function getRuleGroup(id: string): Promise<{data: RuleGroup; error?
|
||||
/**
|
||||
* 创建评查点分组
|
||||
* @param groupData 分组数据
|
||||
* @param token JWT token (可选)
|
||||
* @returns 创建的分组
|
||||
*/
|
||||
export async function createRuleGroup(groupData: RuleGroupCreateUpdateDto): Promise<{data: RuleGroup; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
export async function createRuleGroup(groupData: RuleGroupCreateUpdateDto, token?: string): Promise<{data: RuleGroup; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
try {
|
||||
// 验证必填字段
|
||||
if (!groupData.name || !groupData.code) {
|
||||
@@ -447,7 +460,8 @@ export async function createRuleGroup(groupData: RuleGroupCreateUpdateDto): Prom
|
||||
// 直接发送到 PostgreSQL 表
|
||||
const response = await postgrestPost<ApiResponse<ApiRuleGroup> | ApiRuleGroup, ApiRuleGroup>(
|
||||
'evaluation_point_groups', // 表名
|
||||
apiGroup
|
||||
apiGroup,
|
||||
token
|
||||
);
|
||||
|
||||
if (response.error) {
|
||||
@@ -490,15 +504,17 @@ export async function createRuleGroup(groupData: RuleGroupCreateUpdateDto): Prom
|
||||
* 更新评查点分组
|
||||
* @param id 分组ID
|
||||
* @param data 更新的分组数据
|
||||
* @param token JWT token (可选)
|
||||
* @returns 更新后的分组
|
||||
*/
|
||||
export async function updateRuleGroup(id: string, data: RuleGroupCreateUpdateDto): Promise<{data: RuleGroup; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
export async function updateRuleGroup(id: string, data: RuleGroupCreateUpdateDto, token?: string): Promise<{data: RuleGroup; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
try {
|
||||
// 使用新的filters参数
|
||||
const response = await postgrestPut<ApiResponse<RuleGroup> | RuleGroup, RuleGroupCreateUpdateDto>(
|
||||
'evaluation_point_groups',
|
||||
data,
|
||||
{ id }
|
||||
{ id },
|
||||
token
|
||||
);
|
||||
|
||||
if (response.error) {
|
||||
@@ -524,12 +540,13 @@ export async function updateRuleGroup(id: string, data: RuleGroupCreateUpdateDto
|
||||
/**
|
||||
* 删除评查点分组
|
||||
* @param id 分组ID
|
||||
* @param token JWT token (可选)
|
||||
* @returns 删除结果
|
||||
*/
|
||||
export async function deleteRuleGroup(id: string): Promise<{success: boolean; error?: string}> {
|
||||
export async function deleteRuleGroup(id: string, token?: string): Promise<{success: boolean; error?: string}> {
|
||||
try {
|
||||
// 1. 首先获取分组信息,判断是一级还是二级分组
|
||||
const groupResponse = await getRuleGroup(id);
|
||||
const groupResponse = await getRuleGroup(id, token);
|
||||
if (groupResponse.error) {
|
||||
return { success: false, error: groupResponse.error };
|
||||
}
|
||||
@@ -542,7 +559,7 @@ export async function deleteRuleGroup(id: string): Promise<{success: boolean; er
|
||||
// 2. 如果是一级分组,需要先删除所有子分组
|
||||
if (group.pid === '0') {
|
||||
// 获取所有子分组
|
||||
const childGroupsResponse = await getChildGroups(id);
|
||||
const childGroupsResponse = await getChildGroups(id, token);
|
||||
if (childGroupsResponse.error) {
|
||||
return { success: false, error: childGroupsResponse.error };
|
||||
}
|
||||
@@ -551,7 +568,7 @@ export async function deleteRuleGroup(id: string): Promise<{success: boolean; er
|
||||
|
||||
// 遍历删除每个子分组
|
||||
for (const childGroup of childGroups) {
|
||||
const deleteChildResult = await deleteChildGroup(childGroup.id);
|
||||
const deleteChildResult = await deleteChildGroup(childGroup.id, token);
|
||||
if (!deleteChildResult.success) {
|
||||
return deleteChildResult;
|
||||
}
|
||||
@@ -559,7 +576,7 @@ export async function deleteRuleGroup(id: string): Promise<{success: boolean; er
|
||||
}
|
||||
|
||||
// 3. 删除分组下的所有评查点
|
||||
const deletePointsResult = await deleteEvaluationPointsByGroupId(id);
|
||||
const deletePointsResult = await deleteEvaluationPointsByGroupId(id, token);
|
||||
if (!deletePointsResult.success) {
|
||||
return deletePointsResult;
|
||||
}
|
||||
@@ -568,7 +585,8 @@ export async function deleteRuleGroup(id: string): Promise<{success: boolean; er
|
||||
const response = await postgrestDelete<ApiResponse<{id: number}>>('evaluation_point_groups', {
|
||||
filter: {
|
||||
'id': `eq.${id}`
|
||||
}
|
||||
},
|
||||
token
|
||||
});
|
||||
|
||||
if (response.error) {
|
||||
@@ -588,12 +606,13 @@ export async function deleteRuleGroup(id: string): Promise<{success: boolean; er
|
||||
/**
|
||||
* 删除子分组及其相关数据
|
||||
* @param id 子分组ID
|
||||
* @param token JWT token (可选)
|
||||
* @returns 删除结果
|
||||
*/
|
||||
async function deleteChildGroup(id: string): Promise<{success: boolean; error?: string}> {
|
||||
async function deleteChildGroup(id: string, token?: string): Promise<{success: boolean; error?: string}> {
|
||||
try {
|
||||
// 1. 删除子分组下的所有评查点
|
||||
const deletePointsResult = await deleteEvaluationPointsByGroupId(id);
|
||||
const deletePointsResult = await deleteEvaluationPointsByGroupId(id, token);
|
||||
if (!deletePointsResult.success) {
|
||||
return deletePointsResult;
|
||||
}
|
||||
@@ -602,7 +621,8 @@ async function deleteChildGroup(id: string): Promise<{success: boolean; error?:
|
||||
const response = await postgrestDelete<ApiResponse<{id: number}>>('evaluation_point_groups', {
|
||||
filter: {
|
||||
'id': `eq.${id}`
|
||||
}
|
||||
},
|
||||
token
|
||||
});
|
||||
|
||||
if (response.error) {
|
||||
@@ -622,14 +642,16 @@ async function deleteChildGroup(id: string): Promise<{success: boolean; error?:
|
||||
/**
|
||||
* 删除指定分组下的所有评查点
|
||||
* @param groupId 分组ID
|
||||
* @param token JWT token (可选)
|
||||
* @returns 删除结果
|
||||
*/
|
||||
async function deleteEvaluationPointsByGroupId(groupId: string): Promise<{success: boolean; error?: string}> {
|
||||
async function deleteEvaluationPointsByGroupId(groupId: string, token?: string): Promise<{success: boolean; error?: string}> {
|
||||
try {
|
||||
const response = await postgrestDelete<ApiResponse<{id: number}>>('evaluation_points', {
|
||||
filter: {
|
||||
'evaluation_point_groups_id': `eq.${groupId}`
|
||||
}
|
||||
},
|
||||
token
|
||||
});
|
||||
|
||||
if (response.error) {
|
||||
|
||||
@@ -100,6 +100,7 @@ export interface DocumentSearchParams {
|
||||
sortOrder?: string; // 排序方式
|
||||
page?: number; // 当前页码
|
||||
pageSize?: number; // 每页条数
|
||||
token?: string; // JWT token
|
||||
}
|
||||
|
||||
|
||||
@@ -168,7 +169,8 @@ export async function getReviewFiles(searchParams: DocumentSearchParams = {}, do
|
||||
reviewStatus,
|
||||
dateFrom,
|
||||
dateTo,
|
||||
sortOrder = 'upload_time_desc'
|
||||
sortOrder = 'upload_time_desc',
|
||||
token
|
||||
} = searchParams;
|
||||
|
||||
let p_typeid: number[] | null = null;
|
||||
@@ -204,8 +206,8 @@ export async function getReviewFiles(searchParams: DocumentSearchParams = {}, do
|
||||
|
||||
// 并行执行获取数据和获取总数的请求
|
||||
const [filesResponse, countResponse] = await Promise.all([
|
||||
postgrestPost<ReviewFileFromSQL[]>('rpc/get_review_files_with_details', listParams),
|
||||
postgrestPost<number>('rpc/count_review_files', rpcParams)
|
||||
postgrestPost<ReviewFileFromSQL[]>('rpc/get_review_files_with_details', listParams, token),
|
||||
postgrestPost<number>('rpc/count_review_files', rpcParams, token)
|
||||
]);
|
||||
|
||||
// 处理获取文档列表的错误
|
||||
@@ -316,9 +318,10 @@ export async function getReviewFiles(searchParams: DocumentSearchParams = {}, do
|
||||
* @param id 文件ID
|
||||
* @param auditStatus 审核状态
|
||||
* @param userId 用户ID
|
||||
* @param token JWT token (可选)
|
||||
* @returns 更新结果
|
||||
*/
|
||||
export async function updateDocumentAuditStatus(id: string, auditStatus: number, userId: string): Promise<{
|
||||
export async function updateDocumentAuditStatus(id: string, auditStatus: number, userId: string, token?: string): Promise<{
|
||||
success?: boolean;
|
||||
error?: string;
|
||||
status?: number;
|
||||
@@ -338,7 +341,8 @@ export async function updateDocumentAuditStatus(id: string, auditStatus: number,
|
||||
{
|
||||
id: parseInt(id),
|
||||
user_id: parseInt(userId) // 确保只能更新自己的文档
|
||||
}
|
||||
},
|
||||
token
|
||||
);
|
||||
|
||||
if (response.error) {
|
||||
|
||||
@@ -35,6 +35,7 @@ export interface RulesQueryParams {
|
||||
orderBy?: string;
|
||||
orderDirection?: 'asc' | 'desc';
|
||||
reviewType?: string; // 添加 reviewType 参数,值为 contract 或 record
|
||||
token?: string; // JWT token
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,7 +165,8 @@ export async function getRulesList(params: RulesQueryParams): Promise<{data: Rul
|
||||
keyword,
|
||||
orderBy = 'created_at',
|
||||
orderDirection = 'desc',
|
||||
reviewType
|
||||
reviewType,
|
||||
token
|
||||
} = params;
|
||||
|
||||
// 构建PostgrestParams参数
|
||||
@@ -194,7 +196,8 @@ export async function getRulesList(params: RulesQueryParams): Promise<{data: Rul
|
||||
// 添加额外头部,用于获取总记录数
|
||||
headers: {
|
||||
'Prefer': 'count=exact'
|
||||
}
|
||||
},
|
||||
token
|
||||
};
|
||||
|
||||
// 添加精确匹配过滤:规则组ID
|
||||
@@ -211,7 +214,8 @@ export async function getRulesList(params: RulesQueryParams): Promise<{data: Rul
|
||||
try {
|
||||
// 先获取所有评查点组数据,用于找到对应的pid
|
||||
const groupsAllResponse = await postgrestGet<{code: number; msg: string; data: Array<{id: number; pid: number}>}>('evaluation_point_groups', {
|
||||
select: 'id,pid'
|
||||
select: 'id,pid',
|
||||
token
|
||||
});
|
||||
|
||||
let groups: Array<{id: number; pid: number}> = [];
|
||||
@@ -254,7 +258,8 @@ export async function getRulesList(params: RulesQueryParams): Promise<{data: Rul
|
||||
select: 'id',
|
||||
filter: {
|
||||
'pid': `eq.${ruleType}`
|
||||
}
|
||||
},
|
||||
token
|
||||
};
|
||||
|
||||
const groupsResponse = await postgrestGet<{code: number; msg: string; data: Array<{id: number}>}>('evaluation_point_groups', groupsParams);
|
||||
@@ -364,7 +369,8 @@ export async function getRulesList(params: RulesQueryParams): Promise<{data: Rul
|
||||
// 使用Promise.all并行查询所有分组信息 - 使用正确的函数名
|
||||
const groupPromises = validGroupIds.map(id =>
|
||||
postgrestGet<{code: number; msg: string; data: {id: number; pid: number; name: string; first_name: string; second_name: string}[]}>(
|
||||
`rpc/get_evaluation_point_group_with_pid?input_id=${id}`
|
||||
`rpc/get_evaluation_point_group_with_pid?input_id=${id}`,
|
||||
{ token }
|
||||
)
|
||||
);
|
||||
|
||||
@@ -447,9 +453,10 @@ export async function getRulesList(params: RulesQueryParams): Promise<{data: Rul
|
||||
/**
|
||||
* 获取单个评查点详情
|
||||
* @param id 评查点ID
|
||||
* @param token JWT token (可选)
|
||||
* @returns 评查点详情
|
||||
*/
|
||||
export async function getRule(id: string): Promise<{data: Rule; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
export async function getRule(id: string, token?: string): Promise<{data: Rule; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
try {
|
||||
// 使用postgrestGet获取单个评查点数据
|
||||
const postgrestParams: PostgrestParams = {
|
||||
@@ -473,7 +480,8 @@ export async function getRule(id: string): Promise<{data: Rule; error?: never} |
|
||||
action_config,
|
||||
created_at,
|
||||
updated_at
|
||||
`
|
||||
`,
|
||||
token
|
||||
};
|
||||
|
||||
// 获取评查点详情
|
||||
@@ -498,7 +506,8 @@ export async function getRule(id: string): Promise<{data: Rule; error?: never} |
|
||||
select: 'id,name',
|
||||
filter: {
|
||||
'id': `eq.${apiRule.evaluation_point_groups_id}`
|
||||
}
|
||||
},
|
||||
token
|
||||
};
|
||||
|
||||
// 查询评查点分组
|
||||
@@ -538,9 +547,10 @@ export async function getRule(id: string): Promise<{data: Rule; error?: never} |
|
||||
/**
|
||||
* 创建新评查点
|
||||
* @param ruleData 评查点数据
|
||||
* @param token JWT token (可选)
|
||||
* @returns 创建的评查点
|
||||
*/
|
||||
export async function createRule(ruleData: Omit<Rule, 'id' | 'createdAt' | 'updatedAt'>): Promise<{data: Rule; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
export async function createRule(ruleData: Omit<Rule, 'id' | 'createdAt' | 'updatedAt'>, token?: string): Promise<{data: Rule; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
try {
|
||||
// 将前端模型转换为API接受的格式
|
||||
const apiRuleData = {
|
||||
@@ -569,7 +579,7 @@ export async function createRule(ruleData: Omit<Rule, 'id' | 'createdAt' | 'upda
|
||||
};
|
||||
|
||||
// 使用postgrestPost创建评查点
|
||||
const response = await postgrestPost<{code: number; msg: string; data: ApiRule}, typeof apiRuleData>('evaluation_points', apiRuleData);
|
||||
const response = await postgrestPost<{code: number; msg: string; data: ApiRule}, typeof apiRuleData>('evaluation_points', apiRuleData, token);
|
||||
|
||||
// 检查是否有错误响应
|
||||
if (response.error) {
|
||||
@@ -598,9 +608,10 @@ export async function createRule(ruleData: Omit<Rule, 'id' | 'createdAt' | 'upda
|
||||
* 更新评查点
|
||||
* @param id 评查点ID
|
||||
* @param ruleData 评查点数据
|
||||
* @param token JWT token (可选)
|
||||
* @returns 更新后的评查点
|
||||
*/
|
||||
export async function updateRule(id: string, ruleData: Partial<Omit<Rule, 'id' | 'createdAt' | 'updatedAt'>>): Promise<{data: Rule; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
export async function updateRule(id: string, ruleData: Partial<Omit<Rule, 'id' | 'createdAt' | 'updatedAt'>>, token?: string): Promise<{data: Rule; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
try {
|
||||
// 构建API接受的更新数据
|
||||
const apiRuleData: Record<string, unknown> = {};
|
||||
@@ -630,7 +641,7 @@ export async function updateRule(id: string, ruleData: Partial<Omit<Rule, 'id' |
|
||||
}
|
||||
|
||||
// 使用postgrestPut更新评查点
|
||||
const response = await postgrestPut<{code: number; msg: string; data: ApiRule}, typeof apiRuleData>(`evaluation_points/${id}`, apiRuleData);
|
||||
const response = await postgrestPut<{code: number; msg: string; data: ApiRule}, typeof apiRuleData>(`evaluation_points/${id}`, apiRuleData, undefined, token);
|
||||
|
||||
// 检查是否有错误响应
|
||||
if (response.error) {
|
||||
@@ -658,9 +669,10 @@ export async function updateRule(id: string, ruleData: Partial<Omit<Rule, 'id' |
|
||||
/**
|
||||
* 删除评查点
|
||||
* @param id 评查点ID
|
||||
* @param token JWT token (可选)
|
||||
* @returns 删除结果
|
||||
*/
|
||||
export async function deleteRule(id: string): Promise<{data: Rule; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
export async function deleteRule(id: string, token?: string): Promise<{data: Rule; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
try {
|
||||
// console.log(`开始删除评查点, ID: ${id}`);
|
||||
|
||||
@@ -671,7 +683,8 @@ export async function deleteRule(id: string): Promise<{data: Rule; error?: never
|
||||
},
|
||||
headers: {
|
||||
'Prefer': 'return=representation' // 请求返回被删除的记录
|
||||
}
|
||||
},
|
||||
token
|
||||
};
|
||||
|
||||
// 使用postgrestDelete删除评查点
|
||||
@@ -771,12 +784,13 @@ export async function deleteRule(id: string): Promise<{data: Rule; error?: never
|
||||
/**
|
||||
* 复制评查点
|
||||
* @param id 评查点ID
|
||||
* @param token JWT token (可选)
|
||||
* @returns 新创建的评查点
|
||||
*/
|
||||
export async function duplicateRule(id: string): Promise<{data: Rule; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
export async function duplicateRule(id: string, token?: string): Promise<{data: Rule; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
try {
|
||||
// 1. 获取原评查点详情
|
||||
const ruleResponse = await getRule(id);
|
||||
const ruleResponse = await getRule(id, token);
|
||||
|
||||
if (ruleResponse.error || !ruleResponse.data) {
|
||||
return { error: ruleResponse.error || '获取评查点详情失败', status: 500 };
|
||||
@@ -798,7 +812,7 @@ export async function duplicateRule(id: string): Promise<{data: Rule; error?: ne
|
||||
};
|
||||
|
||||
// 3. 创建新评查点
|
||||
return createRule(newRuleData);
|
||||
return createRule(newRuleData, token);
|
||||
|
||||
} catch (error) {
|
||||
console.error('复制评查点出错:', error);
|
||||
@@ -833,9 +847,10 @@ export interface RuleGroup {
|
||||
/**
|
||||
* 获取评查点类型列表
|
||||
* @param reviewType 评查类型,contract表示合同,record表示卷宗
|
||||
* @param token JWT token (可选)
|
||||
* @returns 评查点类型列表
|
||||
*/
|
||||
export async function getRuleTypes(reviewType?: string): Promise<{data: RuleType[]; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
export async function getRuleTypes(reviewType?: string, token?: string): Promise<{data: RuleType[]; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
try {
|
||||
// 构建PostgrestParams参数
|
||||
const postgrestParams: PostgrestParams = {
|
||||
@@ -850,7 +865,8 @@ export async function getRuleTypes(reviewType?: string): Promise<{data: RuleType
|
||||
// 查询父ID为0的类型(顶级类型)
|
||||
filter: {
|
||||
'pid': 'eq.0'
|
||||
}
|
||||
},
|
||||
token
|
||||
};
|
||||
|
||||
// 根据 reviewType 添加过滤条件
|
||||
@@ -919,9 +935,10 @@ export async function getRuleTypes(reviewType?: string): Promise<{data: RuleType
|
||||
/**
|
||||
* 根据评查点类型ID获取规则组列表
|
||||
* @param typeId 评查点类型ID
|
||||
* @param token JWT token (可选)
|
||||
* @returns 规则组列表
|
||||
*/
|
||||
export async function getRuleGroupsByType(typeId: string): Promise<{data: RuleGroup[]; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
export async function getRuleGroupsByType(typeId: string, token?: string): Promise<{data: RuleGroup[]; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
try {
|
||||
// 如果typeId为空或为"全部",则返回空数组
|
||||
if (!typeId || typeId === 'all') {
|
||||
@@ -941,7 +958,8 @@ export async function getRuleGroupsByType(typeId: string): Promise<{data: RuleGr
|
||||
// 查询指定类型ID的规则组
|
||||
filter: {
|
||||
'pid': `eq.${typeId}`
|
||||
}
|
||||
},
|
||||
token
|
||||
};
|
||||
|
||||
// 发送请求获取规则组列表
|
||||
|
||||
Reference in New Issue
Block a user