|
1 | 1 | import * as v from "valibot"; |
| 2 | +import { nameMap } from "./data.ts"; |
2 | 3 | import { queryNotion, retry, webhook } from "./io.ts"; |
3 | 4 | import { NotionFetchResponse, type Task } from "./validator.ts"; |
4 | 5 |
|
@@ -36,19 +37,31 @@ const query = { |
36 | 37 | ], |
37 | 38 | }; |
38 | 39 |
|
39 | | -function formatTask(task: Task) { |
| 40 | +function formatTask(task: Task): string { |
40 | 41 | const due = task.properties.期日?.date.start; |
41 | 42 | const title = task.properties.タイトル?.title.map((title) => title.plain_text).join(""); |
42 | | - const assignee = task.properties.担当者?.people.map((person) => person.name).join(" / @"); |
| 43 | + const assignees = task.properties.担当者?.people.map( |
| 44 | + (person): { success: true; id: string } | { success: false; display: string } => { |
| 45 | + if (!person.name) return { success: false, display: "-" }; |
| 46 | + const d_id = nameMap.get(person.name); |
| 47 | + if (!d_id) return { success: false, display: person.name }; |
| 48 | + return { success: true, id: d_id }; |
| 49 | + }, |
| 50 | + ); |
| 51 | + |
| 52 | + const assignee = assignees |
| 53 | + ?.map((a) => { |
| 54 | + if (a.success) return `<@${a.id}>`; |
| 55 | + return `@${a.display}`; |
| 56 | + }) |
| 57 | + .join(" "); |
43 | 58 |
|
44 | 59 | if (!assignee) { |
45 | 60 | return `・【${due}】${title} (担当者不在)`; |
46 | 61 | } |
47 | | - return `・【${due}】${title} @${assignee}`; |
| 62 | + return `・【${due}】${title} ${assignee}`; |
48 | 63 | } |
49 | | -/** |
50 | | - - @throws on NetworkError and ParseError |
51 | | - */ |
| 64 | + |
52 | 65 | async function main() { |
53 | 66 | const res = await queryNotion(query); |
54 | 67 | const json = v.parse(NotionFetchResponse, await res.json()); |
|
0 commit comments