Skip to content

Commit

Permalink
feat: button to send emails to self in admin dashboard (so I can test…
Browse files Browse the repository at this point in the history
… things)
  • Loading branch information
Sampiiiii committed May 6, 2024
1 parent 2fc2cc6 commit 5cd012b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 18 deletions.
3 changes: 1 addition & 2 deletions apps/anvil/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TrainingService } from "@/training/training.service";
import { BullModule } from "@nestjs/bull";
import { Logger, MiddlewareConsumer, Module, NestModule, RequestMethod } from "@nestjs/common";
import { ConfigModule } from "@nestjs/config";
import { APP_INTERCEPTOR, APP_PIPE } from "@nestjs/core";
import { APP_PIPE } from "@nestjs/core";
import { ScheduleModule } from "@nestjs/schedule";
import { ThrottlerModule } from "@nestjs/throttler";
import { ZodValidationPipe } from "nestjs-zod";
Expand All @@ -26,7 +26,6 @@ import { UsersModule } from "./users/users.module";
import * as process from "node:process";
import { CsrfMiddleware } from "@/auth/authentication/middleware/csrf.middleware";
import { IdempotencyMiddleware } from "@/shared/middleware/idempotency.middleware";
import { IdempotencyCacheInterceptor } from "@/shared/interceptors/idempotency-cache.interceptor";

@Module({
imports: [
Expand Down
33 changes: 30 additions & 3 deletions apps/anvil/src/root/root.controller.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
import { IsAdmin, IsRep } from "@/auth/authorization/decorators/check-roles-decorator";
import { CaslAbilityGuard } from "@/auth/authorization/guards/casl-ability.guard";
import { EdgeDBService } from "@/edgedb/edgedb.service";
import { GoogleService } from "@/google/google.service";
import { User as GetUser } from "@/shared/decorators/user.decorator";
import { SignInService } from "@/sign-in/sign-in.service";
import type { User } from "@ignis/types/users";
import { Body, Controller, Delete, Get, Param, Patch, Post, Query, Res, UseGuards } from "@nestjs/common";
import {
Body,
Controller,
Delete,
Get,
Param,
Patch,
Post,
Query,
Res,
UseGuards,
UseInterceptors,
} from "@nestjs/common";
import { AuthGuard } from "@nestjs/passport";
import { Response } from "express";
import { CreateAgreementDto, UpdateAgreementDto } from "./dto/agreement.dto";
import { CreateSignInReasonCategoryDto } from "./dto/reason.dto";
import { RootService } from "./root.service";
import { Logger } from "@nestjs/common";
import { EmailService } from "@/email/email.service";
import { IdempotencyCacheInterceptor } from "@/shared/interceptors/idempotency-cache.interceptor";
import { IdempotencyCache } from "@/shared/decorators/idempotency.decorator";

@Controller()
@UseInterceptors(IdempotencyCacheInterceptor)
export class RootController {
constructor(
private readonly signInService: SignInService,
private readonly dbService: EdgeDBService,
private readonly emailService: EmailService,
private readonly rootService: RootService,
private readonly googleService: GoogleService,
private readonly logger: Logger,
Expand Down Expand Up @@ -45,6 +60,7 @@ export class RootController {
}

@Post("sign-in-reasons")
@IdempotencyCache(60)
@UseGuards(AuthGuard("jwt"), CaslAbilityGuard)
async addSignInReason(@Body() reason: CreateSignInReasonCategoryDto) {
this.logger.log("Adding sign-in reason", RootController.name);
Expand All @@ -68,6 +84,7 @@ export class RootController {
@Post("agreements")
@IsAdmin()
@UseGuards(AuthGuard("jwt"), CaslAbilityGuard)
@IdempotencyCache(60)
async createAgreement(@Body() body: CreateAgreementDto) {
this.logger.log("Creating agreement", RootController.name);
return await this.rootService.createAgreement(body.reason_ids, body.content);
Expand All @@ -81,6 +98,7 @@ export class RootController {
}

@Post("agreements/:agreement_id")
@IdempotencyCache(60)
@UseGuards(AuthGuard("jwt"), CaslAbilityGuard)
async signAgreement(@Param("agreement_id") agreement_id: string, @GetUser() user: User) {
this.logger.log(`Signing agreement with ID: ${agreement_id} by user with ID: ${user.id}`, RootController.name);
Expand All @@ -95,6 +113,15 @@ export class RootController {
return await this.rootService.updateAgreement(agreement_id, body.reason_ids, body.content);
}

@Post("test_email")
@IsAdmin()
@IdempotencyCache(60)
@UseGuards(AuthGuard("jwt"), CaslAbilityGuard)
async testEmail(@GetUser() user: User) {
this.logger.log(`Sending email to ${user.email}`, RootController.name);
return await this.emailService.sendWelcomeEmail(user);
}

@Get("teams")
@IsRep()
@UseGuards(AuthGuard("jwt"), CaslAbilityGuard)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
import { createFileRoute } from "@tanstack/react-router";
import Title from "@/components/title";
import { Button } from "@ui/components/ui/button.tsx";
import axiosInstance from "@/api/axiosInstance.ts";

const EmailIndexPage = () => {
const handleSendEmail = async () => {
try {
await axiosInstance.post("/test_email"); // Make the POST request to the endpoint
console.log("Email sent successfully");
} catch (error) {
console.error("Error sending email:", error);
}
};

return (
<div className="container mx-auto p-4">
<Title prompt="Emails" />
<div className="p-6 bg-card rounded-lg">
<h3 className="text-2xl font-bold mb-4">Test Email Sending</h3>
<Button onClick={handleSendEmail}>Send Email to Self</Button>
</div>
</div>
);
};

export const Route = createFileRoute("/_authenticated/admin/notifications/email/")({
component: () => <div>Hello /_authenticated/admin/notifications/email/!</div>,
component: EmailIndexPage,
});
12 changes: 0 additions & 12 deletions apps/forge/src/routes/_authenticated/user/profile/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
import Title from "@/components/title";
import { createFileRoute } from "@tanstack/react-router";
import { RouteUnfinished } from "@/components/routing/RouteUnfinished.tsx";

const UserProfilePageComponent = () => {
return (
<>
<Title prompt="Profile" />
<div className="p-2">
<h3>USER Profile PAGE</h3>
</div>
</>
);
};

export const Route = createFileRoute("/_authenticated/user/profile/")({
component: RouteUnfinished,
});

0 comments on commit 5cd012b

Please sign in to comment.