website refactor
This commit is contained in:
@@ -45,7 +45,7 @@ describe('DashboardController', () => {
|
||||
};
|
||||
mockService.getDashboardOverview.mockResolvedValue(overview);
|
||||
|
||||
const result = await controller.getDashboardOverview(driverId, { user: { userId: driverId } });
|
||||
const result = await controller.getDashboardOverview(driverId, { user: { userId: driverId, primaryDriverId: driverId } });
|
||||
|
||||
expect(mockService.getDashboardOverview).toHaveBeenCalledWith(driverId);
|
||||
expect(result).toEqual(overview);
|
||||
@@ -55,7 +55,7 @@ describe('DashboardController', () => {
|
||||
describe('auth guards (HTTP)', () => {
|
||||
let app: import("@nestjs/common").INestApplication;
|
||||
|
||||
const sessionPort: { getCurrentSession: () => Promise<null | { token: string; user: { id: string } }> } = {
|
||||
const sessionPort: { getCurrentSession: () => Promise<null | { token: string; user: { id: string; primaryDriverId?: string } }> } = {
|
||||
getCurrentSession: vi.fn(async () => null),
|
||||
};
|
||||
|
||||
@@ -128,7 +128,7 @@ describe('DashboardController', () => {
|
||||
it('allows endpoint when authenticated via session port', async () => {
|
||||
vi.mocked(sessionPort.getCurrentSession).mockResolvedValueOnce({
|
||||
token: 't',
|
||||
user: { id: 'user-1' },
|
||||
user: { id: 'user-1', primaryDriverId: 'driver-1' },
|
||||
});
|
||||
|
||||
await request(app.getHttpServer()).get('/dashboard/overview?driverId=d1').expect(200);
|
||||
|
||||
@@ -4,7 +4,7 @@ import { DashboardService } from './DashboardService';
|
||||
import { DashboardOverviewDTO } from './dtos/DashboardOverviewDTO';
|
||||
|
||||
type AuthenticatedRequest = {
|
||||
user?: { userId: string };
|
||||
user?: { userId: string; primaryDriverId?: string };
|
||||
};
|
||||
|
||||
@ApiTags('dashboard')
|
||||
@@ -21,10 +21,10 @@ export class DashboardController {
|
||||
@Query('driverId') _driverId: string,
|
||||
@Req() req: AuthenticatedRequest,
|
||||
): Promise<DashboardOverviewDTO> {
|
||||
const userId = req.user?.userId;
|
||||
if (!userId) {
|
||||
throw new UnauthorizedException('Unauthorized');
|
||||
const driverId = req.user?.primaryDriverId;
|
||||
if (!driverId) {
|
||||
throw new UnauthorizedException('Unauthorized: No driver associated with user');
|
||||
}
|
||||
return this.dashboardService.getDashboardOverview(userId);
|
||||
return this.dashboardService.getDashboardOverview(driverId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user