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 { gtU } from 'Models/User'; | |
// Get User object by id | |
const u = gtU(123); |
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 db from 'Db'; | |
export const getUserById = id => { | |
return db.select('*') | |
->from('users') | |
->where('id', id) | |
->first(); | |
} |
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 db from 'Db'; | |
export const getUserById = id => { | |
return db.select('username,email') | |
->from('users') | |
->where('id', id) | |
->first(); | |
} |
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 db from 'Db'; | |
export const checkUsernameExists = username => { | |
return db.select('*') | |
->from('users') | |
->where('username', username) | |
->first(); | |
} |
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 db from 'db'; | |
export const checkUsernameExists = username => { | |
const user = db.select('id') | |
->from('users') | |
->where('username', username) | |
->first(); | |
return Object.keys(user).length > 0; | |
// returns boolean true | false |
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 { validateParameters } from './utils'; | |
import { checkUsernameExists, checkEmailExists } from './users'; | |
import { insertUser } from './users/db'; | |
export const createNewAccount = async (params) => { | |
await validateParameters(params); | |
await checkUsernameExists(params.username); | |
await checkEmailExists(params.email); | |
return insertUser(params); |
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 (!params.username) { | |
throw new Error('Missing required username'); | |
} | |
if (!params.email) { | |
throw new Error ('Missing required email'); | |
} | |
if (params.username.length > 25) { |
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) { |
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) => { | |
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'); | |