@everytravel/shared
Version:
A comprehensive shared package for Everytravel containing Mongoose models and CRUD operations for hotel booking, user management, and transaction handling. Updated with improved model syntax and enhanced error handling.
102 lines (76 loc) β’ 3.69 kB
Markdown
# @everytravel/shared - Changelog
## 1.0.7 - Property & Suite Management Enhancements (2025-08-12)
### π New Features
#### Enhanced CRUD Operations
- **`updateMany`**: Bulk update multiple documents with filters and validation
- **`softDelete`**: Soft delete documents by setting `softDeleted: true` and `deletedAt` timestamp
- **`bulkSoftDelete`**: Bulk soft delete multiple documents by ID array
#### Model Enhancements
**Property Model (`Property.model.js`)**:
- Added default values: `show: true`, `softDeleted: false`
- Added `deletedAt: Date` field for tracking soft delete timestamp
- Enhanced soft delete functionality with automatic timestamp
**Suite Model (`Suite.model.js`)**:
- Added default values: `show: true`, `softDeleted: false`
- Added `deletedAt: Date` field for tracking soft delete timestamp
- Enhanced soft delete functionality with automatic timestamp
### βοΈ Indexes & Performance
**Property Model (`Property.model.js`)**:
- Added composite indexes for common filters:
- `{ owner: 1, softDeleted: 1 }` for host-scoped queries
- `{ show: 1, softDeleted: 1 }` for public visibility
- Added filter/sort indexes:
- `{ type: 1 }`, `{ 'location.city': 1 }`, `{ 'location.country': 1 }`
- `{ metaTags: 1 }` (multikey), `{ facilities: 1 }` (multikey)
- `{ starRating: 1 }`, `{ createdAt: -1 }`
- Added text index for future fullβtext search: `{ name: 'text', description: 'text' }`
**Suite Model (`Suite.model.js`)**:
- Added composite indexes:
- `{ show: 1, softDeleted: 1 }` for public visibility
- `{ property: 1, softDeleted: 1 }` for property scoping
- Added filter/sort indexes:
- `{ roomType: 1 }`, `{ 'pricePerNight.from': 1 }`, `{ sizeSqMeters: 1 }`
- `{ numBeds: 1 }`, `{ numBathrooms: 1 }`, `{ sleeps: 1 }`, `{ availabilityCount: 1 }`
- `{ metaTags: 1 }` (multikey), `{ features: 1 }` (multikey)
### π¦ Updated Exports
**Methods Index (`methods/index.js`)**:
- Now exports: `updateMany`, `softDelete`, `bulkSoftDelete`
- Maintains backward compatibility with existing exports
### π§ Technical Details
**New Functions in `update/index.js`**:
1. **`updateMany(Model, filter, update, options)`**
- Bulk update multiple documents
- Supports validation and custom options
- Returns update result with `modifiedCount`
2. **`softDelete(Model, filter)`**
- Soft deletes documents matching filter
- Sets `softDeleted: true` and `deletedAt: new Date()`
- Returns update result
3. **`bulkSoftDelete(Model, ids)`**
- Soft deletes multiple documents by ID array
- Optimized for bulk operations
- Returns update result with `modifiedCount`
### π‘ Usage Examples
```javascript
import { updateMany, softDelete, bulkSoftDelete, Property } from '@everytravel/shared';
// Bulk update
await updateMany(Property, { owner: hostId }, { show: false });
// Soft delete single
await softDelete(Property, { _id: propertyId });
// Bulk soft delete
await bulkSoftDelete(Property, [id1, id2, id3]);
```
### π Breaking Changes
None - All changes are backward compatible.
### π Migration Notes
- Existing documents will need `show` and `softDeleted` fields populated if not present
- Consider adding database migration for existing data
- TTL index recommended for `deletedAt` field (90 days retention)
### π― Use Cases
- Host property management (create, update, delete properties)
- Suite management with property association
- Bulk operations for administrative tasks
- Public API filtering (exclude soft-deleted items)
- Automatic cleanup with TTL indexes
---
**Ready for republishing** β