给所有请求都加上jwt,隐藏生成jwt的secret(放到.env中),隐藏app-secret(放在pm2运行配置文件中,后续直接读取环境配置即可)
This commit is contained in:
@@ -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