-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
converted project to use ES6 modules
- Loading branch information
1 parent
3335425
commit 1136c7e
Showing
8 changed files
with
1,076 additions
and
115 deletions.
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
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,20 +1,19 @@ | ||
const BookNamesModel = require("../../V1/DB/models/bookName") | ||
import BookNamesModel from '../../V1/DB/models/bookName.js'; | ||
|
||
const escapeRegExp = (string) => { | ||
return string.toString().replace(/[.*+?^${}|()[\]\\]/g, "\\$&"); // $& means the whole matched string | ||
export const escapeRegExp = (string) => { | ||
return string.toString().replace(/[.*+?^${}|()[\]\\]/g, '\\$&'); // $& means the whole matched string | ||
}; | ||
const returnBookIds = async () => { | ||
const bookNames = await BookNamesModel.find({}); | ||
return bookNames.map((book) => { | ||
return book["bookId"]; | ||
}); | ||
export const returnBookIds = async () => { | ||
const bookNames = await BookNamesModel.find({}); | ||
return bookNames.map((book) => { | ||
return book['bookId']; | ||
}); | ||
}; | ||
|
||
|
||
const compareAlphabetically = (a, b) => { | ||
a = a.toLowerCase(); | ||
b = b.toLowerCase(); | ||
return a < b ? -1 : a > b ? 1 : 0; | ||
export const compareAlphabetically = (a, b) => { | ||
a = a.toLowerCase(); | ||
b = b.toLowerCase(); | ||
return a < b ? -1 : a > b ? 1 : 0; | ||
}; | ||
|
||
module.exports = { escapeRegExp, returnBookIds, compareAlphabetically }; | ||
// export default { escapeRegExp, returnBookIds, compareAlphabetically }; |
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,31 +1,36 @@ | ||
require('dotenv').config() | ||
const mongoose = require('mongoose') | ||
const url = process.env.MONGODB_URI | ||
// require('dotenv').config(); | ||
import dotenv from 'dotenv'; | ||
dotenv.config() | ||
import { connect, model, Schema } from 'mongoose'; | ||
const url = process.env.MONGODB_URI; | ||
|
||
mongoose.connect(url) | ||
.then(result => { | ||
console.log('connected to MongoDB') | ||
}) | ||
.catch((error) => { | ||
console.log('error connecting to MongoDB:', error.message) | ||
}) | ||
connect(url) | ||
.then((result) => { | ||
console.log('connected to MongoDB'); | ||
}) | ||
.catch((error) => { | ||
console.log('error connecting to MongoDB:', error.message); | ||
}); | ||
|
||
const bookName = new mongoose.Schema({ | ||
bookId: String, | ||
BookName: String, | ||
author:String, | ||
idRangeMin:Number, | ||
idRangeMax:Number | ||
}, { | ||
strict:false | ||
}) | ||
const bookName = new Schema( | ||
{ | ||
bookId: String, | ||
BookName: String, | ||
author: String, | ||
idRangeMin: Number, | ||
idRangeMax: Number, | ||
}, | ||
{ | ||
strict: false, | ||
} | ||
); | ||
|
||
bookName.set('toJson', { | ||
transform: (document, returnedObject) => { | ||
returnedObject.id = returnedObject._id.toString() | ||
delete returnedObject._id | ||
delete returnedObject.__v | ||
} | ||
}) | ||
bookName.set('toJson', { | ||
transform: (document, returnedObject) => { | ||
returnedObject.id = returnedObject._id.toString(); | ||
delete returnedObject._id; | ||
delete returnedObject.__v; | ||
}, | ||
}); | ||
|
||
module.exports = mongoose.model('bookNames', bookName, 'bookNames') | ||
export default model('bookNames', bookName, 'bookNames'); |
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
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,31 +1,36 @@ | ||
require('dotenv').config() | ||
const mongoose = require('mongoose') | ||
const url = process.env.MONGODB_URI | ||
// require('dotenv').config(); | ||
import dotenv from 'dotenv'; | ||
dotenv.config() | ||
import { connect, model, Schema } from 'mongoose'; | ||
const url = process.env.MONGODB_URI; | ||
|
||
mongoose.connect(url) | ||
.then(result => { | ||
console.log('connected to MongoDB') | ||
}) | ||
.catch((error) => { | ||
console.log('error connecting to MongoDB:', error.message) | ||
}) | ||
connect(url) | ||
.then((result) => { | ||
console.log('connected to MongoDB'); | ||
}) | ||
.catch((error) => { | ||
console.log('error connecting to MongoDB:', error.message); | ||
}); | ||
|
||
const bookNameV2 = new mongoose.Schema({ | ||
bookId: String, | ||
BookName: String, | ||
author:String, | ||
idRangeMin:Number, | ||
idRangeMax:Number | ||
}, { | ||
strict:false | ||
}) | ||
const bookNameV2 = new Schema( | ||
{ | ||
bookId: String, | ||
BookName: String, | ||
author: String, | ||
idRangeMin: Number, | ||
idRangeMax: Number, | ||
}, | ||
{ | ||
strict: false, | ||
} | ||
); | ||
|
||
bookNameV2.set('toJson', { | ||
transform: (document, returnedObject) => { | ||
returnedObject.id = returnedObject._id.toString() | ||
delete returnedObject._id | ||
delete returnedObject.__v | ||
} | ||
}) | ||
bookNameV2.set('toJson', { | ||
transform: (document, returnedObject) => { | ||
returnedObject.id = returnedObject._id.toString(); | ||
delete returnedObject._id; | ||
delete returnedObject.__v; | ||
}, | ||
}); | ||
|
||
module.exports = mongoose.model('bookNamesV2', bookNameV2, 'bookNamesV2') | ||
export default model('bookNamesV2', bookNameV2, 'bookNamesV2'); |
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
Oops, something went wrong.