forked from Sara-AM91/finance-tracker-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateCategoryIcons.js
54 lines (48 loc) · 1.56 KB
/
updateCategoryIcons.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const mongoose = require("mongoose");
const Category = require("./models/CategoryModel");
const dotenv = require("dotenv");
dotenv.config();
//Connect to your MongoDB database
mongoose.connect(process.env.MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
//Define the icons based on the category titles
const iconMapping = {
Educations: "educations.png",
"Groceries & Food": "food.png",
"Child Support": "child-support.png",
Shopping: "shopping.png",
Entertainment: "entertainment.png",
Healthcare: "healthcare.png",
Rent: "rent.png",
Salary: "salary.png",
Gifts: "gift.png",
Freelance: "freelancer.png",
Interest: "interest.png",
Investments: "investments.png",
"Social Security": "social-security.png",
Pension: "pension.png",
Transportation: "transportation.png",
"Utilities & Bills": "utilities.png",
Interest: "interest.png",
"Stock Sales": "stock-sales.png",
Other: "other.png",
};
//Function to update each category with its corresponding icon
const updateCategories = async () => {
try {
for (const [title, icon] of Object.entries(iconMapping)) {
//Update the category with the corresponding icon based on the title
const result = await Category.updateMany({ title }, { $set: { icon } });
console.log(`Updated category "${title}" with icon "${icon}":`, result);
}
console.log("All categories updated successfully!");
} catch (error) {
console.error("Error updating categories:", error);
} finally {
mongoose.disconnect();
}
};
//Execute the update function
updateCategories();