import mongoose from "mongoose"; import ItemListModel from "./model/todo-list"; import ItemModel from "./model/todo-item"; export const connect = async () => { await mongoose.connect(process.env.MONGO_CONNECT_URL!); console.log("Connected to database"); const lists = await ItemListModel.find(); console.log(JSON.stringify(lists, null, 4)) if (lists.length === 0) { await ItemListModel.create({ name: "Test List", }); const item = await ItemModel.create({ title: "Test Item", }); lists.forEach(async (list) => { await (list as unknown as any).addItem(item); }) } console.log("Database initiated"); };