-
Notifications
You must be signed in to change notification settings - Fork 104
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: add inquiries page to admin UI #242
feat: add inquiries page to admin UI #242
Conversation
5b5cb7b
to
42dfb42
Compare
const inquiry = await Inquiries.findById(ctx.params.id); | ||
if (!inquiry) throw Boom.notFound(ctx.translateError('INVALID_INQUIRY')); | ||
|
||
await Inquiries.deleteOne({ _id: inquiry.id }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await Inquiries.deleteOne({ id: inquiry.id });
Or
await Inquiries.findByIdAndRemove(inquiry._id);
|
||
async function reply(ctx) { | ||
const inquiry = await Inquiries.findById(ctx.params.id); | ||
if (!inquiry) throw Boom.notFound(ctx.translateError('INVALID_INQUIRY')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
INVALID_INQUIRY
is not defined in config/phrases.js
yet
{ | ||
$set: { is_resolved: true } | ||
} | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should instead be:
await Inquiries.findByIdAndUpdate(inquiry._id, {
$set: { is_resolved: true }
});
// in bulk to a previous message then let's skip the email | ||
if (!repliedTo.has(user)) { | ||
// eslint-disable-next-line no-await-in-loop | ||
await email({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having the await
here in the loop would be extra slow if you're doing a lot of inquiries to reply to in production. We could optimize this probably by doing await Emails.create
in the future. It's OK for now.
} | ||
|
||
// eslint-disable-next-line no-await-in-loop | ||
await Inquiries.findOneAndUpdate( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another case where you can use findByIdAndUpdate
to keep code a bit cleaner
@@ -43,7 +43,7 @@ async function help(ctx) { | |||
|
|||
ctx.logger.debug('created inquiry', { inquiry }); | |||
|
|||
await email({ | |||
const emaild = await email({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually I try not to do stuff like adding a letter at the end because of duplicate variable names. Instead you can rename const email = require('#helpers/email')
to const emailHelper = require('#helpers/email')
at the top of the file. Then you can do const email = await emailHelper({ ...
. I do this approach elsewhere in the codebase.
@@ -56,6 +56,15 @@ async function help(ctx) { | |||
} | |||
}); | |||
|
|||
const { subject } = JSON.parse(emaild.message); | |||
|
|||
await Inquiries.findOneAndUpdate( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same concept with findByIdAndUpdate
to keep code cleaner.
+sortHeader('created_at', 'Created', '#table-inquiries') | ||
th(scope="col") | ||
+sortHeader('updated_at', 'Updated', '#table-inquiries') | ||
if passport && passport.otp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably can remove this if passport && passport.otp
stuff, guessing it was just extra from a copy/paste that can be removed.
maxlength=300, | ||
rows=8 | ||
) | ||
p.form-text.small.text-black.text-themed-50= t("Message has a max of 300 characters.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably remove maxlength
and this p.form-text
line.
textarea#input-message.form-control( | ||
rows="8", | ||
required, | ||
maxlength=config.supportRequestMaxLength, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove maxlength
here
sqlite: 'ttab -G nodemon sqlite.js', | ||
|
||
watch: 'ttab -G gulp watch', | ||
bree: 'nodemon bree.js', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also remove ttab
in package.json
and elsewhere?
❯ rg "ttab"
package.json
352: "ttab": "0.8.0",
README.md
157:You can start any of the services using our pre-built commands to make it easy. Note that all of these pre-built commands are using [nps](https://github.com/sezna/nps) and [ttab](https://github.com/mklement0/ttab) (it will automatically open a new tab in terminal for you!).
-You can start any of the services using our pre-built commands to make it easy. Note that all of these pre-built commands are using [nps](https://github.com/sezna/nps) and [ttab](https://github.com/mklement0/ttab) (it will automatically open a new tab in terminal for you!).
+You can start any of the services using our pre-built commands to make it easy. Note that all of these pre-built commands are using [nps](https://github.com/sezna/nps).
Checklist