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

retry postmark #102

Merged
merged 3 commits into from
Mar 24, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ jobs:
run: yarn install
- name: Test
run: yarn test
env:
POSTMARK_SERVER_KEY: ${{ secrets.POSTMARK_SERVER_KEY }}
build-backend-image:
runs-on: ubuntu-latest
name: Build backend image
Expand Down
1 change: 1 addition & 0 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"passport": "^0.6.0",
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
"postmark": "^4.0.2",
"prisma": "^5.2.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
Expand Down
10 changes: 5 additions & 5 deletions apps/server/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ async function main() {
const employees = [
{
id: '777c1974-3104-4744-ae31-7a9296e7784a',
firstName: 'Helen',
lastName: 'Miao',
email: 'email1@kaiyangzhenggmail.onmicrosoft.com',
firstName: 'Iris',
lastName: 'Zhang',
email: 'zhang.iri@northeastern.edu',
positionId: CHIEF_OF_STAFF_UUID,
},
{
Expand All @@ -243,8 +243,8 @@ async function main() {
},
{
id: 'c6de4017-cb1f-44f1-a707-0f38239e0bca',
firstName: 'Iris',
lastName: 'Zhang',
firstName: 'Helen',
lastName: 'Miao',
email: 'email3@kaiyangzhenggmail.onmicrosoft.com',
positionId: AGG_DIR_UUID,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { NotFoundException } from '@nestjs/common';
import { Prisma } from '@prisma/client';
import { PositionsService } from '../positions/positions.service';
import { LoggerServiceImpl } from '../logger/logger.service';
import { PostmarkService } from '../postmark/postmark.service';

describe('FormInstancesController', () => {
let controller: FormInstancesController;
Expand All @@ -28,6 +29,7 @@ describe('FormInstancesController', () => {
PositionsService,
PrismaService,
LoggerServiceImpl,
PostmarkService,
],
}).compile();

Expand Down
3 changes: 2 additions & 1 deletion apps/server/src/form-instances/form-instances.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { PrismaModule } from '../prisma/prisma.module';
import { FormTemplatesModule } from '../form-templates/form-templates.module';
import { PositionsModule } from '../positions/positions.module';
import { LoggerModule } from '../logger/logger.module';
import { PostmarkService } from '../postmark/postmark.service';

@Module({
controllers: [FormInstancesController],
providers: [FormInstancesService],
providers: [FormInstancesService, PostmarkService],
exports: [FormInstancesService],
imports: [PrismaModule, FormTemplatesModule, PositionsModule, LoggerModule],
})
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/form-instances/form-instances.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Prisma } from '@prisma/client';
import { FormTemplateErrorMessage } from '../form-templates/form-templates.errors';
import { FormInstanceErrorMessage } from './form-instance.errors';
import { PositionsErrorMessage } from '../positions/positions.errors';
import { PostmarkService } from '../postmark/postmark.service';

const formInstance1Id = 'formInstanceId1';
const formInstance2Id = 'formInstanceId2';
Expand Down Expand Up @@ -229,6 +230,7 @@ describe('FormInstancesService', () => {
FormInstancesService,
FormTemplatesService,
PositionsService,
PostmarkService,
{
provide: PrismaService,
useValue: db,
Expand Down
11 changes: 11 additions & 0 deletions apps/server/src/form-instances/form-instances.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import { PositionsErrorMessage } from '../positions/positions.errors';
import { SignatureErrorMessage } from '../signatures/signatures.errors';
import { EmployeeErrorMessage } from '../employees/employees.errors';
import { UserEntity } from '../auth/entities/user.entity';
import { PostmarkService } from '../postmark/postmark.service';

@Injectable()
export class FormInstancesService {
constructor(
private prisma: PrismaService,
private formTemplateService: FormTemplatesService,
private positionService: PositionsService,
private postmarkService: PostmarkService,
) {}

/**
Expand Down Expand Up @@ -273,6 +275,7 @@ export class FormInstancesService {
where: { id: formInstanceId },
include: {
signatures: { include: { signerPosition: true, userSignedBy: true } },
originator: true,
},
});

Expand Down Expand Up @@ -333,6 +336,14 @@ export class FormInstancesService {
});
}

const emailBody: string = `Hi ${formInstance.originator.firstName}, your form ${formInstance.name} has been signed by user: ${employee.firstName} ${employee.lastName}.`;
const emailSubject: string = `${formInstance.name} signed by ${employee.firstName} ${employee.lastName}`;
this.postmarkService.sendEmail(
formInstance.originator.email,
emailSubject,
emailBody,
);

return updatedFormInstance;
}

Expand Down
27 changes: 27 additions & 0 deletions apps/server/src/postmark/postmark.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Injectable } from '@nestjs/common';
import { ServerClient } from 'postmark';

@Injectable()
export class PostmarkService {
client: ServerClient;

constructor() {
this.client = new ServerClient(process.env.POSTMARK_SERVER_KEY || '');
}

async sendEmail(to: string, subject: string, textBody: string) {
try {
this.client.sendEmail({
From: 'jfrederick@mfa.org',
To: to,
Subject: subject,
// TODO FIXME when this is uncommented the text body doesn't show up
// 'HtmlBody': '<strong>Hello < /strong> dear Postmark user.',
TextBody: textBody,
MessageStream: 'outbound',
});
} catch (error) {
console.error('Error sending email through postmark:', error);
}
}
}
21 changes: 21 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5394,6 +5394,15 @@ axios@^1.5.0:
form-data "^4.0.0"
proxy-from-env "^1.1.0"

axios@^1.6.2:
version "1.6.8"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.8.tgz#66d294951f5d988a00e87a0ffb955316a619ea66"
integrity sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==
dependencies:
follow-redirects "^1.15.6"
form-data "^4.0.0"
proxy-from-env "^1.1.0"

axobject-query@^3.1.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-3.2.1.tgz#39c378a6e3b06ca679f29138151e45b2b32da62a"
Expand Down Expand Up @@ -7872,6 +7881,11 @@ follow-redirects@^1.0.0, follow-redirects@^1.15.0:
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==

follow-redirects@^1.15.6:
version "1.15.6"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b"
integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==

for-each@^0.3.3:
version "0.3.3"
resolved "https://registry.yarnpkg.com/for-each/-/for-each-0.3.3.tgz#69b447e88a0a5d32c3e7084f3f1710034b21376e"
Expand Down Expand Up @@ -12072,6 +12086,13 @@ postcss@^8.3.5, postcss@^8.4.21, postcss@^8.4.23, postcss@^8.4.4:
picocolors "^1.0.0"
source-map-js "^1.0.2"

postmark@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/postmark/-/postmark-4.0.2.tgz#0c0410ac427d85f2a43454360cf8d07e0fbda317"
integrity sha512-2zlCv+KVVQ0KoamXZHE7d+gXzLlr8tPE+PxQmtUaIZhbHzZAq4D6yH2b+ykhA8wYCc5ISodcx8U1aNLenXBs9g==
dependencies:
axios "^1.6.2"

preact-render-to-string@^5.1.19:
version "5.2.6"
resolved "https://registry.yarnpkg.com/preact-render-to-string/-/preact-render-to-string-5.2.6.tgz#0ff0c86cd118d30affb825193f18e92bd59d0604"
Expand Down
Loading