Skip to content

Commit

Permalink
feat: add recent notification api
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <[email protected]>
  • Loading branch information
Innei committed Apr 14, 2024
1 parent 14e0495 commit 1111b96
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
9 changes: 6 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"material-icon-theme.activeIconPack": "nest",
"cSpell.words": ["qaqdmin"],
"cSpell.words": [
"qaqdmin"
],
"typescript.tsdk": "node_modules/typescript/lib",
"yaml.schemas": {
"https://json.schemastore.org/github-workflow.json": "file:///Users/xiaoxun/github/innei-repo/mx-space/mx-server/.github/workflows/build.yml"
}
}
},
"typescript.preferences.preferTypeOnlyAutoImports": false
}
44 changes: 44 additions & 0 deletions apps/core/src/modules/activity/activity.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Activity } from './activity.constant'
import { ActivityService } from './activity.service'
import {
ActivityDeleteDto,
ActivityNotificationDto,
ActivityQueryDto,
ActivityRangeDto,
ActivityTypeParamsDto,
Expand Down Expand Up @@ -197,4 +198,47 @@ export class ActivityController {
...recent,
}
}

@HTTPDecorators.SkipLogging
@Get('/recent/notification')
async getNotification(@Query() query: ActivityNotificationDto) {
const activity = await this.getRecentActivities()

const { from } = query

const fromDate = new Date(from)
const now = new Date()

if (fromDate > now) {
return []
}

const { post, note } = activity

const postList = post
.filter((item) => {
return new Date(item.created) > fromDate
})
.map((item) => {
return {
title: item.title,
type: CollectionRefTypes.Post,
id: item.id,
slug: item.slug,
}
})
const noteList = note
.filter((item) => {
return new Date(item.created) > fromDate
})
.map((item) => {
return {
title: item.title,
type: CollectionRefTypes.Note,
id: item.nid,
}
})

return [...postList, ...noteList]
}
}
6 changes: 6 additions & 0 deletions apps/core/src/modules/activity/dtos/activity.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ export class ActivityRangeDto {
@Type(() => Number)
end: number
}

export class ActivityNotificationDto {
@IsInt()
@Type(() => Number)
from: number
}

0 comments on commit 1111b96

Please sign in to comment.