Skip to content

Commit

Permalink
fix(database-seeder): fastify error & update
Browse files Browse the repository at this point in the history
  • Loading branch information
eevan7a9 committed Dec 4, 2022
1 parent 3a0c51d commit b936cab
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions backend-fastify/src/database-seeder/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import dotenv from "dotenv";
import mongoose from "mongoose";

import { fastify } from '../index.js';
import { User } from "../models/user.js";
import { users } from "./dummy-data/users.js";

Expand Down Expand Up @@ -31,31 +31,29 @@ const seederProperty = async () => {
const seederEnquiry = async () => {
await Enquiry.deleteMany({});
console.log("Enquiry document - is now empty!");

await Enquiry.insertMany(enquiries);
console.log("Enquiry document - Seed Successful!");
};

mongoose
.connect(process.env.DB_CONNECT, {
useUnifiedTopology: true,
useNewUrlParser: true,
})
.then(() => {
console.log("Mongo connection open for data seeding!!!");

const db = async () => {
/**
* !!!WARNING!!!
* We empty all documents & seed with dummy data
*/
await seederUser();
await seederProperty();
await seederEnquiry();
};

db().then(() => {
mongoose.connection.close();
});
})
.catch((e) => fastify.log.error(e));

const database = mongoose.connect(process.env.DB_CONNECT, {
useUnifiedTopology: true,
useNewUrlParser: true,
}).then(async (con) => {
console.log("Mongo connection open for data seeding!!!");
const db = async () => {
/**
* !!!WARNING!!!
* We empty all documents & seed with dummy data
*/
await seederUser();
await seederProperty();
await seederEnquiry();
console.log("Database Seeder: Success!!!")
};
await db();
await con.disconnect();
await con.connection.close();

}).catch((e) => fastify.log.error(e));

0 comments on commit b936cab

Please sign in to comment.