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
39 changes: 39 additions & 0 deletions models/goal.js
Original file line number Diff line number Diff line change
@@ -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);
20 changes: 20 additions & 0 deletions src/lib/updateGoalIcon.js
Original file line number Diff line number Diff line change
@@ -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);
}
13 changes: 13 additions & 0 deletions src/models/goal.model.js
Original file line number Diff line number Diff line change
@@ -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: ""
};
5 changes: 5 additions & 0 deletions task5.txt
Original file line number Diff line number Diff line change
@@ -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.
16 changes: 16 additions & 0 deletions tests/getGoalsForUser.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});