Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aditya #37

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions backend/dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const core_1 = require("@nestjs/core");
const app_module_1 = require("./app.module");
const dotenv = __importStar(require("dotenv"));
const aws_sdk_1 = __importDefault(require("aws-sdk"));
aws_sdk_1.default.config.update({ region: 'us-east-2' });
/* ! */
async function bootstrap() {
aws_sdk_1.default.config.update({
Expand Down
3 changes: 3 additions & 0 deletions backend/dist/user/user.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.UserService = void 0;
const common_1 = require("@nestjs/common");
const aws_sdk_1 = __importDefault(require("aws-sdk"));
aws_sdk_1.default.config.update({ region: 'us-east-2' }); // need to explicitly mention the region here otherwise an error is thrown for some reason
const dynamodb = new aws_sdk_1.default.DynamoDB.DocumentClient();
let UserService = class UserService {
async getAllUsers() {
Expand All @@ -23,6 +24,7 @@ let UserService = class UserService {
return data.Items;
}
catch (error) {
console.log(error);
throw new Error('Could not retrieve users.');
}
}
Expand All @@ -38,6 +40,7 @@ let UserService = class UserService {
return data.Item;
}
catch (error) {
console.log(error);
throw new Error('Could not retrieve user.');
}
}
Expand Down
2 changes: 2 additions & 0 deletions backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { AppModule } from './app.module';
import * as dotenv from 'dotenv'
import AWS from 'aws-sdk';

AWS.config.update({ region: 'us-east-2' });

/* ! */
async function bootstrap() {
AWS.config.update({
Expand Down
77 changes: 59 additions & 18 deletions backend/src/notifications/notifcation.service.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
// src/notifications/notifications.service.ts
import { Injectable } from '@nestjs/common';
import * as AWS from 'aws-sdk';
import { Notification } from './notification.model'; // Adjust the path as needed
import { Notification } from './notification.model';




AWS.config.update({ region: 'us-east-1' });
AWS.config.update({ region: 'us-east-1' });
const dynamodb = new AWS.DynamoDB.DocumentClient();


@Injectable()
export class NotificationService {


// Function to create a notification
// function to create a notification
async createNotification(notification: Notification): Promise<Notification> {

const alertTime = new Date(notification.alertTime); // Ensures a Date can be created from the given alertTime
const alertTime = new Date(notification.alertTime); // ensures a Date can be created from the given alertTime


const params = {
Expand All @@ -32,31 +31,73 @@ export class NotificationService {
}


// function to find notifications by notification id
async getNotificationByUserId(userId: string): Promise<Notification> {
// function that returns array of notifications by user id (sorted by most recent notifications first)
async getNotificationByUserId(userId: string): Promise<Notification[]> {

console.log("USER ID", userId)

const params = {
TableName: process.env.DYNAMODB_NOTIFICATION_TABLE_NAME || 'TABLE_FAILURE',
Key: {
userId : userId
},
};
// KeyConditionExpression specifies the query condition
// ExpressionAttributeValues specifies the actual value of the key
// IndexName specifies our Global Secondary Index, which was created in the BCANNotifs table to
// allow for querying by userId, as it is not a primary/partition key
const params = {
TableName: process.env.DYNAMODB_NOTIFICATION_TABLE_NAME || 'TABLE_FAILURE',
IndexName: 'userId-alertTime-index',
KeyConditionExpression: 'userId = :userId',
ExpressionAttributeValues: {
':userId': userId,
},
ScanIndexForward: false // sort in descending order
};


try {
const data = await dynamodb.get(params).promise();
const data = await dynamodb.query(params).promise();


if (!data.Item) {
throw new Error('No notification with user id ' + userId + ' found.');
if (!data.Items) {
throw new Error('No notifications with user id ' + userId + ' found.');
}


return data.Item as Notification;
return data.Items as Notification[];
} catch (error) {
console.log(error)
throw new Error('Failed to retrieve notification.');
throw new Error('Failed to retrieve notifications.');
}
}


// function that returns array of notifications by notification id
async getNotificationByNotificationId(notificationId: string): Promise<Notification[]> {

console.log("NOTIF ID", notificationId)

// key condition expression specifies the query condition
// expression attribute values specifies the actual value of the key
const params = {
TableName: process.env.DYNAMODB_NOTIFICATION_TABLE_NAME || 'TABLE_FAILURE',
KeyConditionExpression: 'notificationId = :notificationId',
ExpressionAttributeValues: {
':notificationId': notificationId,
},
};


try {
const data = await dynamodb.query(params).promise();


if (!data.Items) {
throw new Error('No notifications with notification id ' + notificationId + ' found.');
}


return data.Items as Notification[];
} catch (error) {
console.log(error)
throw new Error('Failed to retrieve notification.');
}
}

}
15 changes: 11 additions & 4 deletions backend/src/notifications/notification.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// src/notifications/notifications.controller.ts
import { Controller, Post, Body, Get, Query } from '@nestjs/common';
import { Controller, Post, Body, Get, Query, Param } from '@nestjs/common';
import { NotificationService } from './notifcation.service';
import { Notification } from './notification.model';

Expand All @@ -11,15 +11,22 @@ export class NotificationController {
constructor(private readonly notificationService: NotificationService) { }


// allows to create a new notification
@Post()
async create(@Body() notification: Partial<Notification>): Promise<Notification> {
// Call the service's createNotification method and return the result
// call the service's createNotification method and return the result
return await this.notificationService.createNotification(notification as Notification);
}

// gets notifications based on the noticationId
@Get(':notificationId')
async findByNotification(@Param('notificationId') notificationId: string) {
return await this.notificationService.getNotificationByNotificationId(notificationId);
}

@Get(':userId')
async findByUser(@Query('userId') userId: string) {
// gets notifications by user id (sorted by most recent notifications first)
@Get('/user/:userId')
async findByUser(@Param('userId') userId: string) {
return await this.notificationService.getNotificationByUserId(userId);
}

Expand Down
4 changes: 4 additions & 0 deletions backend/src/user/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Injectable } from '@nestjs/common';
import AWS from 'aws-sdk';

AWS.config.update({ region: 'us-east-2' }); // need to explicitly mention the region here otherwise an error is thrown for some reason

const dynamodb = new AWS.DynamoDB.DocumentClient();

@Injectable()
Expand All @@ -14,6 +16,7 @@ export class UserService {
const data = await dynamodb.scan(params).promise();
return data.Items;
} catch (error) {
console.log(error)
throw new Error('Could not retrieve users.');
}
}
Expand All @@ -30,6 +33,7 @@ export class UserService {
const data = await dynamodb.get(params).promise();
return data.Item;
} catch (error) {
console.log(error)
throw new Error('Could not retrieve user.');
}
}
Expand Down
78 changes: 68 additions & 10 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"preview": "vite preview"
},
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.7.1",
"@fortawesome/free-solid-svg-icons": "^6.7.1",
"@fortawesome/react-fontawesome": "^0.2.2",
"@types/react-router-dom": "^5.3.3",
"core-js": "^3.38.1",
"mobx": "^6.13.2",
Expand All @@ -21,8 +24,8 @@
},
"devDependencies": {
"@eslint/js": "^9.9.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/react": "^18.3.13",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.1",
"eslint": "^9.9.0",
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
Expand Down
16 changes: 9 additions & 7 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
// src/App.tsx

import { BrowserRouter as Router, Route, Routes, Navigate } from 'react-router-dom';
import { BrowserRouter as Router, Route} from 'react-router-dom';
import { Navigate } from '../node_modules/react-router-dom/dist/index.js';
import { Routes } from '../node_modules/react-router-dom/dist/index.js';
import { observer } from 'mobx-react-lite';
import Login from './Login';
import Register from './Register';
import Dashboard from './Dashboard';
import Login from './Login.js';
import Register from './Register.js';
import Dashboard from './Dashboard.js';
import './App.css';

// Register store and mutators
import './external/bcanSatchel/mutators';
import { getStore } from './external/bcanSatchel/store';
import GrantPage from "./grant-info/components/GrantPage.tsx";
import { getStore } from './external/bcanSatchel/store.js';
import GrantPage from "./grant-info/components/GrantPage.js";

const App = observer(() => {
const store = getStore();

return (
<Router>
< div className="app-container">
<div className="app-container">
<Routes>
<Route
path="/login"
Expand Down
Loading
Loading