This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { SQS } from 'aws-sdk'; | |
import db from './utils/db'; | |
export const sendQueue = await (payload, options) => { | |
sqs.sendMessage(payload, (error, data) => { | |
if (error) { | |
console.log('Error sending message to queue', error); | |
throw new Error(error.message); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { SQS } from 'aws-sdk'; | |
import db from './utils/db'; | |
export const sendQueue = async (payload, options) => { | |
const sqs = new SQS(options); | |
let queued; | |
try { | |
queued = await sqs.sendMessage(payload).promise(); | |
console.log('Message sent', queued); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { validateEmail } from './validateEmail'; | |
export const createUser = async (params) => { | |
validateEmail(params.email); | |
await insertUser(params); | |
} | |
export const updateUser = params => { | |
validateEmail(params.email); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import emailCheck from 'email-check-lib'; | |
export const validateEmail = email => { | |
const emailCheck = new EmailCheck(); | |
const emailValidated = emailCheck.validate(params.newEmail); | |
if (!emailValidated) { | |
throw new Error('Invalid email'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import EmailCheck from 'email-check-lib'; | |
export const createAccount = params => { | |
const emailCheck = new EmailCheck(); | |
const emailValidated = emailCheck.validate(params.email); | |
if (emailValidated) { | |
... | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const insertUser = async (params) => { | |
const userId = await db.insert('username,email,password') | |
->values(params) | |
->table('users'); | |
return userId; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const insertUser = params => { | |
return db.insert('username,email,password') | |
->values(params) | |
->table('users'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const createNewAccount = async (params) => { | |
if (!validateCreateNewAccountParameters(params)) | |
throw new Error('Validation error'); | |
if (await checkUsernameExists(params.username)) | |
throw new Error('Username already exists'); | |
if (await checkEmailExists(params.email)) | |
throw new Error('Email already exists'); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const createNewAccount = async (params) => { | |
const validated = validateCreateNewAccountParameters(params); | |
if (!validated) { | |
throw new Error('Validation error'); | |
} | |
const usernameExists = await checkUsernameExists(params.username); | |
if (usernameExists) { | |
throw new Error('Username already exists'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const createNewAccount = async (params) => { | |
const validated = validateCreateNewAccountParameters(params); | |
if (validated) { | |
const usernameExists = await checkUsernameExists(params.username); | |
if (!usernameExists) { | |
const emailExists = await checkEmailExists(params.email); | |
if (!emailExists) { |