mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
Show relevant advertisements on the calendar based on store participation
Update client-side filtering logic to correctly display advertisements based on selected store or user group affiliations, and adjust backend query to fetch participation data. Replit-Commit-Author: Agent Replit-Commit-Session-Id: b163d4c0-de5e-4f4e-a9c0-aed4c7049718 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/b163d4c0-de5e-4f4e-a9c0-aed4c7049718/ByygiiM
This commit is contained in:
1 parent
745ddc6805
commit
e627ff650d
2 files changed
+41
-6
No files matched your search
@@ -178,6 +178,17 @@ export default function CalendarGrid({
|
||||
const getPublicitiesForDate = (date: Date) => {
|
||||
const dateStr = format(date, 'yyyy-MM-dd');
|
||||
|
||||
console.log('🔍 CalendarGrid getPublicitiesForDate:', {
|
||||
date: dateStr,
|
||||
totalPublicities: publicities.length,
|
||||
selectedStoreId,
|
||||
userGroups: userGroups.length
|
||||
});
|
||||
|
||||
if (publicities.length > 0) {
|
||||
console.log('📄 Sample publicity structure:', publicities[0]);
|
||||
}
|
||||
|
||||
return publicities.filter(pub => {
|
||||
// Check if the date is within the publicity period
|
||||
const pubStart = pub.startDate;
|
||||
@@ -194,14 +205,22 @@ export default function CalendarGrid({
|
||||
|
||||
// If a specific store is selected, check if that store participates
|
||||
if (selectedStoreId) {
|
||||
return pub.participatingGroups?.some((pg: any) => pg.groupId === selectedStoreId);
|
||||
const matches = pub.participations?.some((pg: any) => pg.groupId === selectedStoreId);
|
||||
if (matches) {
|
||||
console.log('🎯 Publicity matches selected store:', { pubNumber: pub.pubNumber, selectedStoreId });
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
|
||||
// If no specific store selected but user has assigned stores,
|
||||
// show publicities where any of user's stores participate
|
||||
if (userGroups && userGroups.length > 0) {
|
||||
const userGroupIds = userGroups.map((ug: any) => ug.groupId);
|
||||
return pub.participatingGroups?.some((pg: any) => userGroupIds.includes(pg.groupId));
|
||||
const matches = pub.participations?.some((pg: any) => userGroupIds.includes(pg.groupId));
|
||||
if (matches) {
|
||||
console.log('👥 Publicity matches user groups:', { pubNumber: pub.pubNumber, userGroupIds });
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -358,7 +377,7 @@ export default function CalendarGrid({
|
||||
<div
|
||||
key={`${pub.id}-${idx}`}
|
||||
className="bg-purple-100 text-purple-800 text-xs px-1.5 py-0.5 rounded-sm border border-purple-200 font-medium shadow-sm cursor-help"
|
||||
title={`Pub ${pub.pubNumber}: ${pub.designation}${pub.participatingGroups ? ` - Magasins: ${pub.participatingGroups.map((pg: any) => pg.group?.name).join(', ')}` : ''}`}
|
||||
title={`Pub ${pub.pubNumber}: ${pub.designation}${pub.participations ? ` - Magasins: ${pub.participations.map((pg: any) => pg.group?.name).join(', ')}` : ''}`}
|
||||
>
|
||||
{pub.pubNumber}
|
||||
</div>
|
||||
|
||||
+19
-3
@@ -875,6 +875,8 @@ export class DatabaseStorage implements IStorage {
|
||||
|
||||
// Publicity operations
|
||||
async getPublicities(year?: number, groupIds?: number[]): Promise<PublicityWithRelations[]> {
|
||||
console.log('🔍 getPublicities called with:', { year, groupIds });
|
||||
|
||||
const query = db.select({
|
||||
id: publicities.id,
|
||||
pubNumber: publicities.pubNumber,
|
||||
@@ -903,6 +905,7 @@ export class DatabaseStorage implements IStorage {
|
||||
}
|
||||
|
||||
const results = await query;
|
||||
console.log('📢 Raw publicities found:', results.length);
|
||||
|
||||
// Récupérer les participations séparément
|
||||
const publicityIds = results.map((pub: any) => pub.id);
|
||||
@@ -918,9 +921,11 @@ export class DatabaseStorage implements IStorage {
|
||||
.from(publicityParticipations)
|
||||
.innerJoin(groups, eq(publicityParticipations.groupId, groups.id))
|
||||
.where(inArray(publicityParticipations.publicityId, publicityIds)) : [];
|
||||
|
||||
console.log('🏪 Participations found:', participations.length);
|
||||
|
||||
// Associer les participations aux publicités
|
||||
return results.map((pub: any) => ({
|
||||
const finalResult = results.map((pub: any) => ({
|
||||
...pub,
|
||||
participations: participations
|
||||
.filter((p: any) => p.publicityId === pub.id)
|
||||
@@ -930,7 +935,18 @@ export class DatabaseStorage implements IStorage {
|
||||
group: p.group,
|
||||
createdAt: new Date()
|
||||
}))
|
||||
})) as PublicityWithRelations[];
|
||||
}));
|
||||
|
||||
console.log('✅ Final publicities with participations:', finalResult.length);
|
||||
if (finalResult.length > 0) {
|
||||
console.log('📄 Sample publicity:', {
|
||||
id: finalResult[0].id,
|
||||
pubNumber: finalResult[0].pubNumber,
|
||||
participations: finalResult[0].participations.map((p: any) => ({ groupId: p.groupId, groupName: p.group?.name }))
|
||||
});
|
||||
}
|
||||
|
||||
return finalResult as PublicityWithRelations[];
|
||||
}
|
||||
|
||||
async getPublicity(id: number): Promise<PublicityWithRelations | undefined> {
|
||||
@@ -2108,7 +2124,7 @@ class MemStorage implements IStorage {
|
||||
async createSavTicketHistory(): Promise<any> { return {}; }
|
||||
async updateSavTicketHistory(): Promise<any> { return {}; }
|
||||
async deleteSavTicketHistory(): Promise<void> {}
|
||||
async getPublicities(): Promise<any[]> { return []; }
|
||||
|
||||
async getPublicity(): Promise<any> { return undefined; }
|
||||
async createPublicity(): Promise<any> { return {}; }
|
||||
async updatePublicity(): Promise<any> { return {}; }
|
||||
|
||||
Reference in new issue
Block a user