diff --git a/models/goal.js b/models/goal.js new file mode 100644 index 0000000..bf88c9b --- /dev/null +++ b/models/goal.js @@ -0,0 +1,39 @@ +const mongoose = require("mongoose"); + +const GoalSchema = new mongoose.Schema({ + name: { + type: String, + required: true + }, + targetAmount: { + type: Number, + required: true + }, + targetDate: { + type: Date, + required: true + }, + balance: { + type: Number, + default: 0 + }, + transactionIds: [{ + type: mongoose.Schema.Types.ObjectId, + ref: "Transaction" + }], + tagIds: [{ + type: mongoose.Schema.Types.ObjectId, + ref: "Tag" + }], + icon: { + type: String, + required: false + }, + userId: { + type: mongoose.Schema.Types.ObjectId, + ref: "User", + required: true + } +}); + +module.exports = mongoose.model("Goal", GoalSchema); \ No newline at end of file diff --git a/src/lib/updateGoalIcon.js b/src/lib/updateGoalIcon.js new file mode 100644 index 0000000..8668554 --- /dev/null +++ b/src/lib/updateGoalIcon.js @@ -0,0 +1,20 @@ +// Function to update goal icon using PUT request + +export async function updateGoalIcon(goalId, icon) { + const response = await fetch(`/api/goals/${goalId}`, { + method: "PUT", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({ + icon: icon + }) + }); + + return response.json(); +} + +// Emoji click handler +export function pickEmojiOnClick(goalId, emoji) { + return updateGoalIcon(goalId, emoji); +} \ No newline at end of file diff --git a/src/models/goal.model.js b/src/models/goal.model.js new file mode 100644 index 0000000..bdbee7b --- /dev/null +++ b/src/models/goal.model.js @@ -0,0 +1,13 @@ +// Frontend Goal model (client-side) + +export const Goal = { + id: "1234", + name: "abcd", + targetAmount: 100000, + targetDate: "01 jan - 01 dec", + balance: 0, + transactionIds: [0234], + tagIds: [234], + icon: "", // optional emoji/icon + userId: "" +}; \ No newline at end of file diff --git a/task5.txt b/task5.txt new file mode 100644 index 0000000..8ace9f6 --- /dev/null +++ b/task5.txt @@ -0,0 +1,5 @@ +Task 5 – Create a Pull Request + +I created a new branch for Task 5. +I committed this file to my branch. +I will submit this change using a pull request. diff --git a/tests/getGoalsForUser.test.js b/tests/getGoalsForUser.test.js new file mode 100644 index 0000000..458e635 --- /dev/null +++ b/tests/getGoalsForUser.test.js @@ -0,0 +1,16 @@ +// Test for GetGoalsForUser route + +describe("GET /goals/user/:userId", () => { + it("should return goals for a given user", () => { + const mockUserId = "12345"; + + // expected behaviour + const expectedResponse = { + status: 200, + body: [] + }; + + expect(expectedResponse.status).toBe(200); + expect(Array.isArray(expectedResponse.body)).toBe(true); + }); +}); \ No newline at end of file