Skip to content

Commit 6420335

Browse files
committed
add events api
1 parent 54871a9 commit 6420335

File tree

4 files changed

+82
-2
lines changed

4 files changed

+82
-2
lines changed

.firebaserc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"projects": {
3+
"live": "wedance-4abe3"
4+
},
5+
"targets": {},
6+
"etags": {}
7+
}

services/firebase/src/index.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ import * as cors from 'cors'
55
import * as Handlebars from 'handlebars'
66
import sendEmail from './lib/sendEmail'
77
import { screenshot } from './lib/screenshot'
8-
import { initIndex, profileToAlgolia, removeObject } from './lib/algolia'
8+
import {
9+
eventForApi,
10+
initIndex,
11+
profileToAlgolia,
12+
removeObject,
13+
} from './lib/algolia'
914
import { generateSocialCover } from './lib/migrations'
10-
import { firestore as db, admin } from './firebase'
15+
import { firestore as db, admin, firestore } from './firebase'
1116
import { notifySlackAboutEvents, notifySlackAboutUsers } from './lib/slack'
1217
import { wrap } from './sentry'
1318
import { announceEvent } from './lib/telegram'
@@ -24,6 +29,33 @@ Sentry.init({
2429
const app = express()
2530
app.use(cors({ origin: true }))
2631

32+
app.get('/events', async (req, res) => {
33+
const today = new Date().toISOString().slice(0, 10)
34+
35+
const eventDocs = (
36+
await firestore
37+
.collection('posts')
38+
.where('startDate', '>', today)
39+
.get()
40+
).docs
41+
42+
const data = []
43+
44+
for (const doc of eventDocs) {
45+
const event = {
46+
id: doc.id,
47+
...doc.data(),
48+
} as any
49+
50+
data.push(eventForApi(event))
51+
}
52+
53+
res.json({
54+
success: true,
55+
data,
56+
})
57+
})
58+
2759
app.post('/track/:action', async (req, res) => {
2860
const vars = req.body['event-data']['user-variables']
2961

services/firebase/src/lib/algolia.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,46 @@ export function profileToAlgolia(profile: any, cache: any) {
5252
}
5353
}
5454

55+
export function eventForApi(event: any) {
56+
let result = {
57+
id: event.id,
58+
organiser: event.org.username,
59+
name: event.name,
60+
cover: event.cover,
61+
description: event.description,
62+
price: event.price,
63+
styles: event.styles ? Object.keys(event.styles) : [],
64+
type: event.eventType,
65+
online: event.online === 'Yes' ? true : false,
66+
createdAt: new Date(event.createdAt),
67+
updateAt: new Date(event.updateAt),
68+
startDate: new Date(event.startDate),
69+
endDate: new Date(event.endDate),
70+
}
71+
72+
if (event.venue) {
73+
const venue = {
74+
venue: event.venue.name,
75+
address: event.venue.formatted_address,
76+
locality:
77+
event.venue.address_components.find((c: any) =>
78+
c.types.includes('locality')
79+
)?.long_name || '',
80+
country:
81+
event.venue.address_components.find((c: any) =>
82+
c.types.includes('country')
83+
)?.long_name || '',
84+
location: {
85+
lat: event.venue?.geometry.location.lat,
86+
lng: event.venue?.geometry.location.lng,
87+
},
88+
}
89+
result = { ...result, ...venue }
90+
}
91+
92+
return result
93+
}
94+
5595
export function eventToAlgolia(event: any) {
5696
let result = {
5797
objectID: event.id,

static/_redirects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ https://we-dance.app/* https://wedance.vip/:splat 301!
44
http://wedance.netlify.app/* https://wedance.vip/:splat 301!
55
https://wedance.netlify.app/* https://wedance.vip/:splat 301!
66
/api/styles/* https://dance-styles.herokuapp.com/styles/:splat 200!
7+
/api/events/* https://us-central1-wedance-4abe3.cloudfunctions.net/hooks/events/:splat 200!
78
/wiki https://plant-xylophone-e69.notion.site/WeDance-Wiki-3ca6f10c593942729f5d66af17758a0c 301!
89
/slack https://join.slack.com/t/wedanceclub/shared_invite/zt-tzzzwh6v-y9NPMN83FUlzZFqZmto3IQ 301!
910
/trello https://trello.com/invite/b/8NwjoY9W/31146a069641c55f000e3f73c505a661/wedance-tasks 301!

0 commit comments

Comments
 (0)