Skip to content

Commit

Permalink
Merge pull request #18 from JincorTech/develop
Browse files Browse the repository at this point in the history
Develop to merge
  • Loading branch information
AlekNS authored Feb 2, 2018
2 parents b49ec80 + 2fd8ef5 commit a58dc90
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 38 deletions.
3 changes: 3 additions & 0 deletions src/entities/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { VerifyMethod } from './verify.action';
@Index('user_email', () => ({
email: 1
}), { unique: true })
@Index('user_wallets', () => ({
'wallets.address': 1
}), { unique: true })
export class User {
@ObjectIdColumn()
id: ObjectID;
Expand Down
28 changes: 28 additions & 0 deletions src/helpers/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as LRU from 'lru-cache';
import { number } from 'joi';

function escape(str: string): string {
return str.replace(/\+/g, '-')
Expand Down Expand Up @@ -32,6 +33,33 @@ export function chunkArray<T>(srcArray: T[], size: number): T[][] {
);
}

/**
*
* @param items
* @param chunkSize
* @param mapFunc
*/
export async function processAsyncIntRangeByChunks<R>(
from: number, to: number, step: number, chunkSize: number, mapFunc: (item: number) => Promise<R>
): Promise<R[]> {
if (from > to) {
throw new Error('Invalid range');
}
let data: R[] = [];
let numbers: number[];
let j: number;

while(from <= to) {
numbers = [];
for(j = 0; j < chunkSize && from <= to; ++j, from += step) {
numbers.push(from);
}
data = data.concat(await Promise.all(numbers.map(mapFunc)));
}

return data;
}

/**
*
* @param items
Expand Down
2 changes: 1 addition & 1 deletion src/services/app/user/user.account.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class UserAccountApplication {
const existingUser = await getConnection().getMongoRepository(User).findOne({ email });

if (existingUser) {
if (!existingUser.isVerified) {
if (!existingUser.isVerified && bcrypt.compareSync(userData.password, existingUser.passwordHash)) {
return this.initiateCreateAndReturnUser(existingUser, initiateVerification);
} else {
throw new UserExists('User already exists');
Expand Down
Loading

0 comments on commit a58dc90

Please sign in to comment.