-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- persist data in database - add password authentication - extract messages into own file - refactor bot code => make app more robust
- Loading branch information
Showing
15 changed files
with
454 additions
and
136 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
TELEGRAM_BOT_TOKEN="YOUR_TELEGRAM_BOT_TOKEN" | ||
TELEGRAM_BOT_TOKEN="YOUR_TELEGRAM_BOT_TOKEN" | ||
DATABASE_URL="YOUR_DATABASE_URL" | ||
PASSWORD="YOUR_PASSWORD" |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
node_modules | ||
out | ||
.env | ||
build | ||
.env | ||
*.db | ||
TODO |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,47 @@ | ||
-- CreateTable | ||
CREATE TABLE "Roomie" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"name" TEXT NOT NULL, | ||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" DATETIME NOT NULL, | ||
"done" BOOLEAN NOT NULL DEFAULT false, | ||
"dutyId" INTEGER, | ||
CONSTRAINT "Roomie_dutyId_fkey" FOREIGN KEY ("dutyId") REFERENCES "Duty" ("id") ON DELETE SET NULL ON UPDATE CASCADE | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Duty" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"title" TEXT NOT NULL, | ||
"description" TEXT NOT NULL, | ||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" DATETIME NOT NULL | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Trash" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"title" TEXT NOT NULL | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "TrashCollection" ( | ||
"date" DATETIME NOT NULL PRIMARY KEY | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "_TrashToTrashCollection" ( | ||
"A" INTEGER NOT NULL, | ||
"B" DATETIME NOT NULL, | ||
CONSTRAINT "_TrashToTrashCollection_A_fkey" FOREIGN KEY ("A") REFERENCES "Trash" ("id") ON DELETE CASCADE ON UPDATE CASCADE, | ||
CONSTRAINT "_TrashToTrashCollection_B_fkey" FOREIGN KEY ("B") REFERENCES "TrashCollection" ("date") ON DELETE CASCADE ON UPDATE CASCADE | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Roomie_dutyId_key" ON "Roomie"("dutyId"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "_TrashToTrashCollection_AB_unique" ON "_TrashToTrashCollection"("A", "B"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "_TrashToTrashCollection_B_index" ON "_TrashToTrashCollection"("B"); |
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,3 @@ | ||
# Please do not edit this file manually | ||
# It should be added in your version-control system (i.e. Git) | ||
provider = "sqlite" |
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,38 @@ | ||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
datasource db { | ||
provider = "sqlite" | ||
url = env("DATABASE_URL") | ||
} | ||
|
||
model Roomie { | ||
id Int @id @default(autoincrement()) | ||
name String | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
done Boolean @default(false) | ||
dutyId Int? @unique | ||
duty Duty? @relation(fields: [dutyId], references: [id]) | ||
} | ||
|
||
model Duty { | ||
id Int @id @default(autoincrement()) | ||
title String | ||
description String | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
roomie Roomie? | ||
} | ||
|
||
model Trash { | ||
id Int @id @default(autoincrement()) | ||
title String | ||
trashCollection TrashCollection[] | ||
} | ||
|
||
model TrashCollection { | ||
date DateTime @id | ||
trash Trash[] | ||
} |
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,71 @@ | ||
import { PrismaClient } from "@prisma/client"; | ||
import { trash } from "../src/data"; | ||
|
||
const prisma = new PrismaClient(); | ||
|
||
const seed = async () => { | ||
try { | ||
await Promise.all( | ||
[ | ||
{ | ||
title: "🛀🏽 Badezimmer", | ||
description: "Badezimmer putzen", | ||
}, | ||
{ | ||
title: "👨🏽🍳 Küche", | ||
description: "Küche putzen", | ||
}, | ||
{ | ||
title: "🧹 Wohnzimmer", | ||
description: "Wohnzimmer aufräumen", | ||
}, | ||
{ | ||
title: "🗑️ Müll", | ||
description: "Müll rausbringen", | ||
}, | ||
].map(async (data) => await prisma.duty.create({ data })) | ||
); | ||
|
||
await Promise.all( | ||
[ | ||
"🟦 Papiertonne", | ||
"⬛️ Restabfalltonne", | ||
"🟫 Biotonne", | ||
"🟨 Wertstofftonne", | ||
"🟧 Sperrgut, Grünabfall", | ||
].map(async (title) => await prisma.trash.create({ data: { title } })) | ||
); | ||
|
||
await Promise.all( | ||
[...new Set(Object.keys(trash))].map( | ||
async (key) => | ||
await prisma.trashCollection.create({ | ||
data: { | ||
date: new Date(key), | ||
}, | ||
}) | ||
) | ||
); | ||
|
||
// TODO @ematala implement/fix | ||
// await Promise.all( | ||
// Object.entries(trash).map( | ||
// async ([key, values]) => | ||
// await prisma.trashCollection.update({ | ||
// where: { | ||
// date: new Date(key), | ||
// }, | ||
// data: { | ||
// trash: { | ||
// connect: values.map((id) => ({ id })), | ||
// }, | ||
// }, | ||
// }) | ||
// ) | ||
// ); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}; | ||
|
||
seed(); |
This file was deleted.
Oops, something went wrong.
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.