Implement /edcal command
Displays the Editorial Calendar! Still a WIP, but let's see if it works on Mattermost...
This commit is contained in:
parent
331abd847a
commit
8626909ade
1 changed files with 61 additions and 0 deletions
61
index.js
61
index.js
|
@ -31,3 +31,64 @@ app.post("/add", (req, res) => {
|
|||
const { a, b } = req.body
|
||||
res.send({ result: a + b })
|
||||
})
|
||||
|
||||
app.get("/articles", (req, res) => {
|
||||
let articles = []
|
||||
|
||||
base('Articles').select({
|
||||
maxRecords: 10,
|
||||
view: "Calendar",
|
||||
fields: [
|
||||
"Title",
|
||||
"Author",
|
||||
"Due Date",
|
||||
"Publish Date",
|
||||
"In charge",
|
||||
"Status",
|
||||
],
|
||||
filterByFormula: "NOT({Status} = 'Stalled')",
|
||||
sort: [
|
||||
{ field: "Publish Date", direction: "desc" },
|
||||
{ field: "Status", direction: "asc" },
|
||||
],
|
||||
}).eachPage(function page(records, fetchNextPage) {
|
||||
records.forEach((record) => {
|
||||
console.log(`Got ${record.get('Title')}`)
|
||||
articles.push({
|
||||
title: record.get("Title"),
|
||||
author: record.get("Author"),
|
||||
due_date: record.get("Due Date"),
|
||||
publish_date: record.get("Publish Date"),
|
||||
in_charge: record.get("In charge"),
|
||||
status: record.get("Status"),
|
||||
})
|
||||
})
|
||||
|
||||
fetchNextPage()
|
||||
}, function done(err) {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
res.send({ status: "error", "error": "An error occurred :("})
|
||||
return
|
||||
}
|
||||
|
||||
if (req.body.command != 'edcal') {
|
||||
articleTable = (articles
|
||||
.reverse()
|
||||
.map(a => `|${a.title}|${a.in_charge.map(u=>u.name).join(',')}|${a.due_date}|${a.publish_date}|${a.status}|`)
|
||||
.join("\n"))
|
||||
res.send({
|
||||
response_type: "in_channel",
|
||||
text: `---
|
||||
#### Editorial Calendar
|
||||
|
||||
|Title|In charge|Due Date|Publish Date|Status|
|
||||
|:----|:--------|:-------|:-----------|:-----|
|
||||
${articleTable}
|
||||
---`,
|
||||
})
|
||||
} else {
|
||||
res.send({ status: "ok", articles: articles.reverse() })
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue