Notification system#81
Open
snebo wants to merge 13 commits into
Open
Conversation
fixed typo's and bugs in the notification schema fixed bugs in notifications service that returned incorrect data format
…er and user service from passing any test aside from some outaded refrences like #register in the controller test file which does not exist on the actual controller file, 'photo' was also removed from user schema. It has been readded since it caused a test to fail. this took way longer than expected and came as a shock becuase the tests worked just fine the issue was caused because of the use of 'Inject' rather than the mongoose 'InjectModel' which returns a sting and not the mongoose model itself. which made the dependency undetectable in the test files espicially when 'getModelToken' is used.
added unit tests for event endpoints and ensured presense of proper mock models
modified the events service and controller approve endpoint to accept admin id added more tests for approval event service
… tests, and injectmodel to work in test, but fail in dev since we use inject -for document- we need to pass the name which is the name in our custom shcema compiler 'dbmodule' (the name for example now being User.name) directly, rather than usin getModel() since we are not using the convetional model system
…ed issues with lead application guard not allowing users register to be leadd. the userguard was removed from this endpoint, since it first checks the request is from a lead or an admin
snebo
marked this pull request as ready for review
August 28, 2025 12:14
snebo
requested review from
Tonykaynoni,
definite-d,
oyedeletemitope and
willypelz
August 28, 2025 12:14
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a notifications subsystem (with audit trail) and wires it into lead-application and event-approval flows so admins/users can be notified and resolutions can be tracked.
Changes:
- Introduces
NotificationsModulewith controller/service plusNotificationInfo+NotificationAuditInfoschemas. - Integrates notification creation/resolution into Users (lead applications + verification requests) and Events (create/approve/reject).
- Updates interfaces/DTOs/guards and adjusts unit tests to account for the new dependencies and flows.
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 21 comments.
Show a summary per file
| File | Description |
|---|---|
| src/app.module.ts | Registers NotificationsModule at the app level. |
| src/notifications/notifications.module.ts | Declares notifications module wiring (DB + controller/service). |
| src/notifications/notifications.controller.ts | Adds endpoints for listing, reading, clearing, and admin dashboard notifications. |
| src/notifications/notifications.controller.spec.ts | Adds controller tests with a mocked notifications service. |
| src/notifications/notifications.service.ts | Implements notification CRUD, admin dashboard queries, and audit logging on resolution. |
| src/notifications/notifications.service.spec.ts | Adds unit tests for notification service behaviors. |
| src/shared/schema/notifications.schema.ts | Adds Mongo schema for notification records. |
| src/shared/schema/notificationAudit.schema.ts | Adds Mongo schema for notification resolution audit trail. |
| src/shared/schema/index.ts | Registers the new notification/audit schemas with DB providers. |
| src/shared/interfaces/notification.type.ts | Introduces NotificationType enum for leads/events notifications. |
| src/shared/interfaces/index.ts | Exports the new notification interface types. |
| src/shared/interfaces/event.type.ts | Adds REJECTED event status to support event rejection flow. |
| src/shared/dtos/notificatoin.dto.ts | Adds DTO for creating notifications (used by service). |
| src/shared/schema/user.schema.ts | Adds missing photo property to User schema. |
| src/shared/auth/guards/jwt.users.guard.ts | Updates user-role validation logic and error handling. |
| src/users/users.module.ts | Imports NotificationsModule so UsersService can inject it. |
| src/users/users.controller.ts | Adjusts lead-registration route decorators. |
| src/users/users.admin.controller.ts | Passes admin id through to approval/rejection services. |
| src/users/users.service.ts | Creates admin/user notifications and resolves/audits on lead verification actions. |
| src/users/users.service.spec.ts | Reworks service test setup to mock new dependencies. |
| src/users/users.controller.spec.ts | Updates controller tests for changed method signatures/dependencies. |
| src/events/events.users.module.ts | Imports NotificationsModule so EventService can inject it. |
| src/events/events.users.controller.ts | Import/order adjustments for controllers/guards. |
| src/events/events.users.controller.spec.ts | Adds/updates controller unit tests. |
| src/events/events.users.service.ts | Creates notifications on event creation and resolves/audits on approval/rejection. |
| src/events/events.admin.controller.ts | Adds rejection endpoint + passes admin id into service methods. |
| src/events/events.service.spec.ts | Updates service tests to include notifications interactions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
133
to
136
| // exising user requesting to be a lead | ||
| @ApiBearerAuth() | ||
| @UseGuards(JwtUsersGuard) | ||
| @Post('/lead-registration') | ||
| @UsePipes(new ValidationPipe({ transform: true })) |
Comment on lines
+38
to
+42
| if ( | ||
| !hasRequiredRoles(userRoles, [UserRole.USER]) || | ||
| !hasRequiredRoles(userRoles, [UserRole.ADMIN]) || | ||
| !hasRequiredRoles(userRoles, [UserRole.LEAD]) | ||
| ) { |
Comment on lines
10
to
12
| import { ConfigService } from '@nestjs/config'; | ||
| import { InjectModel } from '@nestjs/mongoose'; | ||
| import { randomBytes } from 'crypto'; |
| await this.notificationsService.createAdminNotificationForNewRequest( | ||
| user._id.toString(), | ||
| NotificationType.Leads, | ||
| `${user_details.firstName || user.email} has applied to be a lead for the position of ${leadPosition}`, |
| leadPosition, | ||
| applicationDate: new Date().toLocaleDateString(), | ||
| applicantEmail: user.email, | ||
| applicantName: user_details.firstName || 'Unknown', |
Comment on lines
+1
to
+4
| export enum NotificationType { | ||
| Leads = 'LEADS_REQUEST', | ||
| events = 'EVENTS_REQUEST', | ||
| } |
Comment on lines
+1
to
3
| import { ConfigService } from '@nestjs/config'; | ||
| import { getModelToken } from '@nestjs/mongoose'; | ||
| import { Test, TestingModule } from '@nestjs/testing'; |
Comment on lines
1
to
15
| import { | ||
| Body, | ||
| Controller, | ||
| Delete, | ||
| Get, | ||
| Inject, | ||
| Param, | ||
| Patch, | ||
| Post, | ||
| Put, | ||
| Query, | ||
| Req, | ||
| Request, | ||
| UseGuards, | ||
| } from '@nestjs/common'; |
Comment on lines
+3
to
+10
| import { | ||
| IsBoolean, | ||
| IsEnum, | ||
| IsNotEmpty, | ||
| IsOptional, | ||
| IsString, | ||
| ValidateIf, | ||
| } from 'class-validator'; |
Comment on lines
1
to
+4
| import { NotFoundException } from '@nestjs/common'; | ||
| import { Types } from 'mongoose'; | ||
| import { getModelToken } from '@nestjs/mongoose'; | ||
| import { Test, TestingModule } from '@nestjs/testing'; | ||
| import mongoose, { Types } from 'mongoose'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add Notification System with Audit Trail for Lead Applications and Events
Summary