Add validation for account info coming from and going into the meta service.

This commit is contained in:
Spencer Ofwiti
2021-04-27 14:20:18 +03:00
parent 04a7e377d8
commit b3586e460b
5 changed files with 85 additions and 7 deletions

View File

@@ -7,3 +7,4 @@ export * from '@app/_helpers/global-error-handler';
export * from '@app/_helpers/export-csv';
export * from '@app/_helpers/read-csv';
export * from '@app/_helpers/clipboard-copy';
export * from '@app/_helpers/schema-validation';

View File

@@ -0,0 +1,22 @@
import { validatePerson, validateVcard } from 'cic-schemas-data-validator';
async function personValidation(person: any): Promise<void> {
const personValidationErrors = await validatePerson(person);
if (personValidationErrors) {
personValidationErrors.map(error => console.log(`${error.message}`));
}
}
async function vcardValidation(vcard: any): Promise<void> {
const vcardValidationErrors = await validateVcard(vcard);
if (vcardValidationErrors) {
vcardValidationErrors.map(error => console.log(`${error.message}`));
}
}
export {
personValidation,
vcardValidation,
};

View File

@@ -12,6 +12,7 @@ import {MutableKeyStore, PGPSigner, Signer} from '@app/_pgp';
import {RegistryService} from '@app/_services/registry.service';
import {CICRegistry} from 'cic-client';
import {AuthService} from './auth.service';
import {personValidation} from '@app/_helpers';
const vCard = require('vcard-parser');
@Injectable({
@@ -88,6 +89,7 @@ export class UserService {
accountInfo.location.area_name = userLocation;
accountInfo.location.area_type = locationType;
accountInfo.vcard = btoa(vCard.generate(accountInfo.vcard));
await personValidation(accountInfo);
const accountKey = await User.toKey(address);
this.getAccountDetailsFromMeta(accountKey).pipe(first()).subscribe(async res => {
const syncableAccount: Syncable = Envelope.fromJSON(JSON.stringify(res)).unwrap();
@@ -183,6 +185,7 @@ export class UserService {
const account = Envelope.fromJSON(JSON.stringify(res)).unwrap();
this.accountsMeta.push(account);
const accountInfo = account.m.data;
await personValidation(accountInfo);
accountInfo.balance = await this.tokenService.getTokenBalance(accountInfo.identities.evm['bloxberg:8996'][0]);
accountInfo.vcard = vCard.parse(atob(accountInfo.vcard));
this.accounts.unshift(accountInfo);