feat: comprehensive seed, Lucide icons, grouped dashboard nav, API fixes
- Rewrite prisma/seed.ts to populate all 27 models with realistic Vietnamese real estate data (8 users with login, 10 properties, 10 listings, orders, payments, reviews, notifications, etc.) - Replace all emoji icons with Lucide React SVG icons across frontend for consistent rendering, sizing, and accessibility - Redesign dashboard nav: grouped sidebar with section headers, primary/secondary split on desktop, icon-only secondary items - Replace language switcher flag emoji with Globe icon - Replace SVG theme toggle with Lucide Moon/Sun icons - Fix API startup: graceful fallback for Sentry profiling, Google OAuth, and Zalo OAuth when credentials are not configured - Relax rate limiting in development mode (10k req/min) - Fix listings API to include media[] array in search response - Add optional chaining for property.media across frontend components - Update OAuth strategy tests to match graceful fallback behavior Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -55,17 +55,17 @@ import { AppController } from './app.controller';
|
||||
{
|
||||
name: 'default',
|
||||
ttl: 60_000,
|
||||
limit: process.env['NODE_ENV'] === 'test' ? 10_000 : 60,
|
||||
limit: process.env['NODE_ENV'] === 'test' || process.env['NODE_ENV'] === 'development' ? 10_000 : 60,
|
||||
},
|
||||
{
|
||||
name: 'auth',
|
||||
ttl: 60_000,
|
||||
limit: process.env['NODE_ENV'] === 'test' ? 10_000 : 10,
|
||||
limit: process.env['NODE_ENV'] === 'test' || process.env['NODE_ENV'] === 'development' ? 10_000 : 10,
|
||||
},
|
||||
{
|
||||
name: 'payment-callback',
|
||||
ttl: 60_000,
|
||||
limit: process.env['NODE_ENV'] === 'test' ? 10_000 : 20,
|
||||
limit: process.env['NODE_ENV'] === 'test' || process.env['NODE_ENV'] === 'development' ? 10_000 : 20,
|
||||
},
|
||||
],
|
||||
}),
|
||||
|
||||
@@ -7,9 +7,14 @@ const isTest = process.env['NODE_ENV'] === 'test';
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const integrations: any[] = [];
|
||||
if (!isTest) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/consistent-type-imports
|
||||
const { nodeProfilingIntegration } = require('@sentry/profiling-node') as typeof import('@sentry/profiling-node');
|
||||
integrations.push(nodeProfilingIntegration());
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/consistent-type-imports
|
||||
const { nodeProfilingIntegration } = require('@sentry/profiling-node') as typeof import('@sentry/profiling-node');
|
||||
integrations.push(nodeProfilingIntegration());
|
||||
} catch {
|
||||
// Native CPU profiler binary not available — skip profiling gracefully.
|
||||
console.warn('[Sentry] Profiling skipped — native module not available');
|
||||
}
|
||||
}
|
||||
|
||||
Sentry.init({
|
||||
|
||||
@@ -45,13 +45,12 @@ describe('GoogleOAuthStrategy', () => {
|
||||
vi.unstubAllEnvs();
|
||||
});
|
||||
|
||||
it('throws if GOOGLE_CLIENT_ID is missing', () => {
|
||||
it('creates strategy with dummy config when GOOGLE_CLIENT_ID is missing', async () => {
|
||||
vi.stubEnv('GOOGLE_CLIENT_ID', '');
|
||||
// Reset module to pick up new env
|
||||
expect(async () => {
|
||||
const { GoogleOAuthStrategy } = await import('../strategies/google-oauth.strategy');
|
||||
new GoogleOAuthStrategy(mockOAuthService as unknown as OAuthService);
|
||||
}).rejects.toThrow('GOOGLE_CLIENT_ID');
|
||||
const { GoogleOAuthStrategy } = await import('../strategies/google-oauth.strategy');
|
||||
const strategy = new GoogleOAuthStrategy(mockOAuthService as unknown as OAuthService);
|
||||
// Strategy should still be created (graceful fallback with dummy values)
|
||||
expect(strategy).toBeDefined();
|
||||
});
|
||||
|
||||
it('creates strategy with correct config', async () => {
|
||||
|
||||
@@ -30,18 +30,18 @@ describe('ZaloOAuthStrategy', () => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('throws if ZALO_APP_ID is missing', () => {
|
||||
it('creates strategy with dummy config when ZALO_APP_ID is missing', () => {
|
||||
vi.stubEnv('ZALO_APP_ID', '');
|
||||
const mockLogger = { log: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn(), verbose: vi.fn() };
|
||||
expect(() => new ZaloOAuthStrategy(mockOAuthService as unknown as OAuthService, mockLogger as any))
|
||||
.toThrow('ZALO_APP_ID');
|
||||
const strategy = new ZaloOAuthStrategy(mockOAuthService as unknown as OAuthService, mockLogger as any);
|
||||
expect(strategy).toBeDefined();
|
||||
});
|
||||
|
||||
it('throws if ZALO_APP_SECRET is missing', () => {
|
||||
it('creates strategy with dummy config when ZALO_APP_SECRET is missing', () => {
|
||||
vi.stubEnv('ZALO_APP_SECRET', '');
|
||||
const mockLogger = { log: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn(), verbose: vi.fn() };
|
||||
expect(() => new ZaloOAuthStrategy(mockOAuthService as unknown as OAuthService, mockLogger as any))
|
||||
.toThrow('ZALO_APP_SECRET');
|
||||
const strategy = new ZaloOAuthStrategy(mockOAuthService as unknown as OAuthService, mockLogger as any);
|
||||
expect(strategy).toBeDefined();
|
||||
});
|
||||
|
||||
describe('getAuthorizationUrl', () => {
|
||||
|
||||
@@ -11,7 +11,15 @@ export class GoogleOAuthStrategy extends PassportStrategy(Strategy, 'google') {
|
||||
const callbackURL = process.env['GOOGLE_CALLBACK_URL'] ?? '/auth/google/callback';
|
||||
|
||||
if (!clientID || !clientSecret) {
|
||||
throw new Error('GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET environment variables are required');
|
||||
// Use dummy values so the app can start without Google OAuth configured.
|
||||
// The Google login route will be non-functional until real credentials are set.
|
||||
super({
|
||||
clientID: 'NOT_CONFIGURED',
|
||||
clientSecret: 'NOT_CONFIGURED',
|
||||
callbackURL,
|
||||
scope: ['email', 'profile'],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
super({
|
||||
|
||||
@@ -49,7 +49,11 @@ export class ZaloOAuthStrategy {
|
||||
const appSecret = process.env['ZALO_APP_SECRET'];
|
||||
|
||||
if (!appId || !appSecret) {
|
||||
throw new Error('ZALO_APP_ID and ZALO_APP_SECRET environment variables are required');
|
||||
// Allow app to start without Zalo OAuth configured — routes will be non-functional.
|
||||
this.appId = 'NOT_CONFIGURED';
|
||||
this.appSecret = 'NOT_CONFIGURED';
|
||||
this.callbackUrl = process.env['ZALO_CALLBACK_URL'] ?? '/auth/zalo/callback';
|
||||
return;
|
||||
}
|
||||
|
||||
this.appId = appId;
|
||||
|
||||
@@ -74,6 +74,7 @@ export interface ListingSearchItem {
|
||||
bedrooms: number | null;
|
||||
bathrooms: number | null;
|
||||
thumbnail: string | null;
|
||||
media: ListingMediaData[];
|
||||
};
|
||||
seller: {
|
||||
id: string;
|
||||
@@ -94,5 +95,6 @@ export interface ListingSellerItem {
|
||||
city: string;
|
||||
areaM2: number;
|
||||
thumbnail: string | null;
|
||||
media: ListingMediaData[];
|
||||
};
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ export async function searchListings(
|
||||
include: {
|
||||
property: {
|
||||
include: {
|
||||
media: { orderBy: { order: 'asc' }, take: 1 },
|
||||
media: { orderBy: { order: 'asc' }, take: 5 },
|
||||
},
|
||||
},
|
||||
seller: { select: { id: true, fullName: true } },
|
||||
@@ -135,6 +135,13 @@ export async function searchListings(
|
||||
bedrooms: listing.property.bedrooms,
|
||||
bathrooms: listing.property.bathrooms,
|
||||
thumbnail: listing.property.media[0]?.url ?? null,
|
||||
media: listing.property.media.map((m) => ({
|
||||
id: m.id,
|
||||
url: m.url,
|
||||
type: m.type,
|
||||
order: m.order,
|
||||
caption: m.caption,
|
||||
})),
|
||||
},
|
||||
seller: listing.seller,
|
||||
})),
|
||||
@@ -182,6 +189,13 @@ export async function findBySellerIdQuery(
|
||||
city: listing.property.city,
|
||||
areaM2: listing.property.areaM2,
|
||||
thumbnail: listing.property.media[0]?.url ?? null,
|
||||
media: listing.property.media.map((m) => ({
|
||||
id: m.id,
|
||||
url: m.url,
|
||||
type: m.type,
|
||||
order: m.order,
|
||||
caption: m.caption,
|
||||
})),
|
||||
},
|
||||
})),
|
||||
total,
|
||||
|
||||
Reference in New Issue
Block a user