Fix issue preventing administrators from deleting advertisements

Improve the publicity deletion endpoint by adding comprehensive logging for debugging, ensuring correct role-based access control, and refining the database deletion logic to include participations for data integrity.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 1e4433b5-47ab-464c-b663-fea2e53367dd
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/1e4433b5-47ab-464c-b663-fea2e53367dd/BADbf74
This commit is contained in:
michaelschal committed 2025-09-15 09:19:25 +00:00
1 parent b1a7ef235a
commit 9ad2afaf90
4 files changed
+41 -5

No files matched your search

+20 -2
View File
@@ -1479,8 +1479,26 @@ export class DatabaseStorage implements IStorage {
}
async deletePublicity(id: number): Promise<void> {
await db.delete(publicityParticipations).where(eq(publicityParticipations.publicityId, id));
await db.delete(publicities).where(eq(publicities.id, id));
console.log(`🗑️ [DELETION] Starting deletion of publicity ID: ${id}`);
try {
// First, delete all participations (defensive approach for production DB constraints)
const deletedParticipations = await db.delete(publicityParticipations).where(eq(publicityParticipations.publicityId, id)).returning();
console.log(`🗑️ [DELETION] Deleted ${deletedParticipations.length} participations for publicity ${id}`);
// Then delete the publicity itself
const deletedPublicity = await db.delete(publicities).where(eq(publicities.id, id)).returning();
console.log(`🗑️ [DELETION] Deleted publicity ${id}, found: ${deletedPublicity.length > 0 ? 'YES' : 'NO'}`);
if (deletedPublicity.length === 0) {
throw new Error(`Publicity with ID ${id} not found`);
}
console.log(`✅ [DELETION] Successfully deleted publicity ID: ${id}`);
} catch (error) {
console.error(`❌ [DELETION] Failed to delete publicity ID: ${id}`, error);
throw error;
}
}
async getPublicityParticipations(publicityId: number): Promise<PublicityParticipation[]> {