feat: route permission guards, home page per role — RolePermissionsContext, PermissionGuard, App routes, DB migration

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-20 10:50:22 +03:00
parent 80429cd52a
commit a701366216
5 changed files with 129 additions and 56 deletions

View File

@@ -41,7 +41,7 @@ const rolePermissionsRoute: FastifyPluginAsync = async (fastify) => {
// ── PUT /api/hotels/:slug/role-permissions/:roleKey ────────────────────────
fastify.put<SlugRoleParam & {
Body: { name: string; color: string; isSystem?: boolean; permissions: Record<string, boolean> }
Body: { name: string; color: string; isSystem?: boolean; permissions: Record<string, boolean>; homePage?: string }
}>(
'/api/hotels/:slug/role-permissions/:roleKey',
{ onRequest: [fastify.authenticate] },
@@ -56,18 +56,19 @@ const rolePermissionsRoute: FastifyPluginAsync = async (fastify) => {
const hotelId = await getHotelId(slug)
if (!hotelId) return reply.code(404).send({ error: 'Hotel not found' })
const { name, color, isSystem = false, permissions } = request.body
const { name, color, isSystem = false, permissions, homePage = null } = request.body
const { rows } = await db.query(
`INSERT INTO role_permissions (hotel_id, role_key, name, color, is_system, permissions)
VALUES ($1, $2, $3, $4, $5, $6)
`INSERT INTO role_permissions (hotel_id, role_key, name, color, is_system, permissions, home_page)
VALUES ($1, $2, $3, $4, $5, $6, $7)
ON CONFLICT (hotel_id, role_key) DO UPDATE
SET name = EXCLUDED.name,
color = EXCLUDED.color,
permissions = EXCLUDED.permissions,
home_page = EXCLUDED.home_page,
updated_at = NOW()
RETURNING *`,
[hotelId, roleKey, name, color, isSystem, JSON.stringify(permissions)],
[hotelId, roleKey, name, color, isSystem, JSON.stringify(permissions), homePage],
)
return rows[0]
},