todo list
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
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._id);
|
||||
})
|
||||
}
|
||||
|
||||
console.log("Database initiated");
|
||||
};
|
||||
Reference in New Issue
Block a user