TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/miikorz/DailyNews/llms.txt
Use this file to discover all available pages before exploring further.
Feed entity is the single data model that powers the entire DailyNews backend. It represents one news article — whether scraped automatically from El País or El Mundo, or created manually via the API. The domain definition lives in src/domain/model/Feed.ts and is expressed as both a TypeScript interface (for type-safety) and a FeedDTO class (for constructing new instances). The infrastructure layer maps this domain model to a Mongoose ODM schema in src/infrastructure/repositories/feed/FeedODMModel.ts and stores all articles in a single MongoDB collection named feeds.
Feed Interface
TheFeed interface defines the shape of a news article throughout the application. All service methods, repository methods, and controller handlers are typed against this interface.
FeedDTO Class
FeedDTO is the concrete implementation of Feed used when constructing new feed objects — particularly inside the scraper repositories. Its constructor accepts all fields except createdAt, which is automatically set to new Date() at construction time. The toObject() method returns a plain JavaScript object conforming to the Feed interface, suitable for passing to repository methods or returning from the API.
Field Reference
The headline or title of the news article. Required for both scraped and manually created feeds. The
createFeed controller endpoint validates its presence and returns 400 Bad Request if it is missing.A short summary or teaser for the article. Defaults to an empty string in the Mongoose schema if not provided.
The author or byline of the article. Defaults to an empty string if not available (common for scraped articles where the homepage does not expose an author element).
The canonical URL of the full article. Used as the deduplication key in
saveScrappedFeeds() — no two documents in the collection may share the same link.URL of the article’s hero/thumbnail image. May be
null when no image is found during scraping. Defaults to an empty string in the Mongoose schema.The name of the news source that published the article (e.g.,
"El País" or "El Mundo"). For manually created feeds this field can be set to any string.Timestamp of when the document was inserted. Automatically set to
Date.now by the Mongoose schema default; also set by FeedDTO at construction time.Mongoose ODM Model
FeedODMModel.ts defines the Mongoose schema and exports the compiled model. The schema mirrors the Feed interface: title and link are plain String fields (effectively required by the controller’s validation), while description, author, portrait, and newsletter are optional strings that default to empty strings. createdAt defaults to Date.now.
FeedRepositoryInterface
FeedRepositoryInterface defines the contract for all database operations on the Feed collection. The FeedRepository class implements this interface, and the interface is also used as the type for the repository parameter injected into FeedService.
| Method | Signature | Description |
|---|---|---|
saveScrappedFeeds | (feeds: Feed[]) => Promise<Feed[]> | Deduplicates by link and inserts only new articles |
findAll | () => Promise<Feed[]> | Returns all articles sorted by createdAt descending |
findById | (id: string) => Promise<Feed | null> | Looks up a single article by its MongoDB _id |
findByTitle | (title: string) => Promise<Feed[]> | Case-insensitive regex search on the title field |
create | (feed: {...}) => Promise<Feed> | Inserts a new article document |
update | (id: string, feed: Partial<Feed>) => Promise<Feed | null> | Updates the article with the given _id, returns the new version |
delete | (id: string) => Promise<Feed | null> | Removes the article with the given _id |
FeedRepository Implementation
FeedRepository is the concrete Mongoose implementation of FeedRepositoryInterface. Notable implementation details:
findAll()chains.sort({ createdAt: -1 })and.lean()to return plain objects sorted newest-first.findByTitle()builds aRegExpwith theiflag for case-insensitive title search and also sorts bycreatedAtdescending.update()passes{ new: true }tofindByIdAndUpdateso the updated document (not the original) is returned.saveScrappedFeeds()uses aSet<string>of existing links to filter the input array before callinginsertMany, avoiding duplicate key errors.
All news articles — whether scraped automatically from El País and El Mundo or created manually via
POST /feed — are stored in the same MongoDB feeds collection. This single-collection design keeps the data model and query logic simple. If you need to separate sources in the future, consider adding an indexed source field or using separate collections per newsletter.