Skip to content

Dev tools safety (Admin Database Schema Migration)#419

Closed
CasperL1218 wants to merge 73 commits intomainfrom
dev-tools-safety
Closed

Dev tools safety (Admin Database Schema Migration)#419
CasperL1218 wants to merge 73 commits intomainfrom
dev-tools-safety

Conversation

@CasperL1218
Copy link
Copy Markdown
Contributor

Summary

  • Replaces `window.confirm()` on the Schema Migration "Run Migration" button with a proper MUI Dialog
  • Admin must type `CONFIRM` exactly before the button enables — prevents accidental batch-writes to all
    apartment records
  • No new imports needed (Dialog, TextField already imported)

Test plan

  • Go to Admin → Dev Tools → Schema Migration
  • Click "Run Migration" — confirm dialog opens
  • Verify "Run Migration" button inside dialog is disabled until "CONFIRM" is typed
  • Cancel closes dialog without running migration
  • Typing CONFIRM enables and runs migration as before

parsa-tehranipoor and others added 30 commits May 27, 2025 00:20
Merge main repository code to current branch
\
- Implemented apartment information edit endpoint
- Implemented create new apartment endpoint
- Implemented admin page apartment pagination, sorting, and editing functionalities
- Implement folder page to display user folders
- Add folder card component for folder representation
- Added 'add to folder' button in apartment page
- Debugged authentication issues in folder operations
  Backend Changes:
  - Add RoomType interface with UUID-based IDs (beds, baths, price)
  - Replace single numBeds/numBaths/price fields with roomTypes array
  - Add migration endpoint POST /api/admin/migrate-all-apartments-schema
    - Supports dry run mode for preview
    - Batch processing (100 apartments per batch)
    - Initializes roomTypes as empty array and removes old fields
  - Update PUT /api/admin/update-apartment to handle roomTypes
    - Generate UUIDs for new room types
    - Validate beds/baths/price >= 1 (integers only)
    - Check for duplicate room type combinations
  - Update POST /api/admin/add-apartment to accept roomTypes
    - Same validation and UUID generation
    - Allow empty roomTypes array
  - Update add_buildings.ts script to use new schema

  Frontend Changes (Temporary):
  - Comment out old bed/bath/price displays in ApartmentCard
  - Comment out bed display in NewApartmentCard
  - Update price sorting to use avgPrice temporarily
  - Proper room type display will be implemented in future commits
  - Proper room type sorting will be implemented in future commits

  Note: All apartments will start with empty roomTypes after migration.
  Frontend integer validation for admin UI will be added in following commits.
  Admin Page Room Type Management
  - Added room types editing modal with table UI for beds/baths/price
  - Displays existing room types with inline editing and delete functionality
  - Includes "Add Room Type" button with validation (>= 1 for all fields)
  - Checks for duplicate room types (same beds/baths/price combination)
  - Backend generates UUIDs for new room types automatically
  - Shows room type count in Data tab instead of old numBeds/numBaths fields
  - Displays room type IDs (truncated) for debugging

  Room Type Display Utilities and Card Updates
  - Created roomTypeUtils.ts with comprehensive display functions:
    - formatPrice: Formats prices with K suffix (e.g., $1.5K, $3K)
    - formatBeds/formatBaths: Formats bed/bath counts (e.g., "2 beds", "1 bath")
    - getRoomTypeRange: Gets min/max values for beds/baths/price
    - formatPriceRange: Formats price ranges (e.g., "$1.5K - $3K")
    - formatRoomTypesDisplay: Complete display string for cards
    - getMinPrice/getMaxPrice: Helper functions for sorting
  - Updated NewApartmentCard to display dynamic price ranges from room types
  - Shows "Coming soon" when no room types are available
  - Update ApartmentCard component to display room type information
    - Add imports for formatPriceRange, formatBedsRange, getRoomTypeRange utilities
    - Replace TODO section with dynamic room types display
    - Show "Coming soon" message for apartments with empty roomTypes
    - Display formatted price and bed ranges for apartments with room types data

  - Implement comprehensive search filtering with room types support
    - Re-enable price, bedroom, and bathroom filter parameters
    - Add exact match filtering for beds/baths (not >=)
    - Implement additional search result sections (location, price, bed/bath)
    - Return structured response with main results + 3 additional sections
    - Filter apartments based on roomTypes array instead of old schema
    - Handle empty roomTypes arrays in filter logic

  - Update search results page to support additional sections
    - Add state variables for additionalLocation, additionalPrice, additionalBedBath
    - Prepare frontend for displaying multiple result sections

  - Enhance apartment sorting with room types
    - Use getMinPrice/getMaxPrice utilities for sorting by price
    - Sort by minimum price (cheapest) or maximum price (most expensive)
    - Handle apartments with empty roomTypes arrays

  This completes the frontend display implementation for the room types refactor.
  Backend migration tools and admin CRUD are already in place from previous commits.
  Ready for data migration and testing.
