-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor bot view and add API helper generation * Remove bot service and refactor snapshot views to use centralized snapshot service functions.
- Loading branch information
Showing
5 changed files
with
154 additions
and
90 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,56 @@ | ||
import { displayLocaleDate, formatYearMonth } from '@/utils/date' | ||
|
||
|
||
|
||
|
||
|
||
export function generateAPIHelper(uuid: string, apiToken: string, origin: string) { | ||
const data = { | ||
"message": "Your message here", | ||
"snapshot_uuid": uuid, | ||
"stream": false, | ||
} | ||
return `curl -X POST ${origin}/api/chatbot -H "Content-Type: application/json" -H "Authorization: Bearer ${apiToken}" -d '${JSON.stringify(data)}'` | ||
} | ||
|
||
export function getChatbotPosts(posts: Snapshot.Snapshot[]) { | ||
return posts | ||
.filter((post: Snapshot.Snapshot) => post.typ === 'chatbot') | ||
.map((post: Snapshot.Snapshot): Snapshot.PostLink => ({ | ||
uuid: post.uuid, | ||
date: displayLocaleDate(post.createdAt), | ||
title: post.title, | ||
})) | ||
} | ||
|
||
export function getSnapshotPosts(posts: Snapshot.Snapshot[]) { | ||
return posts | ||
.filter((post: Snapshot.Snapshot) => post.typ === 'snapshot') | ||
.map((post: Snapshot.Snapshot): Snapshot.PostLink => ({ | ||
uuid: post.uuid, | ||
date: displayLocaleDate(post.createdAt), | ||
title: post.title, | ||
})) | ||
} | ||
|
||
export function postsByYearMonthTransform(posts: Snapshot.PostLink[]) { | ||
const init: Record<string, Snapshot.PostLink[]> = {} | ||
return posts.reduce((acc, post) => { | ||
const yearMonth = formatYearMonth(new Date(post.date)) | ||
if (!acc[yearMonth]) | ||
acc[yearMonth] = [] | ||
|
||
acc[yearMonth].push(post) | ||
return acc | ||
}, init) | ||
} | ||
|
||
export function getSnapshotPostLinks(snapshots: Snapshot.Snapshot[]): Record<string, Snapshot.PostLink[]> { | ||
const snapshotPosts = getSnapshotPosts(snapshots) | ||
return postsByYearMonthTransform(snapshotPosts) | ||
} | ||
|
||
export function getBotPostLinks(bots: Snapshot.Snapshot[]): Record<string, Snapshot.PostLink[]> { | ||
const chatbotPosts = getChatbotPosts(bots) | ||
return postsByYearMonthTransform(chatbotPosts) | ||
} |
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
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