Skip to content

Commit

Permalink
chore(functions): remove request dependency (#3673)
Browse files Browse the repository at this point in the history
  • Loading branch information
evakill authored Jun 18, 2024
1 parent d7dc9b2 commit bad3b83
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 42 deletions.
2 changes: 0 additions & 2 deletions functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"google-auth-library": "^9.10.0",
"handlebars": "^4.7.8",
"oa-shared": "workspace:*",
"request": "^2.88.2",
"sitemap": "^7.1.1",
"uuid": "^9.0.1"
},
Expand All @@ -42,7 +41,6 @@
"@types/fs-extra": "^11.0.4",
"@types/jest": "^29.5.12",
"@types/node": "^20.8.0",
"@types/request": "^2.48.12",
"@types/uuid": "^9.0.0",
"@types/webpack": "^5.28.5",
"@types/webpack-node-externals": "^3.0.4",
Expand Down
54 changes: 18 additions & 36 deletions functions/src/Integrations/firebase-slack.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CONFIG } from '../config/config'
import * as functions from 'firebase-functions'
import * as request from 'request'
import axios from 'axios'
import { IModerationStatus } from 'oa-shared'

const SITE_URL = CONFIG.deployment.site_url
Expand All @@ -11,56 +11,38 @@ const SLACK_WEBHOOK_URL = CONFIG.integrations.slack_webhook
export const notifyNewPin = functions
.runWith({ memory: '512MB' })
.firestore.document('v3_mappins/{pinId}')
.onCreate((snapshot) => {
.onCreate(async (snapshot) => {
const info = snapshot.data()
const id = info._id
const type = info.type
const moderation = info.moderation

if (moderation !== IModerationStatus.AWAITING_MODERATION) return

request.post(
SLACK_WEBHOOK_URL,
{
json: {
text: `📍 *New ${type}* pin from _${id}_ awaiting moderation. \n Location here ${SITE_URL}/map/#${id}`,
},
},
(err, res) => {
if (err) {
console.error(err)
return
} else {
return res
}
},
)
return await axios
.post(SLACK_WEBHOOK_URL, {
text: `📍 *New ${type}* pin from _${id}_ awaiting moderation. \n Location here ${SITE_URL}/map/#${id}`,
})
.catch((err) => {
console.error(err)
})
})

export const notifyNewHowTo = functions
.runWith({ memory: '512MB' })
.firestore.document('v3_howtos/{id}')
.onCreate((snapshot) => {
.onCreate(async (snapshot) => {
const info = snapshot.data()
const user = info._createdBy
const title = info.title
const slug = info.slug
// console.log(info);
request.post(
SLACK_WEBHOOK_URL,
{
json: {
text: `📓 Yeah! New How To *${title}* by _${user}_ awaiting moderation,

return await axios
.post(SLACK_WEBHOOK_URL, {
text: `📓 Yeah! New How To *${title}* by _${user}_ awaiting moderation,
check it out: ${SITE_URL}/how-to/${slug}`,
},
},
(err, res) => {
if (err) {
console.error(err)
return
} else {
return res
}
},
)
})
.catch((err) => {
console.error(err)
})
})
6 changes: 2 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9044,7 +9044,7 @@ __metadata:
languageName: node
linkType: hard

"@types/request@npm:^2.48.12, @types/request@npm:^2.48.8":
"@types/request@npm:^2.48.8":
version: 2.48.12
resolution: "@types/request@npm:2.48.12"
dependencies:
Expand Down Expand Up @@ -17327,7 +17327,6 @@ __metadata:
"@types/fs-extra": ^11.0.4
"@types/jest": ^29.5.12
"@types/node": ^20.8.0
"@types/request": ^2.48.12
"@types/uuid": ^9.0.0
"@types/webpack": ^5.28.5
"@types/webpack-node-externals": ^3.0.4
Expand All @@ -17349,7 +17348,6 @@ __metadata:
jest: 29.7.0
jest-junit: ^16.0.0
oa-shared: "workspace:*"
request: ^2.88.2
sitemap: ^7.1.1
supertest: ^6.3.3
ts-jest: 29.1.4
Expand Down Expand Up @@ -27024,7 +27022,7 @@ __metadata:
languageName: node
linkType: hard

"request@npm:^2.87.0, request@npm:^2.88.2":
"request@npm:^2.87.0":
version: 2.88.2
resolution: "request@npm:2.88.2"
dependencies:
Expand Down

0 comments on commit bad3b83

Please sign in to comment.