generated from trywilco/Anythink-Market-Public
-
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.
- Loading branch information
WilcoApp
committed
Dec 28, 2023
1 parent
145c1e5
commit d73d068
Showing
1 changed file
with
58 additions
and
1 deletion.
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,58 @@ | ||
//TODO: seeds script should come here, so we'll be able to put some data in our local env | ||
require("dotenv").config(); | ||
const mongoose = require("mongoose"); | ||
require("../models/User"); | ||
require("../models/Item"); | ||
require("../models/Comment"); | ||
|
||
const User = mongoose.model("User"); | ||
const Item = mongoose.model("Item"); | ||
|
||
const connectToDatabase = () => { | ||
const connection = process.env.MONGODB_URI || "mongodb://localhost:27017/anythink-market"; | ||
mongoose.connect(connection); | ||
mongoose.set("debug", true); | ||
}; | ||
|
||
async function main() { | ||
connectToDatabase(); | ||
const verifiedUser = new User({ | ||
username: 'verifiedUser', | ||
email: `verifiedUser@gmail.com`, | ||
isVerified: true | ||
}); | ||
await verifiedUser.save(); | ||
|
||
const notVerifiedUser = new User({ | ||
username: 'notVerifiedUser', | ||
email: 'notVerifiedUser@gmail.com', | ||
isVerified: false, | ||
} | ||
); | ||
await notVerifiedUser.save(); | ||
|
||
const itemForVerifiedUser = new Item({ | ||
slug: `verified_seller_item`, | ||
title: `Verified seller item`, | ||
description: `description for the item`, | ||
seller: verifiedUser, | ||
}); | ||
await itemForVerifiedUser.save(); | ||
|
||
const itemForNotVerifiedUser = new Item({ | ||
slug: `not_verified_seller_item`, | ||
title: `Not Verified seller item`, | ||
description: `description for the item`, | ||
seller: notVerifiedUser, | ||
}); | ||
await itemForNotVerifiedUser.save(); | ||
} | ||
|
||
main() | ||
.then(() => { | ||
console.log("Finished DB seeding"); | ||
process.exit(0); | ||
}) | ||
.catch((err) => { | ||
console.log(`Error while running DB seed: ${err.message}`); | ||
process.exit(1); | ||
}); |