…ayout

  - Rename "Data" tab to "Apartment Data" for clarity
  - Remove test apartments pagination and filtering logic
  - Add real-time search functionality:
    - Search by apartment name
    - Search by apartment address
    - Both searches reset pagination to first page
  - Add room types filter dropdown:
    - All Apartments (default)
    - With Room Types (show only apartments with room types data)
    - Without Room Types (show only apartments missing room types)
  - Reorganize apartment display with horizontal card layout:
    - Replace vertical list with compact card-based design
    - Organize information in 3 responsive columns (Location, Details, Stats)
    - Add visual distinction for apartments without room types (gray italic)
    - Position edit button in top-right corner of each card
    - Reduce vertical space usage by ~50%
  - Update display counter to show filtered vs total apartment counts
  - Simplify pagination logic by removing test apartment handling
  - Improve visual hierarchy with section labels and consistent spacing

  This makes it easier for admins to find and manage apartments,
  especially when populating room types data after migration.
  - Add "Create New Apartment" button in Apartment Data tab header
  - Implement two-step apartment creation workflow:
    1. Preview mode: Calculate location data from address
    2. Confirm mode: Create apartment in database
  - Create modal dialog with required fields:
    - Apartment Name (text input)
    - Full Address (text input with geocoding support)
    - Landlord ID (text input)
    - Area (dropdown: Collegetown, West, North, Downtown, Other)
  - Display preview of calculated location data before creation:
    - Show latitude and longitude from geocoded address
    - Show calculated distance to campus
    - Confirm before final creation
  - Add comprehensive error handling and validation:
    - Form validation for required fields
    - Backend error display in modal
    - Loading states for preview and create actions
  - Integrate with existing `/api/admin/add-apartment` endpoint
    - Endpoint automatically geocodes address to get coordinates
    - Calculates walking distance to Ho Plaza
    - Validates landlord exists
    - Checks for duplicate locations
  - Auto-reload apartment list after successful creation
  - Show success message with generated apartment ID

  This streamlines the apartment creation process for admins by
  automating location data calculation and providing validation
  before committing changes to the database.
parsa-tehranipoor and others added 24 commits December 7, 2025 22:43
- Added scripts to export apartment data to CSV and update apartment data from CSV
- Updated package.json with new script commands for data export and update
   4.9.5, pin @types/react to ^17
  project documentation style guide, add local files to gitignore
  Aligns common/types/db-types.ts with the actual Firestore field name used
  by all backend endpoints and frontend components.
  Adds user folder/bookmark system — folder CRUD endpoints, AddToFolderPopover
  component, FolderCard, FolderSection, BookmarksPage integration, and
  FolderDetailPage. Conflict resolutions: kept dynamic priceDisplay over
  hardcoded values, preserved landlord messaging feature from bugs-in-reviews,
  kept both firebase and AddToFolderPopover imports.
  - Resolved AdminPage.tsx conflicts: kept both blog post tab and apartment
    data/dev tools tabs from main's admin-data-edit merge
  - Resolved app.ts conflicts: kept BlogPost types + Folder types + both
    blogPostCollection and folderCollection declarations
  - Removed duplicate axios/firebase imports introduced by merge
  - Fixed onEditorChange implicit any in TinyMCE Editor
  - Removed unused firebase import in BlogPostDetailPage.tsx
  - Added backend/scripts/init_blogposts_collection.ts (idempotent Firestore
    init script for prod)
  - Added POST /api/admin/init-collections endpoint (admin-authenticated)
  - Added Database Initialization section to Dev Tools tab in AdminPage
  Moves admin access from hardcoded-only to Firestore-backed:
  - backend/src/authAdmin.ts: new authenticateAdmin middleware that checks
    both hardcoded superadmins AND Firestore adminWhitelist collection
  - GET /api/is-admin: async admin check for frontend
  - GET/POST/DELETE /api/admin/whitelist: CRUD endpoints for Firestore whitelist
  - App.tsx: async isAdminUser state via /api/is-admin so Firestore-added
    admins can access /admin route without a redeploy
  - AdminPage.tsx: new Admin Management tab with add/remove + confirmation
  Replaces window.confirm() with a MUI Dialog that requires the admin to
  type 'CONFIRM' before the schema migration can proceed, preventing
  accidental batch-writes to all apartment records.
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
3 out of 4 committers have signed the CLA.

✅ parsa-tehranipoor
✅ CasperL1218
✅ laurenp-2
❌ Lauren Pothuru


Lauren Pothuru seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@dti-github-bot
Copy link
Copy Markdown
Member

[diff-counting] Significant lines: 9483. This diff might be too big! Developer leads are invited to review the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants