Add validation for account info coming from and going into the meta service.
This commit is contained in:
@@ -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';
|
||||
|
||||
22
src/app/_helpers/schema-validation.ts
Normal file
22
src/app/_helpers/schema-validation.ts
Normal 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,
|
||||
};
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user