Skip to content

Commit

Permalink
Merge branch 'main' into feature/#27
Browse files Browse the repository at this point in the history
  • Loading branch information
Inlet-back committed Oct 26, 2024
2 parents 40db171 + 50ce4b1 commit 8211b92
Show file tree
Hide file tree
Showing 12 changed files with 904 additions and 99 deletions.
32 changes: 29 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,32 @@ env:
on: push

jobs:
lint:
runs-on: ubuntu-latest
defaults:
run:
working-directory: task_yell
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18
check-latest: true

- name: Install dependencies
run: npm install

- name: Run ESLint
run: npm run lint

- name: Run Prettier
run: npm run format:check

preview:
needs: lint
if: ${{ github.ref != 'refs/heads/main' }}
runs-on: ubuntu-latest
environment:
Expand All @@ -24,12 +49,12 @@ jobs:
node-version: 18
check-latest: true

- name: Install Vercel CLI
run: npm install --global vercel@latest

- name: Mv directory
run: cd ./task_yell

- name: Install Vercel CLI
run: npm install --global vercel@latest

- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}

Expand All @@ -45,6 +70,7 @@ jobs:
run: vercel alias ${{ steps.deploy.outputs.url }} stg.my-service.com --scope=my-team --token=${{ secrets.VERCEL_TOKEN }}

prod:
needs: lint
if: ${{ github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
steps:
Expand Down
46 changes: 43 additions & 3 deletions firebase/functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,53 @@
* See a full list of supported triggers at https://firebase.google.com/docs/functions
*/

import {onRequest} from "firebase-functions/v2/https";
import { onRequest } from "firebase-functions/v2/https";
import * as functions from "firebase-functions/v2";
import * as logger from "firebase-functions/logger";

import * as admin from "firebase-admin";
import type { DocumentReference } from "firebase-admin/firestore";
// Start writing functions
// https://firebase.google.com/docs/functions/typescript

admin.initializeApp();

export const helloWorld = onRequest((request, response) => {
logger.info("Hello logs!", {structuredData: true});
logger.info("Hello logs!", { structuredData: true });
response.send("Hello from Firebase!");
});

export const pushNotification = functions.scheduler
.onSchedule("every 1 minutes", async () => {
const now = (() => {
let s = admin.firestore.Timestamp.now().seconds
s = s - s % 60
return new admin.firestore.Timestamp(s, 0)
})()
// リマインダーコレクションから現在時刻のリマインダーをクエリ
const db = admin.firestore()
const notifications = await Promise.all((await db.collection('notifications')
.where('datetime', '==', now)
.where("type", "==", "push")
.get())
.docs
.map(async doc => {
const event = await (doc.get("eventOrTaskRef") as DocumentReference).get();
const tokens = await db.collection("users").doc(doc.get("userId")).get().then(doc => doc.get("fcm-tokens")) as string[];
return {
title: event.get("title"),
description: event.get("description"),
tokens
}
}));

const messaging = admin.messaging();
for (const notification of notifications) {
await messaging.sendEachForMulticast({
tokens: notification.tokens,
notification: {
title: notification.title,
body: notification.description
}
})
}
});
2 changes: 1 addition & 1 deletion task_yell/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": ["next/core-web-vitals", "next/typescript"]
"extends": ["next/core-web-vitals", "next/typescript", "prettier"]
}
Loading

0 comments on commit 8211b92

Please sign in to comment.