Skip to content

Commit

Permalink
small improvements (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
tima101 committed May 27, 2021
1 parent 880cc17 commit 8c37079
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 60 deletions.
28 changes: 18 additions & 10 deletions book/10-begin/api/server/models/Invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ class InvitationClass extends mongoose.Model {
throw new Error('Team does not exist or you have no permission');
}

const registeredUser = await User.findOne({ email }).select('defaultTeamSlug').setOptions({ lean: true });
const registeredUser = await User.findOne({ email })
.select('defaultTeamSlug')
.setOptions({ lean: true });

if (registeredUser) {
if (team.memberIds.includes(registeredUser._id.toString())) {
Expand All @@ -90,7 +92,9 @@ class InvitationClass extends mongoose.Model {
}

let token;
const invitation = await this.findOne({ teamId, email }).select('token').setOptions({ lean: true });
const invitation = await this.findOne({ teamId, email })
.select('token')
.setOptions({ lean: true });

if (invitation) {
token = invitation.token;
Expand All @@ -116,20 +120,24 @@ class InvitationClass extends mongoose.Model {
throw new Error('Invitation email template not found');
}

await sendEmail({
from: `Kelly from saas-app.async-await.com <${process.env.EMAIL_SUPPORT_FROM_ADDRESS}>`,
to: [email],
subject: emailTemplate.subject,
body: emailTemplate.message,
}).catch((err) => {
try {
await sendEmail({
from: `Kelly from saas-app.async-await.com <${process.env.EMAIL_SUPPORT_FROM_ADDRESS}>`,
to: [email],
subject: emailTemplate.subject,
body: emailTemplate.message,
});
} catch (err) {
console.log('Email sending error:', err);
});
}

return await this.findOne({ teamId, email }).setOptions({ lean: true });
}

public static async getTeamInvitations({ userId, teamId }) {
const team = await Team.findOne({ _id: teamId }).select('teamLeaderId').setOptions({ lean: true });
const team = await Team.findOne({ _id: teamId })
.select('teamLeaderId')
.setOptions({ lean: true });

if (userId !== team.teamLeaderId) {
throw new Error('You have no permission.');
Expand Down
16 changes: 9 additions & 7 deletions book/10-end/api/server/models/Invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,16 @@ class InvitationClass extends mongoose.Model {
throw new Error('Invitation email template not found');
}

await sendEmail({
from: `Kelly from saas-app.async-await.com <${process.env.EMAIL_SUPPORT_FROM_ADDRESS}>`,
to: [email],
subject: emailTemplate.subject,
body: emailTemplate.message,
}).catch((err) => {
try {
await sendEmail({
from: `Kelly from saas-app.async-await.com <${process.env.EMAIL_SUPPORT_FROM_ADDRESS}>`,
to: [email],
subject: emailTemplate.subject,
body: emailTemplate.message,
});
} catch (err) {
console.log('Email sending error:', err);
});
}

return await this.findOne({ teamId, email }).setOptions({ lean: true });
}
Expand Down
16 changes: 9 additions & 7 deletions book/7-end/api/server/models/Invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,16 @@ class InvitationClass extends mongoose.Model {
throw new Error('Invitation email template not found');
}

await sendEmail({
from: `Kelly from saas-app.async-await.com <${process.env.EMAIL_SUPPORT_FROM_ADDRESS}>`,
to: [email],
subject: emailTemplate.subject,
body: emailTemplate.message,
}).catch((err) => {
try {
await sendEmail({
from: `Kelly from saas-app.async-await.com <${process.env.EMAIL_SUPPORT_FROM_ADDRESS}>`,
to: [email],
subject: emailTemplate.subject,
body: emailTemplate.message,
});
} catch (err) {
console.log('Email sending error:', err);
});
}

return await this.findOne({ teamId, email }).setOptions({ lean: true });
}
Expand Down
16 changes: 9 additions & 7 deletions book/8-begin/api/server/models/Invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,16 @@ class InvitationClass extends mongoose.Model {
throw new Error('Invitation email template not found');
}

await sendEmail({
from: `Kelly from saas-app.async-await.com <${process.env.EMAIL_SUPPORT_FROM_ADDRESS}>`,
to: [email],
subject: emailTemplate.subject,
body: emailTemplate.message,
}).catch((err) => {
try {
await sendEmail({
from: `Kelly from saas-app.async-await.com <${process.env.EMAIL_SUPPORT_FROM_ADDRESS}>`,
to: [email],
subject: emailTemplate.subject,
body: emailTemplate.message,
});
} catch (err) {
console.log('Email sending error:', err);
});
}

return await this.findOne({ teamId, email }).setOptions({ lean: true });
}
Expand Down
16 changes: 9 additions & 7 deletions book/8-end/api/server/models/Invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,16 @@ class InvitationClass extends mongoose.Model {
throw new Error('Invitation email template not found');
}

await sendEmail({
from: `Kelly from saas-app.async-await.com <${process.env.EMAIL_SUPPORT_FROM_ADDRESS}>`,
to: [email],
subject: emailTemplate.subject,
body: emailTemplate.message,
}).catch((err) => {
try {
await sendEmail({
from: `Kelly from saas-app.async-await.com <${process.env.EMAIL_SUPPORT_FROM_ADDRESS}>`,
to: [email],
subject: emailTemplate.subject,
body: emailTemplate.message,
});
} catch (err) {
console.log('Email sending error:', err);
});
}

return await this.findOne({ teamId, email }).setOptions({ lean: true });
}
Expand Down
16 changes: 9 additions & 7 deletions book/9-begin/api/server/models/Invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,16 @@ class InvitationClass extends mongoose.Model {
throw new Error('Invitation email template not found');
}

await sendEmail({
from: `Kelly from saas-app.async-await.com <${process.env.EMAIL_SUPPORT_FROM_ADDRESS}>`,
to: [email],
subject: emailTemplate.subject,
body: emailTemplate.message,
}).catch((err) => {
try {
await sendEmail({
from: `Kelly from saas-app.async-await.com <${process.env.EMAIL_SUPPORT_FROM_ADDRESS}>`,
to: [email],
subject: emailTemplate.subject,
body: emailTemplate.message,
});
} catch (err) {
console.log('Email sending error:', err);
});
}

return await this.findOne({ teamId, email }).setOptions({ lean: true });
}
Expand Down
16 changes: 9 additions & 7 deletions book/9-end/api/server/models/Invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,16 @@ class InvitationClass extends mongoose.Model {
throw new Error('Invitation email template not found');
}

