123 lines
2.5 KiB
TypeScript
123 lines
2.5 KiB
TypeScript
import { isFileBlob, type FileBlob } from "./Data";
|
|
import type { RoleDefinition } from "./Roles";
|
|
|
|
export interface ProfileData {
|
|
name: string;
|
|
surname: string;
|
|
email: string;
|
|
phone: string;
|
|
address: string;
|
|
postalCode: string;
|
|
city: string;
|
|
country: string;
|
|
idDocument: FileBlob | null;
|
|
idCertified: boolean;
|
|
}
|
|
|
|
export function isProfileData(data: any): data is ProfileData{
|
|
if (typeof data !== 'object' || data === null) return false;
|
|
|
|
const requiredStringFields = [
|
|
'name',
|
|
'surname',
|
|
'email',
|
|
'phone',
|
|
'address',
|
|
'postalCode',
|
|
'city',
|
|
'country',
|
|
];
|
|
|
|
for (const field of requiredStringFields) {
|
|
if (typeof data[field] !== 'string') return false;
|
|
}
|
|
|
|
const requiredBooleanFields = [
|
|
'idCertified',
|
|
];
|
|
|
|
for (const field of requiredBooleanFields) {
|
|
if (typeof data[field] !== 'boolean') return false;
|
|
}
|
|
|
|
const requiredFileFields = [
|
|
'idDocument',
|
|
];
|
|
|
|
for (const field of requiredFileFields) {
|
|
if (!isFileBlob(data[field]) && data[field] !== null) return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
const emptyProfileData: ProfileData = {
|
|
name: '',
|
|
surname: '',
|
|
email: '',
|
|
phone: '',
|
|
address: '',
|
|
postalCode: '',
|
|
city: '',
|
|
country: '',
|
|
idDocument: null,
|
|
idCertified: false,
|
|
};
|
|
|
|
const profileDataFields: string[] = Object.keys(emptyProfileData);
|
|
|
|
const ProfilePublicFields: string[] = ['idCertified'];
|
|
|
|
export const ProfilePrivateFields = [
|
|
...profileDataFields.filter(key => !ProfilePublicFields.includes(key))
|
|
];
|
|
|
|
export interface ProfileCreated {
|
|
processId: string,
|
|
process: any, // Process
|
|
profileData: ProfileData,
|
|
}
|
|
|
|
export function setDefaultProfileRoles(ownerId: string[], validatorId: string): Record<string, RoleDefinition> {
|
|
return {
|
|
demiurge: {
|
|
members: [...ownerId, validatorId],
|
|
validation_rules: [],
|
|
storages: []
|
|
},
|
|
owner: {
|
|
members: ownerId,
|
|
validation_rules: [
|
|
{
|
|
quorum: 0.5,
|
|
fields: [...ProfilePrivateFields, 'roles'],
|
|
min_sig_member: 1,
|
|
},
|
|
],
|
|
storages: []
|
|
},
|
|
validator: {
|
|
members: [validatorId],
|
|
validation_rules: [
|
|
{
|
|
quorum: 0.5,
|
|
fields: ['idCertified', 'roles'],
|
|
min_sig_member: 1,
|
|
},
|
|
{
|
|
quorum: 0.0,
|
|
fields: [...profileDataFields],
|
|
min_sig_member: 0,
|
|
},
|
|
],
|
|
storages: []
|
|
},
|
|
apophis: {
|
|
members: ownerId,
|
|
validation_rules: [],
|
|
storages: []
|
|
}
|
|
}
|
|
};
|
|
|