fix(analytics, prescription, hydration): filter out admin/static asset requests from view counter, support guest prescription upload with fallback UI, and unify Hero component fallbacks with database defaults
Deploy Canina / deploy (push) Waiting to run
Deploy Canina / deploy (push) Waiting to run
This commit is contained in:
1 parent
3e21aefbf1
commit
b617331683
7 files changed
+41
-28
No files matched your search
@@ -101,7 +101,7 @@ export class AdminService {
|
||||
revenue,
|
||||
newOrders,
|
||||
users,
|
||||
todayVisits: todayVisits || 154,
|
||||
todayVisits,
|
||||
categoriesDistribution: [
|
||||
{ name: 'مکمل سگ', value: dogCount || 8 },
|
||||
{ name: 'مکمل گربه', value: catCount || 6 },
|
||||
|
||||
@@ -77,9 +77,19 @@ export class AppModule implements NestModule {
|
||||
consumer
|
||||
.apply((req: any, res: any, next: () => void) => {
|
||||
MetricsController.incrementRequestCount();
|
||||
// Increment daily visits counter in Redis (fire-and-forget)
|
||||
const todayKey = `visits:${new Date().toISOString().split('T')[0]}`;
|
||||
this.redisService.incr(todayKey, 86400).catch(() => {}); // TTL = 24h
|
||||
|
||||
const url: string = req.originalUrl || req.url || '';
|
||||
const method: string = req.method || '';
|
||||
|
||||
// Exclude options, admin panel requests, static assets, and health metrics from visit counter
|
||||
const isAdminPath = url.includes('/admin') || url.includes('/api/admin');
|
||||
const isStaticAsset = url.match(/\.(js|css|png|jpg|jpeg|gif|ico|svg|woff2?|map)$/i);
|
||||
const isIgnoredMethod = method === 'OPTIONS' || method === 'HEAD';
|
||||
|
||||
if (!isAdminPath && !isStaticAsset && !isIgnoredMethod) {
|
||||
const todayKey = `visits:${new Date().toISOString().split('T')[0]}`;
|
||||
this.redisService.incr(todayKey, 86400).catch(() => {});
|
||||
}
|
||||
next();
|
||||
})
|
||||
.exclude('metrics')
|
||||
|
||||
@@ -23,8 +23,6 @@ export interface UserReqPayload {
|
||||
}
|
||||
|
||||
@ApiTags('Prescriptions - نسخه و تاییدیه دارویی')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Controller('prescriptions')
|
||||
export class PrescriptionsController {
|
||||
constructor(private readonly prescriptionsService: PrescriptionsService) {}
|
||||
@@ -35,28 +33,32 @@ export class PrescriptionsController {
|
||||
@Req() req: UserReqPayload,
|
||||
@Body() body: { petId?: string; fileUrl: string; notes?: string },
|
||||
) {
|
||||
const userId = req.user.id || req.user.userId || '';
|
||||
const userId = req.user?.id || req.user?.userId || null;
|
||||
return this.prescriptionsService.create(userId, body);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'دریافت لیست نسخهها (کاربر یا ادمین)' })
|
||||
findAll(@Req() req: UserReqPayload) {
|
||||
const userId = req.user.id || req.user.userId || '';
|
||||
const isAdmin = req.user.role === 'Admin';
|
||||
const isAdmin = req.user.role === 'Admin' || req.user.role === 'ADMIN';
|
||||
return this.prescriptionsService.findAll(userId, isAdmin);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'دریافت جزئیات یک نسخه' })
|
||||
findOne(@Req() req: UserReqPayload, @Param('id') id: string) {
|
||||
const userId = req.user.id || req.user.userId || '';
|
||||
const isAdmin = req.user.role === 'Admin';
|
||||
const isAdmin = req.user.role === 'Admin' || req.user.role === 'ADMIN';
|
||||
return this.prescriptionsService.findOne(id, userId, isAdmin);
|
||||
}
|
||||
|
||||
@UseGuards(RolesGuard)
|
||||
@Roles('Admin')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('Admin', 'ADMIN')
|
||||
@Patch(':id/review')
|
||||
@ApiOperation({ summary: 'بررسی و تایید/رد نسخه دارویی (نیازمند ادمین)' })
|
||||
review(
|
||||
|
||||
@@ -10,12 +10,12 @@ export class PrescriptionsService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
async create(
|
||||
userId: string,
|
||||
userId: string | null,
|
||||
data: { petId?: string; fileUrl: string; notes?: string },
|
||||
) {
|
||||
return this.prisma.prescription.create({
|
||||
data: {
|
||||
userId,
|
||||
userId: userId || undefined,
|
||||
petId: data.petId,
|
||||
fileUrl: data.fileUrl,
|
||||
notes: data.notes,
|
||||
|
||||
Reference in new issue
Block a user