fix: role-permissions GET/PUT return camelCase (isSystem, roleKey, homePage)
Backend was returning raw Postgres snake_case column names; frontend SavedRolePermission interface expected camelCase. This caused isSystem to always be undefined → all roles treated as custom in UserModal. Also adds home_page to the SELECT so homePage is available. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -29,13 +29,22 @@ const rolePermissionsRoute: FastifyPluginAsync = async (fastify) => {
|
|||||||
if (!hotelId) return reply.code(404).send({ error: 'Hotel not found' })
|
if (!hotelId) return reply.code(404).send({ error: 'Hotel not found' })
|
||||||
|
|
||||||
const { rows } = await db.query(
|
const { rows } = await db.query(
|
||||||
`SELECT id, hotel_id, role_key, name, color, is_system, permissions, created_at, updated_at
|
`SELECT id, hotel_id, role_key, name, color, is_system, permissions, home_page, created_at, updated_at
|
||||||
FROM role_permissions
|
FROM role_permissions
|
||||||
WHERE hotel_id = $1
|
WHERE hotel_id = $1
|
||||||
ORDER BY is_system DESC, name`,
|
ORDER BY is_system DESC, name`,
|
||||||
[hotelId],
|
[hotelId],
|
||||||
)
|
)
|
||||||
return rows
|
return rows.map(r => ({
|
||||||
|
id: r.id,
|
||||||
|
hotelId: r.hotel_id,
|
||||||
|
roleKey: r.role_key,
|
||||||
|
name: r.name,
|
||||||
|
color: r.color,
|
||||||
|
isSystem: r.is_system,
|
||||||
|
permissions: r.permissions,
|
||||||
|
homePage: r.home_page,
|
||||||
|
}))
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -70,7 +79,17 @@ const rolePermissionsRoute: FastifyPluginAsync = async (fastify) => {
|
|||||||
RETURNING *`,
|
RETURNING *`,
|
||||||
[hotelId, roleKey, name, color, isSystem, JSON.stringify(permissions), homePage],
|
[hotelId, roleKey, name, color, isSystem, JSON.stringify(permissions), homePage],
|
||||||
)
|
)
|
||||||
return rows[0]
|
const r = rows[0]
|
||||||
|
return {
|
||||||
|
id: r.id,
|
||||||
|
hotelId: r.hotel_id,
|
||||||
|
roleKey: r.role_key,
|
||||||
|
name: r.name,
|
||||||
|
color: r.color,
|
||||||
|
isSystem: r.is_system,
|
||||||
|
permissions: r.permissions,
|
||||||
|
homePage: r.home_page,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user