A simple to-do app focused on tasks that can be completed within a specific time span.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

works

+42 -8
+1 -1
server/tasks/notify/push.ts
··· 1 1 export default defineTask({ 2 2 async run(_event) { 3 - console.log("Task running"); 3 + await Todos.sendMsg() 4 4 5 5 const result = { 6 6 sent: 10,
+3 -2
server/utils/authHandle.ts
··· 37 37 return createError({ 38 38 statusCode: 400, 39 39 statusMessage: "No Session set", 40 - }); 40 + }); 41 + 41 42 } 42 43 43 44 return result.session.userId; 44 45 } 45 - }, 46 + }, 46 47 47 48 async getUserIdOrThrow(event: H3Event): Promise<string> { 48 49 const session = await AuthApi.getUserId(event);
+3 -3
server/utils/db/subscription.ts
··· 43 43 message: `Subscription already exists`, 44 44 }); 45 45 }, 46 - async sendNotification(userId: string) { 46 + async sendNotification(userId: string, title: string, body: string) { 47 47 const subscriptions = await Subscriptions.getAll(userId); 48 48 49 49 const payload = JSON.stringify({ 50 - title: "Erinnerung", 51 - body: "Zeit für XYZ", 50 + title: title, 51 + body: body, 52 52 }); 53 53 54 54 for (const sub of subscriptions) {
+35 -2
server/utils/db/todos.ts
··· 1 1 import type { NuxtError } from "nuxt/app"; 2 2 import { updateOrInsertAfterTodo } from "~~/shared/array"; 3 3 import { toLocalDateString } from "~~/shared/date"; 4 - import type { Todo, UUID } from "~~/shared/types"; 4 + import { Time, type Todo, type UUID } from "~~/shared/types"; 5 5 6 6 function getKey(userId: string): string { 7 7 return `todos:${userId}`; ··· 11 11 async getAll(userId: string): Promise<Todo[]> { 12 12 const storage = useStorage(); 13 13 return (await storage.get<Todo[]>(getKey(userId))) ?? []; 14 - }, 14 + }, 15 + 16 + async sendMsg(): Promise<void> { 17 + const keys = await useStorage().getKeys(); 18 + const filteredKeys = keys.filter((key) => key.startsWith("todos:")); 19 + 20 + filteredKeys.forEach(async (key) => { 21 + const todos = await useStorage().get<Todo[]>(key); 22 + 23 + todos?.forEach(todo => { 24 + if (todo.time?.type === "point") { 25 + const date = new Date(todo.time.time); 26 + const now = new Date(); 27 + 28 + const sameMinute = 29 + date.getUTCFullYear() === now.getUTCFullYear() && 30 + date.getUTCMonth() === now.getUTCMonth() && 31 + date.getUTCDate() === now.getUTCDate() && 32 + date.getUTCHours() === now.getUTCHours() && 33 + date.getUTCMinutes() === now.getUTCMinutes(); 34 + 35 + if (sameMinute) { 36 + Subscriptions.sendNotification(key.substring(6), todo.title, todo.note); 37 + } 38 + } 39 + }) 40 + }) 41 + }, 42 + 43 + async getAllWithTimeStamp(userId: string): Promise<Todo[]> { 44 + let todos = await Todos.getAll(userId); 45 + 46 + return todos.filter(todo => todo.time?.type === "range"); 47 + }, 15 48 16 49 async move( 17 50 userId: string,