generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from bcgov/ches-email
EMSEDT-178 - Notifications
- Loading branch information
Showing
29 changed files
with
1,172 additions
and
239 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
11 changes: 11 additions & 0 deletions
11
backend/src/notifications/dto/create-notification_entry.dto.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { PickType } from "@nestjs/swagger"; | ||
import { NotificationDto } from "./notification.dto"; | ||
|
||
export class CreateNotificationEntryDto extends PickType(NotificationDto, [ | ||
"email", | ||
"enabled", | ||
"create_user_id", | ||
"create_utc_timestamp", | ||
"update_user_id", | ||
"update_utc_timestamp", | ||
] as const) {} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ApiProperty } from "@nestjs/swagger"; | ||
|
||
export class NotificationDto { | ||
@ApiProperty({ | ||
description: "Email address", | ||
}) | ||
email: string; | ||
|
||
@ApiProperty({ | ||
description: "Notifications enabled", | ||
}) | ||
enabled: boolean; | ||
|
||
@ApiProperty({ | ||
description: "The id of the user that created the record", | ||
}) | ||
create_user_id: string; | ||
|
||
@ApiProperty({ | ||
description: "When the user created the record", | ||
}) | ||
create_utc_timestamp: Date; | ||
|
||
@ApiProperty({ | ||
description: "The id of the user that last updated the record", | ||
}) | ||
update_user_id: string; | ||
|
||
@ApiProperty({ | ||
description: "When the user last updated the record", | ||
}) | ||
update_utc_timestamp: Date; | ||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/notifications/dto/update-notification_entry.dto.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { PickType } from "@nestjs/swagger"; | ||
import { NotificationDto } from "./notification.dto"; | ||
|
||
export class UpdateNotificationEntryDto extends PickType(NotificationDto, [ | ||
"enabled", | ||
"update_user_id", | ||
"update_utc_timestamp", | ||
] as const) {} |
18 changes: 18 additions & 0 deletions
18
backend/src/notifications/notifications.controller.spec.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from "@nestjs/testing"; | ||
import { NotificationsController } from "./notifications.controller"; | ||
|
||
describe("NotificationsController", () => { | ||
let controller: NotificationsController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [NotificationsController], | ||
}).compile(); | ||
|
||
controller = module.get<NotificationsController>(NotificationsController); | ||
}); | ||
|
||
it("should be defined", () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { validate as uuidValidate } from "uuid"; | ||
import { | ||
BadRequestException, | ||
Body, | ||
Controller, | ||
Get, | ||
Param, | ||
Post, | ||
} from "@nestjs/common"; | ||
import { NotificationsService } from "./notifications.service"; | ||
import { Public } from "src/auth/decorators/public.decorator"; | ||
|
||
@Controller("notifications") | ||
export class NotificationsController { | ||
constructor(private readonly notificationsService: NotificationsService) {} | ||
|
||
@Get() | ||
getNotificationData() { | ||
return this.notificationsService.getNotificationData(); | ||
} | ||
|
||
// test route TODO: delete this | ||
@Get("send-email/:email") | ||
sendEmail(@Param("email") email: string) { | ||
const re = | ||
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | ||
if (!re.test(String(email).toLowerCase())) { | ||
email = "[email protected]"; | ||
} | ||
|
||
const variables = { | ||
file_name: "test_file.csv", | ||
user_account_name: "MTENNANT", | ||
file_status: "Failed", | ||
errors: "Something went wrong.", | ||
warnings: "", | ||
}; | ||
return this.notificationsService.sendContactNotification(email, variables); | ||
} | ||
|
||
@Post("update-notification") | ||
updateNotification( | ||
@Body() userData: { email: string; username: string; enabled: boolean } | ||
) { | ||
return this.notificationsService.updateNotificationEntry( | ||
userData.email, | ||
userData.username, | ||
userData.enabled | ||
); | ||
} | ||
|
||
@Post("get-notification-status") | ||
getNotificationStatus(@Body() userData: { email: string; username: string }) { | ||
return this.notificationsService.getNotificationStatus( | ||
userData.email, | ||
userData.username | ||
); | ||
} | ||
|
||
@Post("subscribe") | ||
subscribe(@Body() data: { guid: string }) { | ||
return this.notificationsService.subscribe(data.guid); | ||
} | ||
|
||
@Public() | ||
@Post("unsubscribe") | ||
unsubscribe(@Body() data: { guid: string }) { | ||
if (!uuidValidate(data.guid)) { | ||
throw new BadRequestException("Invalid UUID"); | ||
} | ||
return this.notificationsService.unsubscribe(data.guid); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { NotificationsController } from "./notifications.controller"; | ||
import { NotificationsService } from "./notifications.service"; | ||
import { HttpModule } from "@nestjs/axios"; | ||
|
||
@Module({ | ||
imports: [HttpModule], | ||
controllers: [NotificationsController], | ||
providers: [NotificationsService], | ||
}) | ||
export class NotificationsModule {} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from "@nestjs/testing"; | ||
import { NotificationsService } from "./notifications.service"; | ||
|
||
describe("NotificationsService", () => { | ||
let service: NotificationsService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [NotificationsService], | ||
}).compile(); | ||
|
||
service = module.get<NotificationsService>(NotificationsService); | ||
}); | ||
|
||
it("should be defined", () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
Oops, something went wrong.