Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
🐛 Fix regiter email endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Apr 25, 2019
1 parent 759e14f commit 9ad7747
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export const DB_DATABASE = process.env.DB_DATABASE || "database";

// Email
export const SES_EMAIL = process.env.SES_EMAIL || "";
export const SES_REGION = process.env.SES_REGION || "eu-west-1";
export const SES_ACCESS = process.env.SES_ACCESS || "";
export const SES_SECRET = process.env.SES_SECRET || "";
4 changes: 2 additions & 2 deletions src/crud/user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { query, tableValues, setValues } from "../helpers/mysql";
import { User } from "../interfaces/tables/user";
import { capitalizeFirstAndLastLetter } from "../helpers/string";
import { capitalizeFirstAndLastLetter, dateToDateTime } from "../helpers/utils";
import { hash } from "bcrypt";

export const listAllUsers = async () => {
Expand Down Expand Up @@ -31,7 +31,7 @@ interface KV {
[index: string]: any;
}
export const updateUser = async (id: number, user: KV) => {
user.updatedAt = new Date();
user.updatedAt = dateToDateTime(new Date());
// Create user
return await query(`UPDATE users SET ${setValues(user)} WHERE id = ?`, [
...Object.values(user),
Expand Down
8 changes: 6 additions & 2 deletions src/helpers/mail.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import * as ses from "node-ses";
import { Mail } from "../interfaces/mail";
import { SES_SECRET, SES_ACCESS, SES_EMAIL } from "../config";
import { SES_SECRET, SES_ACCESS, SES_EMAIL, SES_REGION } from "../config";
import { readFile } from "fs-extra";
import { join } from "path";
import { render } from "mustache";
import marked from "marked";
import i18n from "../i18n";

const client = ses.createClient({ key: SES_ACCESS, secret: SES_SECRET });
const client = ses.createClient({
key: SES_ACCESS,
secret: SES_SECRET,
amazon: `https://email.${SES_REGION}.amazonaws.com`
});

export const sendMail = (mail: Mail) =>
new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ interface KV {
export const setValues = (object: KV) => {
let query = "";
Object.keys(object).forEach(key => {
query += `${key} = "${object[key]}", `;
query += `${key} = ?, `;
});
return query.slice(0, -2);
};
6 changes: 6 additions & 0 deletions src/helpers/string.ts → src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ export const capitalizeFirstAndLastLetter = (string: string) => {

export const capitalizeFirstLetter = (string: string) =>
string.charAt(0).toUpperCase() + string.toLowerCase().slice(1);

export const dateToDateTime = (date: Date) =>
date
.toISOString()
.slice(0, 19)
.replace("T", " ");

0 comments on commit 9ad7747

Please sign in to comment.