Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add ability to process all transactions from blockchain. Closes #16. #17

Merged
merged 1 commit into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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