Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/config/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const connectDB = async () => {
throw new Error("Invalid NODE_ENV specified");
}
try {
const conn = await mongoose.connect(process.env.MONGO_URI_DEVELOPMENT, {
const mongoURI =
process.env.NODE_ENV === "production"
? process.env.MONGO_URI_PROD
: process.env.MONGO_URI_DEV;

const conn = await mongoose.connect(mongoURI, {
useNewUrlParser: true,
useUnifiedTopology: true,
Expand Down
32 changes: 32 additions & 0 deletions server/data/artist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"_id": "60c72b3f4f7d5c001f6471a1",
"name": {
"hebrew": "אביב גפן",
"arabic": "أفيف جيفن",
"english": "Aviv Geffen"
},
"imgURL": "https://example.com/aviv_geffen.jpg",
"albums": ["Blackfield", "Blackfield II"]
},
{
"_id": "60c72b3f4f7d5c001f6471a2",
"name": {
"hebrew": "אריק איינשטיין",
"arabic": "أريك أينشتاين",
"english": "Arik Einstein"
},
"imgURL": "https://example.com/arik_einstein.jpg",
"albums": ["Good Old Eretz Israel", "Songs of the Paratroopers"]
},
{
"_id": "60c72b3f4f7d5c001f6471a4",
"name": {
"hebrew": "שלמה ארצי",
"arabic": "شلومو أرتزي",
"english": "Shlomo Artzi"
},
"imgURL": "https://example.com/shlomo_artzi.jpg",
"albums": ["Songs of My Beloved Land", "A Man Reflects on a Woman"]
}
]
56 changes: 56 additions & 0 deletions server/data/song.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[
{
"_id": "60c72b3f4f7d5c001f6471b1",
"name": {
"hebrew": "אחרי שהכל נגמר",
"arabic": "بعد أن انتهى كل شيء",
"english": "After Everything is Over"
},
"lyrics": {
"hebrew": "אחרי שהכל נגמר...",
"arabic": "بعد أن انتهى كل شيء...",
"english": "After everything is over..."
},
"originalLang": "hebrew",
"artist": "60c72b3f4f7d5c001f6471a1",
"imgURL": "https://example.com/after_everything_is_over.jpg",
"album": "Blackfield",
"youtubeURL": "https://www.youtube.com/watch?v=example1"
},
{
"_id": "60c72b3f4f7d5c001f6471b2",
"name": {
"hebrew": "אני ואתה",
"arabic": "أنا وأنت",
"english": "Me and You"
},
"lyrics": {
"hebrew": "אני ואתה...",
"arabic": "أنا وأنت...",
"english": "Me and you..."
},
"originalLang": "hebrew",
"artist": "60c72b3f4f7d5c001f6471a2",
"imgURL": "https://example.com/me_and_you.jpg",
"album": "Good Old Eretz Israel",
"youtubeURL": "https://www.youtube.com/watch?v=example2"
},
{
"_id": "60c72b3f4f7d5c001f6471b3",
"name": {
"hebrew": "מרץ",
"arabic": "مرتز",
"english": "March"
},
"lyrics": {
"hebrew": "מרץ, מרץ, תירוץ, תירוץ...",
"arabic": "مرتز، مرتز، تيروز، تيروز...",
"english": "March, march, excuse, excuse..."
},
"originalLang": "hebrew",
"artist": "60c72b3f4f7d5c001f6471a4",
"imgURL": "https://example.com/march.jpg",
"album": "Songs of My Beloved Land",
"youtubeURL": "https://www.youtube.com/watch?v=example3"
}
]
142 changes: 142 additions & 0 deletions server/data/topSongs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
[
{
"_id": "60c72b3f4f7d5c001f6471d1",
"date": "2023-06-14T12:34:56.789Z",
"language": "hebrew",
"songs": ["60c3cfc5546eef0015f6b8e1"],
"imgURL": "https://example.com/song1.jpg"
},
{
"_id": "60c72b3f4f7d5c001f6471d2",
"date": "2023-06-14T12:34:56.789Z",
"language": "hebrew",
"songs": ["60c3cfc5546eef0015f6b8e2"],
"imgURL": "https://example.com/song2.jpg"
},
{
"_id": "60c72b3f4f7d5c001f6471d3",
"date": "2023-06-14T12:34:56.789Z",
"language": "hebrew",
"songs": ["60c3cfc5546eef0015f6b8e3"],
"imgURL": "https://example.com/song3.jpg"
},
{
"_id": "60c72b3f4f7d5c001f6471d4",
"date": "2023-06-14T12:34:56.789Z",
"language": "hebrew",
"songs": ["60c3cfc5546eef0015f6b8e4"],
"imgURL": "https://example.com/song4.jpg"
},
{
"_id": "60c72b3f4f7d5c001f6471d5",
"date": "2023-06-14T12:34:56.789Z",
"language": "hebrew",
"songs": ["60c3cfc5546eef0015f6b8e5"],
"imgURL": "https://example.com/song5.jpg"
},
{
"_id": "60c72b3f4f7d5c001f6471d6",
"date": "2023-06-14T12:34:56.789Z",
"language": "hebrew",
"songs": ["60c3cfc5546eef0015f6b8e6"],
"imgURL": "https://example.com/song6.jpg"
},
{
"_id": "60c72b3f4f7d5c001f6471d7",
"date": "2023-06-14T12:34:56.789Z",
"language": "hebrew",
"songs": ["60c3cfc5546eef0015f6b8e7"],
"imgURL": "https://example.com/song7.jpg"
},
{
"_id": "60c72b3f4f7d5c001f6471d8",
"date": "2023-06-14T12:34:56.789Z",
"language": "hebrew",
"songs": ["60c3cfc5546eef0015f6b8e8"],
"imgURL": "https://example.com/song8.jpg"
},
{
"_id": "60c72b3f4f7d5c001f6471d9",
"date": "2023-06-14T12:34:56.789Z",
"language": "hebrew",
"songs": ["60c3cfc5546eef0015f6b8e9"],
"imgURL": "https://example.com/song9.jpg"
},
{
"_id": "60c72b3f4f7d5c001f647110",
"date": "2023-06-14T12:34:56.789Z",
"language": "hebrew",
"songs": ["60c3cfc5546eef0015f6b810"],
"imgURL": "https://example.com/son10.jpg"
},
{
"_id": "60c72b3f4f7d5c001f647111",
"date": "2023-06-14T12:34:56.789Z",
"language": "arabic",
"songs": ["60c3cfc5546eef0015f6b811"],
"imgURL": "https://example.com/son11.jpg"
},
{
"_id": "60c72b3f4f7d5c001f647112",
"date": "2023-06-14T12:34:56.789Z",
"language": "arabic",
"songs": ["60c3cfc5546eef0015f6b812"],
"imgURL": "https://example.com/son12.jpg"
},
{
"_id": "60c72b3f4f7d5c001f647113",
"date": "2023-06-14T12:34:56.789Z",
"language": "arabic",
"songs": ["60c3cfc5546eef0015f6b813"],
"imgURL": "https://example.com/son13.jpg"
},
{
"_id": "60c72b3f4f7d5c001f647114",
"date": "2023-06-14T12:34:56.789Z",
"language": "arabic",
"songs": ["60c3cfc5546eef0015f6b814"],
"imgURL": "https://example.com/son14.jpg"
},
{
"_id": "60c72b3f4f7d5c001f647115",
"date": "2023-06-14T12:34:56.789Z",
"language": "arabic",
"songs": ["60c3cfc5546eef0015f6b815"],
"imgURL": "https://example.com/son15.jpg"
},
{
"_id": "60c72b3f4f7d5c001f647116",
"date": "2023-06-14T12:34:56.789Z",
"language": "arabic",
"songs": ["60c3cfc5546eef0015f6b816"],
"imgURL": "https://example.com/son16.jpg"
},
{
"_id": "60c72b3f4f7d5c001f647117",
"date": "2023-06-14T12:34:56.789Z",
"language": "arabic",
"songs": ["60c3cfc5546eef0015f6b817"],
"imgURL": "https://example.com/son17.jpg"
},
{
"_id": "60c72b3f4f7d5c001f647118",
"date": "2023-06-14T12:34:56.789Z",
"language": "arabic",
"songs": ["60c3cfc5546eef0015f6b818"],
"imgURL": "https://example.com/son18.jpg"
},
{
"_id": "60c72b3f4f7d5c001f647119",
"date": "2023-06-14T12:34:56.789Z",
"language": "arabic",
"songs": ["60c3cfc5546eef0015f6b819"],
"imgURL": "https://example.com/son19.jpg"
},
{
"_id": "60c72b3f4f7d5c001f647120",
"date": "2023-06-14T12:34:56.789Z",
"language": "arabic",
"songs": ["60c3cfc5546eef0015f6b820"],
"imgURL": "https://example.com/son20.jpg"
}
]
66 changes: 66 additions & 0 deletions server/generateDummyData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import fs from "fs";
import mongoose from "mongoose";
import dotenv from "dotenv";

import { fileURLToPath } from "url";
import { join, dirname } from "path";

import Artist from "./models/Artist.js";
import Song from "./models/Song.js";
import TopSongs from "./models/TopSongs.js";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

dotenv.config({ path: join(__dirname, "./config/config.env") });

mongoose.connect(process.env.MONGO_URI_DEV, {
useNewUrlParser: true,
useUnifiedTopology: true,
});

const artist = JSON.parse(
fs.readFileSync(new URL("./data/artist.json", import.meta.url), "utf-8")
);

const song = JSON.parse(
fs.readFileSync(new URL("./data/song.json", import.meta.url), "utf-8")
);

const topSongs = JSON.parse(
fs.readFileSync(new URL("./data/topSongs.json", import.meta.url), "utf-8")
);

// Import into DB
const importData = async () => {
try {
await Artist.create(artist);
await Song.create(song);
await TopSongs.create(topSongs);

console.log("Data Imported...");
process.exit();
} catch (err) {
console.error(err);
}
};

// Delete data
const deleteData = async () => {
try {
await Artist.deleteMany({ imgURL: { $regex: /https:\/\/example\.com/ } });
await Song.deleteMany({ imgURL: { $regex: /https:\/\/example\.com/ } });
await TopSongs.deleteMany({ imgURL: { $regex: /https:\/\/example\.com/ } });

console.log("Data Destroyed...");
process.exit();
} catch (err) {
console.error(err);
}
};

if (process.argv[2] === "-i") {
importData();
} else if (process.argv[2] === "-d") {
deleteData();
}
1 change: 1 addition & 0 deletions server/models/Song.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import mongoose from "mongoose";
import Artist from "./Artist.js";
import asyncHandler from "../middleware/asyncHandler.js";
import ErrorResponse from "../utils/ErrorResponse.js";

const SongSchema = new mongoose.Schema(
{
Expand Down
70 changes: 34 additions & 36 deletions server/models/TopSongs.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
import mongoose from "mongoose";

const TopSongsSchema = new mongoose.Schema(
{
date:{
type: Date,
default: Date.now,
},
language: {
type: String,
required: [true, "Please add language"],
enum: ['hebrew', 'arabic']
},
songs:[
{
type: mongoose.Schema.Types.ObjectId,
ref: 'Song',
}
],
// This field needs to be refractured:
imgURL: {
type: String,
},
{
date: {
type: Date,
default: Date.now,
},
{
toJSON: {
transform(_, ret) {
delete ret.__v;
},
},
toObject: {
transform(_, ret) {
delete ret.__v;
},
},
}

)

language: {
type: String,
required: [true, "Please add language"],
enum: ["hebrew", "arabic"],
},
songs: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "Song",
},
],
// This field needs to be refractured:
imgURL: {
type: String,
},
},
{
toJSON: {
transform(_, ret) {
delete ret.__v;
},
},
toObject: {
transform(_, ret) {
delete ret.__v;
},
},
}
);

export default mongoose.model("TopSongs", TopSongsSchema);
export default mongoose.model("TopSongs", TopSongsSchema);
Loading