-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: evening and morning notifs (#380)
- Loading branch information
1 parent
b9f662d
commit 88808dd
Showing
22 changed files
with
994 additions
and
84 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
api-node/prisma/migrations/20240129161743_notifications/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
-- AlterTable | ||
ALTER TABLE "User" ADD COLUMN "appversion" TEXT, | ||
ADD COLUMN "appversion_build" TEXT; | ||
|
||
-- CreateTable | ||
CREATE TABLE "Notification" ( | ||
"id" TEXT NOT NULL, | ||
"user_id" TEXT NOT NULL, | ||
"title" TEXT NOT NULL, | ||
"body" TEXT NOT NULL, | ||
"data" TEXT NOT NULL, | ||
"ticket" TEXT, | ||
"error" TEXT, | ||
"push_notif_token" TEXT, | ||
"appversion" TEXT, | ||
"appbuild" TEXT, | ||
"appdevice" TEXT, | ||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
||
CONSTRAINT "Notification_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Notification" ADD CONSTRAINT "Notification_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
10 changes: 10 additions & 0 deletions
10
api-node/prisma/migrations/20240129161830_user_app/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `appversion_build` on the `User` table. All the data in the column will be lost. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "User" DROP COLUMN "appversion_build", | ||
ADD COLUMN "appbuild" TEXT, | ||
ADD COLUMN "appdevice" TEXT; |
16 changes: 16 additions & 0 deletions
16
api-node/prisma/migrations/20240129175008_notification_indicator_values/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
Warnings: | ||
- Added the required column `indicatorId` to the `Notification` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `indicatorSlug` to the `Notification` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `indicatorValue` to the `Notification` table without a default value. This is not possible if the table is not empty. | ||
- Made the column `push_notif_token` on table `Notification` required. This step will fail if there are existing NULL values in that column. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "Notification" ADD COLUMN "indicatorId" TEXT NOT NULL, | ||
ADD COLUMN "indicatorSlug" "IndicatorsSlugEnum" NOT NULL, | ||
ADD COLUMN "indicatorValue" INTEGER NOT NULL, | ||
ADD COLUMN "recommandationId" TEXT, | ||
ADD COLUMN "typeWeatherAlert" TEXT, | ||
ALTER COLUMN "push_notif_token" SET NOT NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { setupCronJob } from './utils'; | ||
import { capture } from '~/third-parties/sentry'; | ||
import { | ||
sendEveningNotification, | ||
sendMorningNotification, | ||
} from '~/utils/notifications'; | ||
|
||
/* | ||
* | ||
* | ||
Initialization of the cron jobs | ||
We call them one after the other, | ||
in order to avoid to launch them all at the same time | ||
and have logs that are mixed and not readable. | ||
Test it: run `npm run dev-cronjobs` and check the logs | ||
*/ | ||
|
||
export async function initNotifications() { | ||
await Promise.resolve() | ||
.then(() => { | ||
console.log('Inside notifications cronjobs'); | ||
}) | ||
.then( | ||
async () => | ||
await setupCronJob({ | ||
name: 'Morning notifications', | ||
cronTime: '0 7 * * *', | ||
job: sendMorningNotification, | ||
runOnInit: false, | ||
}), | ||
) | ||
.then( | ||
async () => | ||
await setupCronJob({ | ||
name: 'Evening notifications', | ||
cronTime: '21 20 * * *', | ||
job: sendEveningNotification, | ||
runOnInit: false, | ||
}), | ||
) | ||
.then(() => { | ||
console.log('All notifications cron jobs are set up'); | ||
}) | ||
.catch(capture); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.