|
|
@@ -281,20 +281,15 @@ export function createCrudRoutes<
|
|
|
|
|
|
// 设置租户上下文
|
|
|
const tenantId = c.get('tenantId');
|
|
|
- console.debug('从Hono上下文中获取租户ID:', tenantId);
|
|
|
- console.debug('从Hono上下文中获取用户对象:', user);
|
|
|
|
|
|
// 优先从tenantId上下文获取,如果没有则从用户对象中提取
|
|
|
let finalTenantId = tenantId;
|
|
|
if (finalTenantId === undefined && user?.tenantId !== undefined) {
|
|
|
finalTenantId = user.tenantId;
|
|
|
- console.debug('从用户对象中提取租户ID:', finalTenantId);
|
|
|
}
|
|
|
|
|
|
if (finalTenantId !== undefined) {
|
|
|
crudService.setTenantContext(finalTenantId);
|
|
|
- } else {
|
|
|
- console.debug('没有找到租户ID');
|
|
|
}
|
|
|
|
|
|
const [data, total] = await crudService.getList(
|
|
|
@@ -309,7 +304,6 @@ export function createCrudRoutes<
|
|
|
user?.id
|
|
|
);
|
|
|
|
|
|
- console.debug('数据库返回的原始数据:', JSON.stringify(data, null, 2));
|
|
|
|
|
|
try {
|
|
|
const validatedData = await parseWithAwait(z.array(listSchema), data);
|
|
|
@@ -319,12 +313,6 @@ export function createCrudRoutes<
|
|
|
}, 200);
|
|
|
} catch (validationError) {
|
|
|
if (validationError instanceof z.ZodError) {
|
|
|
- console.debug('Zod验证错误详情:', validationError);
|
|
|
- console.debug('验证失败的字段:', validationError.errors.map(e => ({
|
|
|
- path: e.path,
|
|
|
- message: e.message,
|
|
|
- code: e.code
|
|
|
- })));
|
|
|
return c.json({
|
|
|
code: 400,
|
|
|
message: '参数验证失败',
|
|
|
@@ -335,7 +323,6 @@ export function createCrudRoutes<
|
|
|
}
|
|
|
} catch (error) {
|
|
|
if (error instanceof z.ZodError) {
|
|
|
- console.debug('Zod验证错误详情:', error);
|
|
|
return c.json({ code: 400, message: '参数验证失败', errors: error.errors || error.message }, 400);
|
|
|
}
|
|
|
return c.json({
|
|
|
@@ -359,26 +346,20 @@ export function createCrudRoutes<
|
|
|
|
|
|
// 设置租户上下文
|
|
|
const tenantId = c.get('tenantId');
|
|
|
- console.debug('从Hono上下文中获取租户ID:', tenantId);
|
|
|
- console.debug('从Hono上下文中获取用户对象:', user);
|
|
|
|
|
|
// 优先从tenantId上下文获取,如果没有则从用户对象中提取
|
|
|
let finalTenantId = tenantId;
|
|
|
if (finalTenantId === undefined && user?.tenantId !== undefined) {
|
|
|
finalTenantId = user.tenantId;
|
|
|
- console.debug('从用户对象中提取租户ID:', finalTenantId);
|
|
|
}
|
|
|
|
|
|
if (finalTenantId !== undefined) {
|
|
|
crudService.setTenantContext(finalTenantId);
|
|
|
- } else {
|
|
|
- console.debug('没有找到租户ID');
|
|
|
}
|
|
|
const result = await crudService.create(data, user?.id);
|
|
|
return c.json(await parseWithAwait(getSchema, result), 201);
|
|
|
} catch (error) {
|
|
|
if (error instanceof z.ZodError) {
|
|
|
- console.debug('Zod验证错误详情:', error);
|
|
|
return c.json({ code: 400, message: '参数验证失败', errors: error.errors || error.message }, 400);
|
|
|
}
|
|
|
|
|
|
@@ -416,20 +397,15 @@ export function createCrudRoutes<
|
|
|
|
|
|
// 设置租户上下文
|
|
|
const tenantId = c.get('tenantId');
|
|
|
- console.debug('从Hono上下文中获取租户ID:', tenantId);
|
|
|
- console.debug('从Hono上下文中获取用户对象:', user);
|
|
|
|
|
|
// 优先从tenantId上下文获取,如果没有则从用户对象中提取
|
|
|
let finalTenantId = tenantId;
|
|
|
if (finalTenantId === undefined && user?.tenantId !== undefined) {
|
|
|
finalTenantId = user.tenantId;
|
|
|
- console.debug('从用户对象中提取租户ID:', finalTenantId);
|
|
|
}
|
|
|
|
|
|
if (finalTenantId !== undefined) {
|
|
|
crudService.setTenantContext(finalTenantId);
|
|
|
- } else {
|
|
|
- console.debug('没有找到租户ID');
|
|
|
}
|
|
|
const result = await crudService.getById(id, relations || [], user?.id);
|
|
|
|
|
|
@@ -451,7 +427,6 @@ export function createCrudRoutes<
|
|
|
return c.json(await parseWithAwait(getSchema, result), 200);
|
|
|
} catch (error) {
|
|
|
if (error instanceof z.ZodError) {
|
|
|
- console.debug('Zod验证错误详情:', error);
|
|
|
return c.json({ code: 400, message: '参数验证失败', errors: error.errors || error.message }, 400);
|
|
|
}
|
|
|
if (error instanceof PermissionError) {
|
|
|
@@ -480,20 +455,15 @@ export function createCrudRoutes<
|
|
|
|
|
|
// 设置租户上下文
|
|
|
const tenantId = c.get('tenantId');
|
|
|
- console.debug('从Hono上下文中获取租户ID:', tenantId);
|
|
|
- console.debug('从Hono上下文中获取用户对象:', user);
|
|
|
|
|
|
// 优先从tenantId上下文获取,如果没有则从用户对象中提取
|
|
|
let finalTenantId = tenantId;
|
|
|
if (finalTenantId === undefined && user?.tenantId !== undefined) {
|
|
|
finalTenantId = user.tenantId;
|
|
|
- console.debug('从用户对象中提取租户ID:', finalTenantId);
|
|
|
}
|
|
|
|
|
|
if (finalTenantId !== undefined) {
|
|
|
crudService.setTenantContext(finalTenantId);
|
|
|
- } else {
|
|
|
- console.debug('没有找到租户ID');
|
|
|
}
|
|
|
const result = await crudService.update(id, data, user?.id);
|
|
|
|
|
|
@@ -504,7 +474,6 @@ export function createCrudRoutes<
|
|
|
return c.json(await parseWithAwait(getSchema, result), 200);
|
|
|
} catch (error) {
|
|
|
if (error instanceof z.ZodError) {
|
|
|
- console.debug('Zod验证错误详情:', error);
|
|
|
return c.json({ code: 400, message: '参数验证失败', errors: error.errors || error.message }, 400);
|
|
|
}
|
|
|
|
|
|
@@ -536,20 +505,15 @@ export function createCrudRoutes<
|
|
|
|
|
|
// 设置租户上下文
|
|
|
const tenantId = c.get('tenantId');
|
|
|
- console.debug('从Hono上下文中获取租户ID:', tenantId);
|
|
|
- console.debug('从Hono上下文中获取用户对象:', user);
|
|
|
|
|
|
// 优先从tenantId上下文获取,如果没有则从用户对象中提取
|
|
|
let finalTenantId = tenantId;
|
|
|
if (finalTenantId === undefined && user?.tenantId !== undefined) {
|
|
|
finalTenantId = user.tenantId;
|
|
|
- console.debug('从用户对象中提取租户ID:', finalTenantId);
|
|
|
}
|
|
|
|
|
|
if (finalTenantId !== undefined) {
|
|
|
crudService.setTenantContext(finalTenantId);
|
|
|
- } else {
|
|
|
- console.debug('没有找到租户ID');
|
|
|
}
|
|
|
const success = await crudService.delete(id, user?.id);
|
|
|
|
|
|
@@ -560,7 +524,6 @@ export function createCrudRoutes<
|
|
|
return c.body(null, 204);
|
|
|
} catch (error) {
|
|
|
if (error instanceof z.ZodError) {
|
|
|
- console.debug('Zod验证错误详情:', error);
|
|
|
return c.json({ code: 400, message: '参数验证失败', errors: error.errors || error.message }, 400);
|
|
|
}
|
|
|
|
|
|
@@ -617,20 +580,15 @@ export function createCrudRoutes<
|
|
|
|
|
|
// 设置租户上下文
|
|
|
const tenantId = c.get('tenantId');
|
|
|
- console.debug('从Hono上下文中获取租户ID:', tenantId);
|
|
|
- console.debug('从Hono上下文中获取用户对象:', user);
|
|
|
|
|
|
// 优先从tenantId上下文获取,如果没有则从用户对象中提取
|
|
|
let finalTenantId = tenantId;
|
|
|
if (finalTenantId === undefined && user?.tenantId !== undefined) {
|
|
|
finalTenantId = user.tenantId;
|
|
|
- console.debug('从用户对象中提取租户ID:', finalTenantId);
|
|
|
}
|
|
|
|
|
|
if (finalTenantId !== undefined) {
|
|
|
crudService.setTenantContext(finalTenantId);
|
|
|
- } else {
|
|
|
- console.debug('没有找到租户ID');
|
|
|
}
|
|
|
|
|
|
const [data, total] = await crudService.getList(
|
|
|
@@ -651,7 +609,6 @@ export function createCrudRoutes<
|
|
|
}, 200);
|
|
|
} catch (error) {
|
|
|
if (error instanceof z.ZodError) {
|
|
|
- console.debug('Zod验证错误详情:', error);
|
|
|
return c.json({ code: 400, message: '参数验证失败', errors: error.errors || error.message }, 400);
|
|
|
}
|
|
|
|
|
|
@@ -684,20 +641,15 @@ export function createCrudRoutes<
|
|
|
|
|
|
// 设置租户上下文
|
|
|
const tenantId = c.get('tenantId');
|
|
|
- console.debug('从Hono上下文中获取租户ID:', tenantId);
|
|
|
- console.debug('从Hono上下文中获取用户对象:', user);
|
|
|
|
|
|
// 优先从tenantId上下文获取,如果没有则从用户对象中提取
|
|
|
let finalTenantId = tenantId;
|
|
|
if (finalTenantId === undefined && user?.tenantId !== undefined) {
|
|
|
finalTenantId = user.tenantId;
|
|
|
- console.debug('从用户对象中提取租户ID:', finalTenantId);
|
|
|
}
|
|
|
|
|
|
if (finalTenantId !== undefined) {
|
|
|
crudService.setTenantContext(finalTenantId);
|
|
|
- } else {
|
|
|
- console.debug('没有找到租户ID');
|
|
|
}
|
|
|
const result = await crudService.getById(id, relations || [], user?.id);
|
|
|
|
|
|
@@ -718,7 +670,6 @@ export function createCrudRoutes<
|
|
|
return c.json(await parseWithAwait(getSchema, result), 200);
|
|
|
} catch (error) {
|
|
|
if (error instanceof z.ZodError) {
|
|
|
- console.debug('Zod验证错误详情:', error);
|
|
|
return c.json({ code: 400, message: '参数验证失败', errors: error.errors || error.message }, 400);
|
|
|
}
|
|
|
if (error instanceof PermissionError) {
|