Skip to content

Commit

Permalink
Adding seeds script
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoApp committed Dec 12, 2024
1 parent 71a6a75 commit 0977bcd
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion backend/scripts/seeds.js
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: `[email protected]`,
isVerified: true
});
await verifiedUser.save();

const notVerifiedUser = new User({
username: 'notVerifiedUser',
email: '[email protected]',
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);
});

0 comments on commit 0977bcd

Please sign in to comment.