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

[recnet-api] Fix: change from field of email #372

Merged
merged 2 commits into from
Dec 9, 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: 1 addition & 1 deletion apps/recnet-api/src/modules/email/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class EmailService {

// send email
const mailOptions = {
from: this.nodemailerConfig.user,
from: `RecNet<${this.nodemailerConfig.user}>`,
to: user.email,
subject: WeeklyDigestSubject(cutoff, this.appConfig.nodeEnv),
html: render(
Expand Down
86 changes: 61 additions & 25 deletions apps/recnet-api/src/modules/subscription/subscription.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,48 @@ import { announcementSchema, recSchema } from "@recnet/recnet-api-model";

import { WeeklyDigestContent } from "./subscription.type";

import { EmailService } from "../email/email.service";
import { SlackService } from "../slack/slack.service";

function getMockWeeklyDigestData(): WeeklyDigestContent {
const getMockRec = (title = 1) =>
generateMock(recSchema, {
stringMap: {
photoUrl: () => "https://avatar.iran.liara.run/public",
title: () => `Paper Title ${title}`,
},
});
const announcement = generateMock(announcementSchema, {
stringMap: {
content: () => "This is a test announcement!",
},
});
return {
recs: [getMockRec(), getMockRec(2), getMockRec(3), getMockRec()],
numUnusedInviteCodes: 3,
latestAnnouncement: {
...announcement,
startAt: new Date(announcement.startAt),
endAt: new Date(announcement.endAt),
},
};
}

@ApiTags("subscriptions")
@Controller("subscriptions")
export class SubscriptionController {
constructor(
@Inject(AppConfig.KEY)
private readonly appConfig: ConfigType<typeof AppConfig>,
private readonly slackService: SlackService,
private readonly emailService: EmailService,
private readonly userRepository: UserRepository
) {}

/* Development only */
@ApiOperation({
summary: "[Dev only] Send weekly digest slack to the designated user.",
summary:
"[Dev only] Send slack weekly digest slack to the designated user.",
description: "This endpoint is for development only.",
})
@ApiCreatedResponse()
Expand All @@ -46,7 +73,7 @@ export class SubscriptionController {
},
})
@Post("slack/test")
public async testSendingWeeklyDigest(
public async testSendingSlackWeeklyDigest(
@Body("userId") userId: string
): Promise<void> {
if (this.appConfig.nodeEnv === "production") {
Expand All @@ -57,34 +84,43 @@ export class SubscriptionController {
);
}

function getMockWeeklyDigestData(): WeeklyDigestContent {
const getMockRec = (title = 1) =>
generateMock(recSchema, {
stringMap: {
photoUrl: () => "https://avatar.iran.liara.run/public",
title: () => `Paper Title ${title}`,
},
});
const announcement = generateMock(announcementSchema, {
stringMap: {
content: () => "This is a test announcement!",
},
});
return {
recs: [getMockRec(), getMockRec(2), getMockRec(3), getMockRec()],
numUnusedInviteCodes: 3,
latestAnnouncement: {
...announcement,
startAt: new Date(announcement.startAt),
endAt: new Date(announcement.endAt),
},
};
const cutoff = getLatestCutOff();
const user = await this.userRepository.findUserById(userId);
const content = getMockWeeklyDigestData();

this.slackService.sendWeeklyDigest(user, content, cutoff);
}

@ApiOperation({
summary:
"[Dev only] Send email weekly digest slack to the designated user.",
description: "This endpoint is for development only.",
})
@ApiCreatedResponse()
@ApiBody({
schema: {
properties: {
userId: { type: "string" },
},
required: ["userId"],
},
})
@Post("email/test")
public async testSendingEmailWeeklyDigest(
@Body("userId") userId: string
): Promise<void> {
if (this.appConfig.nodeEnv === "production") {
throw new RecnetError(
ErrorCode.INTERNAL_SERVER_ERROR,
HttpStatus.INTERNAL_SERVER_ERROR,
"This endpoint is only for development"
);
}

const cutoff = getLatestCutOff();
const user = await this.userRepository.findUserById(userId);
const content = getMockWeeklyDigestData();

this.slackService.sendWeeklyDigest(user, content, cutoff);
this.emailService.sendWeeklyDigest(user, content, cutoff);
}
}
Loading