-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(search-searvice): adding /sitemap REST endpoint
- Loading branch information
1 parent
2e808a8
commit 05c44ad
Showing
4 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Request } from 'express'; | ||
import { SiteMaps } from './schema'; | ||
|
||
export const getSiteMap = async (req: Request) => { | ||
const { contentType } = req.query; | ||
|
||
const sitemapData = (await SiteMaps.find()).map((item) => ({ | ||
url: item.url, | ||
contentType: item.contentType, | ||
lastModified: new Date().toISOString(), | ||
})); | ||
|
||
const filteredSitemapData = contentType | ||
? sitemapData.filter((item) => item.contentType === contentType) | ||
: sitemapData; | ||
|
||
return { | ||
count: filteredSitemapData.length, | ||
data: filteredSitemapData, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { | ||
Document, Model, model, Schema, | ||
} from 'mongoose'; | ||
|
||
export const SiteMapSchema: Schema = new Schema({ | ||
url: { type: String }, | ||
contentType: { type: String }, | ||
}); | ||
|
||
interface SiteMapModel extends Sitemap, Document {} | ||
|
||
interface SiteMapStatic extends Model<SiteMapModel> {} | ||
|
||
export const SiteMaps: Model<SiteMapModel> = model<SiteMapModel, SiteMapStatic>('SiteMap', SiteMapSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
declare type Sitemap = { | ||
url: string; | ||
contentType: string; | ||
}; |