await sendEmail({
from: `Kelly from saas-app.async-await.com <${process.env.EMAIL_SUPPORT_FROM_ADDRESS}>`,
to: [email],
subject: emailTemplate.subject,
body: emailTemplate.message,
}).catch((err) => {
try {
await sendEmail({
from: `Kelly from saas-app.async-await.com <${process.env.EMAIL_SUPPORT_FROM_ADDRESS}>`,
to: [email],
subject: emailTemplate.subject,
body: emailTemplate.message,
});
} catch (err) {
console.log('Email sending error:', err);
});
}

return await this.findOne({ teamId, email }).setOptions({ lean: true });
}
Expand Down
16 changes: 9 additions & 7 deletions saas/api/server/models/Invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,16 @@ class InvitationClass extends mongoose.Model {
throw new Error('Invitation email template not found');
}

await sendEmail({
from: `Kelly from saas-app.async-await.com <${process.env.EMAIL_SUPPORT_FROM_ADDRESS}>`,
to: [email],
subject: emailTemplate.subject,
body: emailTemplate.message,
}).catch((err) => {
try {
await sendEmail({
from: `Kelly from saas-app.async-await.com <${process.env.EMAIL_SUPPORT_FROM_ADDRESS}>`,
to: [email],
subject: emailTemplate.subject,
body: emailTemplate.message,
});
} catch (err) {
console.log('Email sending error:', err);
});
}

return await this.findOne({ teamId, email }).setOptions({ lean: true });
}
Expand Down
6 changes: 5 additions & 1 deletion saas/app/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ class MyApp extends App {
/>
<link
rel="stylesheet"
href="https://d2c24pn6pcl4ug.cloudfront.net/css/nprogress.min.css"
href={
isThemeDark
? 'https://storage.googleapis.com/async-await/nprogress-light.min.css?v=1'
: 'https://storage.googleapis.com/async-await/nprogress-dark.min.css?v=1'
}
/>
</Head>
<CssBaseline />
Expand Down

0 comments on commit 8c37079

Please sign in to comment.