mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-10-03 00:27:30 -05:00
Move app to apps/web-react in pnpm workspace layout
This commit is contained in:
41
apps/web-react/scripts/send-test-notification.ts
Normal file
41
apps/web-react/scripts/send-test-notification.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { db } from "~/db/sql";
|
||||
import { notify } from "~/features/notifications/core/notify.server";
|
||||
import { webPushEnabled } from "~/features/notifications/core/webPush.server";
|
||||
import * as NotificationRepository from "~/features/notifications/NotificationRepository.server";
|
||||
import invariant from "~/utils/invariant";
|
||||
import { logger } from "~/utils/logger";
|
||||
|
||||
const username = process.argv[2]?.trim() ?? "Sendou";
|
||||
const seasonNth = Number(process.argv[3] ?? 1);
|
||||
|
||||
invariant(!Number.isNaN(seasonNth), "season nth must be a number (argument 2)");
|
||||
|
||||
const user = await db
|
||||
.selectFrom("User")
|
||||
.select(["id", "username"])
|
||||
.where("username", "=", username)
|
||||
.executeTakeFirst();
|
||||
|
||||
invariant(user, `user with username ${username} not found`);
|
||||
|
||||
if (!webPushEnabled) {
|
||||
logger.warn(
|
||||
"VAPID env vars not set, only the in-app notification will be created",
|
||||
);
|
||||
}
|
||||
|
||||
const subscriptions =
|
||||
await NotificationRepository.findAllSubscriptionsByUserIds([user.id]);
|
||||
logger.info(
|
||||
`${user.username} (id ${user.id}) has ${subscriptions.length} push subscription(s)`,
|
||||
);
|
||||
|
||||
await notify({
|
||||
userIds: [user.id],
|
||||
notification: { type: "SEASON_STARTED", meta: { seasonNth } },
|
||||
skipPushGracePeriod: true,
|
||||
});
|
||||
|
||||
logger.info("Notification sent");
|
||||
|
||||
process.exit(0);
|
||||
Reference in New Issue
Block a user