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

feat: get email service to send mail #618

Merged
merged 2 commits into from
Nov 13, 2023
Merged
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 .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"Vachel",
"Vallon",
"VALLONS",
"vendia",
"virtuals"
],
"[dotenv]": {
Expand Down
2 changes: 1 addition & 1 deletion common/git-hooks/post-merge
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh

# Check if the merge was successful
if [ "$1" -eq 0 ]; then
Expand Down
1 change: 1 addition & 0 deletions services/email-service/.env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ BASE_URL=
APP_NAME=email-service
ENVIROMENT=local

EMAIL_ADDRESS=
MONGO_DATABASE_URI=
MONGO_DATABASE_USER=
MONGO_DATABASE_PASSWORD=
4 changes: 2 additions & 2 deletions services/email-service/bin/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
import * as cdk from 'aws-cdk-lib';
import { EmailServiceStack } from '../stacks/email-service.stack';
import { MainStack } from '../stacks/main.stack';

const app = new cdk.App();
new EmailServiceStack(app, 'EmailServiceStack');
new MainStack(app, 'EmailServiceMainStack');
16 changes: 11 additions & 5 deletions services/email-service/openapi-spec.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"openapi": "3.0.0",
"paths": {
"/v1/health": {
"/health": {
"get": {
"operationId": "HealthController_check",
"parameters": [],
Expand Down Expand Up @@ -104,7 +104,7 @@
}
}
},
"/v1/email-message/user-account-created": {
"/email-message/user-account-created": {
"post": {
"operationId": "EmailMessageController_convert",
"parameters": [
Expand Down Expand Up @@ -135,7 +135,7 @@
"responses": { "201": { "description": "" } }
}
},
"/v1/email-message/user-forgotten-password-reset": {
"/email-message/user-forgotten-password-reset": {
"post": {
"operationId": "EmailMessageController_convertUserForgottenPasswordReset",
"parameters": [
Expand Down Expand Up @@ -168,7 +168,7 @@
"responses": { "201": { "description": "" } }
}
},
"/v1/email-message/stats": {
"/email-message/stats": {
"get": {
"operationId": "EmailMessageController_stats",
"parameters": [],
Expand All @@ -183,7 +183,13 @@
"contact": {}
},
"tags": [],
"servers": [],
"servers": [
{ "url": "http://localhost:3000", "description": "Local" },
{
"url": "https://nx7uv2rfy4.execute-api.us-east-2.amazonaws.com/default/v1/email-message/",
"description": "Sandbox"
}
],
"components": {
"schemas": {
"UserAccountCreatedDto": {
Expand Down
7 changes: 6 additions & 1 deletion services/email-service/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NestFactory } from '@nestjs/core';
import { ExpressAdapter } from '@nestjs/platform-express';
import serverlessExpress from '@vendia/serverless-express';
import { ValidationPipe } from '@nestjs/common';
import { ValidationPipe, VersioningType } from '@nestjs/common';
import { Context, Handler } from 'aws-lambda';
import express from 'express';

Expand All @@ -17,6 +17,11 @@ async function bootstrap() {
new ExpressAdapter(expressApp),
);
app.enableCors();
app.enableVersioning({
type: VersioningType.HEADER,
header: 'Accept-Version',
defaultVersion: '1',
});
app.useGlobalPipes(
new ValidationPipe({
transform: true,
Expand Down
22 changes: 14 additions & 8 deletions services/email-service/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,34 @@ async function bootstrap() {
const app = await NestFactory.create(AppModule);

app.enableVersioning({
type: VersioningType.URI,
type: VersioningType.HEADER,
header: 'Accept-Version',
defaultVersion: '1',
});

app.useGlobalPipes(
new ValidationPipe({
transform: true,
transformOptions: { enableImplicitConversion: true },
}),
);

const config = new DocumentBuilder()
.setTitle('@cats-cradles/email-service')
.setDescription('An API for the email service')
.setVersion('1.0')
.addServer('http://localhost:3000', 'Local')
.addServer(
'https://nx7uv2rfy4.execute-api.us-east-2.amazonaws.com/default/v1/email-message/',
'Sandbox',
)
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);

// update the openapi-spec
writeFileSync('./openapi-spec.json', JSON.stringify(document));

app.useGlobalPipes(
new ValidationPipe({
transform: true,
transformOptions: { enableImplicitConversion: true },
}),
);

await app.listen(3000);
}
bootstrap();
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ export class EmailMessage {
public data?: string;

@IsEnum(StatusType)
@Prop()
@Prop({
type: String,
enum: Object.values(StatusType),
default: StatusType.OPEN,
}) // Use the enum
public status: StatusType;

@IsDateString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import { Expose } from 'class-transformer';
import { kebabCase } from 'lodash';

export abstract class TemplateDto {
abstract subject: string;

abstract fromAddress: string;

@IsEmail()
@ApiProperty({
description: 'The email recipient',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString } from 'class-validator';
import { IsEmail, IsString } from 'class-validator';
import { Expose } from 'class-transformer';
import { TemplateDto } from './template.dto';

export class UserAccountCreatedDto extends TemplateDto {
readonly subject: 'User Account Created';

readonly fromAddress = '[email protected]';

@IsString()
@ApiProperty({
description: 'The first name of the recipient',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsFQDN } from 'class-validator';
import { IsString, IsFQDN, IsEmail } from 'class-validator';
import { Expose } from 'class-transformer';
import { TemplateDto } from './template.dto';

export class UserForgottenPasswordResetDto extends TemplateDto {
readonly subject: 'Forgotten Password Reset';

readonly fromAddress = '[email protected]';

@IsString()
@ApiProperty({
description: 'The username of the recipient',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import {
Get, Controller, Post, Body, Query,
Get,
Controller,
Post,
Body,
Query,
VERSION_NEUTRAL,
} from '@nestjs/common';
import { ApiBody, ApiQuery } from '@nestjs/swagger';
import { UserAccountCreatedDto, UserForgottenPasswordResetDto } from './dto';
Expand All @@ -11,7 +16,7 @@ import { ActionType } from '../../models/email-message/action.type';
import { EngineService } from './engine.service';
import { QueueService } from './queue.service';

@Controller({ path: 'email-message', version: ['1'] })
@Controller({ path: 'email-message', version: ['1', VERSION_NEUTRAL] })
export class EmailMessageController {
constructor(
private _engineService: EngineService,
Expand All @@ -25,11 +30,16 @@ export class EmailMessageController {
@Body() data: UserAccountCreatedDto,
@Query('action') action: ActionType,
): Promise<any> {
const defaultData = {
subject: 'Forgotten Password Reset',
fromAddress: '[email protected]',
};

return this._engineService.process(
action,
UserAccountCreatedDto.slug,
UserAccountCreatedTemplate,
data,
{ ...data, ...defaultData },
);
}

Expand All @@ -40,11 +50,16 @@ export class EmailMessageController {
@Body() data: UserForgottenPasswordResetDto,
@Query('action') action: ActionType,
): Promise<any> {
const defaultData = {
subject: 'User Account Created',
fromAddress: '[email protected]',
};

return this._engineService.process(
action,
UserForgottenPasswordResetDto.slug,
UserForgottenPasswordResetTemplate,
data,
{ ...data, ...defaultData },
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller, Get } from '@nestjs/common';
import { Controller, Get, VERSION_NEUTRAL } from '@nestjs/common';
import { HealthCheckService, HealthCheck } from '@nestjs/terminus';

@Controller('health')
@Controller({ path: 'health', version: ['1', VERSION_NEUTRAL] })
export class HealthController {
constructor(private health: HealthCheckService) {}

Expand Down
Loading
Loading