Spaces:
Running
Running
Commit ·
0addeca
1
Parent(s): f963af3
feat(contact-us): add contact form submission
Browse filesadd complete contact-us module including controller, validated DTO and service
add SUPPORT_EMAIL to .env.example
register ContactUsModule in root app module
implement form submission that sends team notifications and user confirmation emails
.env.example
CHANGED
|
@@ -20,4 +20,5 @@ SMTP_PORT=587
|
|
| 20 |
SMTP_USER=your-email@gmail.com
|
| 21 |
SMTP_PASS=your-app-password
|
| 22 |
SMTP_FROM=MaternAlert <no-reply@maternalert.com>
|
|
|
|
| 23 |
|
|
|
|
| 20 |
SMTP_USER=your-email@gmail.com
|
| 21 |
SMTP_PASS=your-app-password
|
| 22 |
SMTP_FROM=MaternAlert <no-reply@maternalert.com>
|
| 23 |
+
SUPPORT_EMAIL=support@maternalert.com.ng
|
| 24 |
|
src/app.module.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { EducationModule } from "./education/education.module";
|
|
| 14 |
import { ClinicFinderModule } from "./clinic-finder/clinic-finder.module";
|
| 15 |
import { MonitoringEngineModule } from "./monitoring-engine/monitoring-engine.module";
|
| 16 |
import { EmailModule } from "./email/email.module";
|
|
|
|
| 17 |
import { AppController } from "./app.controller";
|
| 18 |
import { HealthController } from "./health.controller";
|
| 19 |
|
|
@@ -50,6 +51,7 @@ import { HealthController } from "./health.controller";
|
|
| 50 |
ClinicFinderModule,
|
| 51 |
MonitoringEngineModule,
|
| 52 |
EmailModule,
|
|
|
|
| 53 |
],
|
| 54 |
controllers: [AppController, HealthController],
|
| 55 |
providers: [
|
|
|
|
| 14 |
import { ClinicFinderModule } from "./clinic-finder/clinic-finder.module";
|
| 15 |
import { MonitoringEngineModule } from "./monitoring-engine/monitoring-engine.module";
|
| 16 |
import { EmailModule } from "./email/email.module";
|
| 17 |
+
import { ContactUsModule } from "./contact-us/contact-us.module";
|
| 18 |
import { AppController } from "./app.controller";
|
| 19 |
import { HealthController } from "./health.controller";
|
| 20 |
|
|
|
|
| 51 |
ClinicFinderModule,
|
| 52 |
MonitoringEngineModule,
|
| 53 |
EmailModule,
|
| 54 |
+
ContactUsModule,
|
| 55 |
],
|
| 56 |
controllers: [AppController, HealthController],
|
| 57 |
providers: [
|
src/contact-us/contact-us.controller.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Controller, Post, Body, HttpCode, HttpStatus } from "@nestjs/common";
|
| 2 |
+
import { ContactUsService } from "./contact-us.service";
|
| 3 |
+
import { CreateContactUsDto } from "./dto/create-contact-us.dto";
|
| 4 |
+
|
| 5 |
+
@Controller("contact-us")
|
| 6 |
+
export class ContactUsController {
|
| 7 |
+
constructor(private readonly contactUsService: ContactUsService) {}
|
| 8 |
+
|
| 9 |
+
@Post()
|
| 10 |
+
@HttpCode(HttpStatus.OK)
|
| 11 |
+
async submit(@Body() createContactUsDto: CreateContactUsDto) {
|
| 12 |
+
return this.contactUsService.submitContactForm(createContactUsDto);
|
| 13 |
+
}
|
| 14 |
+
}
|
src/contact-us/contact-us.module.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Module } from "@nestjs/common";
|
| 2 |
+
import { ContactUsController } from "./contact-us.controller";
|
| 3 |
+
import { ContactUsService } from "./contact-us.service";
|
| 4 |
+
import { EmailModule } from "../email/email.module";
|
| 5 |
+
|
| 6 |
+
@Module({
|
| 7 |
+
imports: [EmailModule],
|
| 8 |
+
controllers: [ContactUsController],
|
| 9 |
+
providers: [ContactUsService],
|
| 10 |
+
})
|
| 11 |
+
export class ContactUsModule {}
|
src/contact-us/contact-us.service.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Injectable, Logger } from "@nestjs/common";
|
| 2 |
+
import { ConfigService } from "@nestjs/config";
|
| 3 |
+
import { CreateContactUsDto } from "./dto/create-contact-us.dto";
|
| 4 |
+
import { EmailService } from "../email/email.service";
|
| 5 |
+
|
| 6 |
+
@Injectable()
|
| 7 |
+
export class ContactUsService {
|
| 8 |
+
private readonly logger = new Logger(ContactUsService.name);
|
| 9 |
+
|
| 10 |
+
constructor(
|
| 11 |
+
private readonly emailService: EmailService,
|
| 12 |
+
private readonly configService: ConfigService,
|
| 13 |
+
) {}
|
| 14 |
+
|
| 15 |
+
async submitContactForm(createContactUsDto: CreateContactUsDto) {
|
| 16 |
+
this.logger.log(`Contact form submitted by: ${createContactUsDto.email}`);
|
| 17 |
+
|
| 18 |
+
const supportEmail =
|
| 19 |
+
this.configService.get<string>("SUPPORT_EMAIL") ||
|
| 20 |
+
"support@maternalert.com.ng";
|
| 21 |
+
|
| 22 |
+
// Send notification to MaternAlert team
|
| 23 |
+
await this.emailService.sendEmail(
|
| 24 |
+
supportEmail,
|
| 25 |
+
`New Contact Form: ${createContactUsDto.subject}`,
|
| 26 |
+
`
|
| 27 |
+
Name: ${createContactUsDto.name}
|
| 28 |
+
Email: ${createContactUsDto.email}
|
| 29 |
+
Subject: ${createContactUsDto.subject}
|
| 30 |
+
|
| 31 |
+
Message:
|
| 32 |
+
${createContactUsDto.message}
|
| 33 |
+
`,
|
| 34 |
+
);
|
| 35 |
+
|
| 36 |
+
// Send confirmation to the user
|
| 37 |
+
await this.emailService.sendEmail(
|
| 38 |
+
createContactUsDto.email,
|
| 39 |
+
"Thank you for contacting MaternAlert",
|
| 40 |
+
`
|
| 41 |
+
Hello ${createContactUsDto.name},
|
| 42 |
+
|
| 43 |
+
Thank you for reaching out to MaternAlert. We have received your message and will respond as soon as possible.
|
| 44 |
+
|
| 45 |
+
Best regards,
|
| 46 |
+
The MaternAlert Team
|
| 47 |
+
`,
|
| 48 |
+
);
|
| 49 |
+
|
| 50 |
+
return { message: "Contact form submitted successfully" };
|
| 51 |
+
}
|
| 52 |
+
}
|
src/contact-us/dto/create-contact-us.dto.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { IsEmail, IsNotEmpty, IsString, MaxLength } from "class-validator";
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Create Contact Us DTO
|
| 5 |
+
*
|
| 6 |
+
* VALIDATION RULES:
|
| 7 |
+
* - Name: max 100 characters
|
| 8 |
+
* - Email: valid email format
|
| 9 |
+
* - Subject: max 200 characters
|
| 10 |
+
* - Message: max 2000 characters
|
| 11 |
+
*
|
| 12 |
+
* CLINICAL SAFETY:
|
| 13 |
+
* - No medical data collected
|
| 14 |
+
* - No diagnostic information
|
| 15 |
+
* - Plain text communication only
|
| 16 |
+
*/
|
| 17 |
+
export class CreateContactUsDto {
|
| 18 |
+
@IsString()
|
| 19 |
+
@IsNotEmpty()
|
| 20 |
+
@MaxLength(100)
|
| 21 |
+
name!: string;
|
| 22 |
+
|
| 23 |
+
@IsEmail()
|
| 24 |
+
@IsNotEmpty()
|
| 25 |
+
email!: string;
|
| 26 |
+
|
| 27 |
+
@IsString()
|
| 28 |
+
@IsNotEmpty()
|
| 29 |
+
@MaxLength(200)
|
| 30 |
+
subject!: string;
|
| 31 |
+
|
| 32 |
+
@IsString()
|
| 33 |
+
@IsNotEmpty()
|
| 34 |
+
@MaxLength(2000)
|
| 35 |
+
message!: string;
|
| 36 |
+
}
|