Merge pull request 'Fix some issues' (#17) from ajanin into dev
All checks were successful
Build and Push to Registry / build-and-push (push) Successful in 3m56s
All checks were successful
Build and Push to Registry / build-and-push (push) Successful in 3m56s
Reviewed-on: #17
This commit is contained in:
commit
9589cf1116
@ -1,5 +1,3 @@
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import MessageBus from 'src/sdk/MessageBus';
|
||||
|
||||
export default abstract class AbstractService {
|
||||
|
@ -176,14 +176,14 @@ export default class DeedTypeService extends AbstractService {
|
||||
}
|
||||
|
||||
public static updateDeedType(process: any, newData: any): Promise<void> {
|
||||
// Update cache
|
||||
this.setItem('_deed_types_', process);
|
||||
|
||||
return new Promise<void>((resolve: () => void) => {
|
||||
this.messageBus.updateProcess(process.processId, { updated_at: new Date().toISOString(), ...newData }, [], null).then((processUpdated: any) => {
|
||||
const newStateId: string = processUpdated.diffs[0]?.state_id;
|
||||
this.messageBus.notifyUpdate(process.processId, newStateId).then(() => {
|
||||
this.messageBus.validateState(process.processId, newStateId).then(() => {
|
||||
// Update cache
|
||||
this.setItem('_deed_types_', processUpdated);
|
||||
|
||||
resolve();
|
||||
}).catch(() => console.error('Failed to validate state'));
|
||||
}).catch(() => console.error('Failed to notify update'));
|
||||
|
@ -1,3 +1,8 @@
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import User from 'src/sdk/User';
|
||||
import MessageBus from 'src/sdk/MessageBus';
|
||||
|
||||
import RuleService from './RuleService';
|
||||
import RuleGroupService from './RuleGroupService';
|
||||
import RoleService from './RoleService';
|
||||
@ -19,7 +24,9 @@ export interface ProgressInfo {
|
||||
|
||||
export default class ImportData {
|
||||
|
||||
public static async import(office: any, onProgress?: (info: ProgressInfo) => void): Promise<void> {
|
||||
protected static readonly messageBus: MessageBus = MessageBus.getInstance();
|
||||
|
||||
public static async import(office: any, validatorId: string, onProgress?: (info: ProgressInfo) => void): Promise<void> {
|
||||
// Définir les étapes d'importation dynamiquement
|
||||
const importSteps = [
|
||||
{
|
||||
@ -81,6 +88,86 @@ export default class ImportData {
|
||||
results.push(result);
|
||||
}
|
||||
}
|
||||
|
||||
if (!await this.isDone()) {
|
||||
await this.done(validatorId);
|
||||
}
|
||||
}
|
||||
|
||||
public static async isDone(): Promise<boolean> {
|
||||
return await this.messageBus.getProcessesDecoded((publicValues: any) =>
|
||||
publicValues['uid'] &&
|
||||
publicValues['utype'] &&
|
||||
publicValues['utype'] === 'importData' &&
|
||||
publicValues['isDeleted'] && publicValues['isDeleted'] === 'false'
|
||||
).then(async (processes: any[]) => processes.length > 0);
|
||||
}
|
||||
|
||||
private static async done(validatorId: string): Promise<any> {
|
||||
const ownerId = User.getInstance().getPairingId()!;
|
||||
|
||||
const processData: any = {
|
||||
uid: uuidv4(),
|
||||
utype: 'importData',
|
||||
isDeleted: 'false',
|
||||
created_at: new Date().toISOString(),
|
||||
updated_at: new Date().toISOString()
|
||||
};
|
||||
|
||||
const privateFields: string[] = Object.keys(processData);
|
||||
privateFields.splice(privateFields.indexOf('uid'), 1);
|
||||
privateFields.splice(privateFields.indexOf('utype'), 1);
|
||||
privateFields.splice(privateFields.indexOf('isDeleted'), 1);
|
||||
|
||||
const roles: any = {
|
||||
demiurge: {
|
||||
members: [...[ownerId], validatorId],
|
||||
validation_rules: [],
|
||||
storages: []
|
||||
},
|
||||
owner: {
|
||||
members: [ownerId],
|
||||
validation_rules: [
|
||||
{
|
||||
quorum: 0.5,
|
||||
fields: [...privateFields, 'roles', 'uid', 'utype'],
|
||||
min_sig_member: 1,
|
||||
},
|
||||
],
|
||||
storages: []
|
||||
},
|
||||
validator: {
|
||||
members: [validatorId],
|
||||
validation_rules: [
|
||||
{
|
||||
quorum: 0.5,
|
||||
fields: ['idCertified', 'roles'],
|
||||
min_sig_member: 1,
|
||||
},
|
||||
{
|
||||
quorum: 0.0,
|
||||
fields: [...privateFields],
|
||||
min_sig_member: 0,
|
||||
},
|
||||
],
|
||||
storages: []
|
||||
},
|
||||
apophis: {
|
||||
members: [ownerId],
|
||||
validation_rules: [],
|
||||
storages: []
|
||||
}
|
||||
};
|
||||
|
||||
return new Promise<void>((resolve: () => void, reject: (error: string) => void) => {
|
||||
this.messageBus.createProcess(processData, privateFields, roles).then((processCreated: any) => {
|
||||
this.messageBus.notifyUpdate(processCreated.processId, processCreated.process.states[0].state_id).then(() => {
|
||||
this.messageBus.validateState(processCreated.processId, processCreated.process.states[0].state_id).then(() => {
|
||||
resolve();
|
||||
}).catch(reject);
|
||||
}).catch(reject);
|
||||
}).catch(reject);
|
||||
});
|
||||
}
|
||||
|
||||
private static async importRules(onProgress?: (progress: number, description?: string) => void): Promise<any[]> {
|
||||
|
@ -63,6 +63,7 @@ export default function LoginCallBack() {
|
||||
office_status: 'ACTIVATED'
|
||||
};
|
||||
const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0';
|
||||
|
||||
OfficeService.createOffice(officeData, validatorId).then((process: any) => {
|
||||
if (process) {
|
||||
const office: any = process.processData;
|
||||
@ -74,13 +75,50 @@ export default function LoginCallBack() {
|
||||
});
|
||||
};
|
||||
|
||||
const getCollaborator = async (collaboratorData: any) => {
|
||||
const getCollaborator = async (idNotUser: any) => {
|
||||
return await new Promise<any>(async (resolve: (role: any) => void) => {
|
||||
const processFound: any | null = await CollaboratorService.getCollaboratorBy({ idNot: idNotUser.idNot });
|
||||
if (processFound) {
|
||||
resolve(processFound.processData);
|
||||
} else {
|
||||
const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0';
|
||||
const office: any = await getOffice(idNotUser);
|
||||
|
||||
if (!await ImportData.isDone()) {
|
||||
LoaderService.getInstance().hide();
|
||||
setShowProgress(true);
|
||||
|
||||
await ImportData.import(office, validatorId, (info: ProgressInfo) => {
|
||||
setProgressInfo(info);
|
||||
});
|
||||
|
||||
setShowProgress(false);
|
||||
LoaderService.getInstance().show();
|
||||
}
|
||||
|
||||
const role: any = (await RoleService.getRoles())
|
||||
.map((process: any) => process.processData)
|
||||
.find((role: any) => role.name === idNotUser.role.name);
|
||||
|
||||
const officeRole: any = (await OfficeRoleService.getOfficeRoles())
|
||||
.map((process: any) => process.processData)
|
||||
.filter((officeRole: any) => officeRole.office.uid === office.uid)
|
||||
.find((officeRole: any) => officeRole.name === idNotUser.office_role.name);
|
||||
|
||||
const collaboratorData: any = {
|
||||
idNot: idNotUser.idNot,
|
||||
contact: idNotUser.contact,
|
||||
office: {
|
||||
uid: office.uid
|
||||
},
|
||||
role: {
|
||||
uid: role.uid
|
||||
},
|
||||
office_role: {
|
||||
uid: officeRole.uid
|
||||
}
|
||||
};
|
||||
|
||||
CollaboratorService.createCollaborator(collaboratorData, validatorId).then((process: any) => {
|
||||
if (process) {
|
||||
const collaborator: any = process.processData;
|
||||
@ -235,40 +273,7 @@ export default function LoginCallBack() {
|
||||
LoaderService.getInstance().show();
|
||||
MessageBus.getInstance().initMessageListener();
|
||||
MessageBus.getInstance().isReady().then(async () => {
|
||||
const office: any = await getOffice(idNotUser);
|
||||
LoaderService.getInstance().hide();
|
||||
|
||||
setShowProgress(true);
|
||||
await ImportData.import(office, (info: ProgressInfo) => {
|
||||
setProgressInfo(info);
|
||||
});
|
||||
setShowProgress(false);
|
||||
|
||||
LoaderService.getInstance().show();
|
||||
|
||||
const role: any = (await RoleService.getRoles())
|
||||
.map((process: any) => process.processData)
|
||||
.find((role: any) => role.name === idNotUser.role.name);
|
||||
|
||||
const officeRole: any = (await OfficeRoleService.getOfficeRoles())
|
||||
.map((process: any) => process.processData)
|
||||
.filter((officeRole: any) => officeRole.office.uid === office.uid)
|
||||
.find((officeRole: any) => officeRole.name === idNotUser.office_role.name);
|
||||
|
||||
const collaboratorData: any = {
|
||||
idNot: idNotUser.idNot,
|
||||
contact: idNotUser.contact,
|
||||
office: {
|
||||
uid: office.uid
|
||||
},
|
||||
role: {
|
||||
uid: role.uid
|
||||
},
|
||||
office_role: {
|
||||
uid: officeRole.uid
|
||||
}
|
||||
};
|
||||
const collaborator: any = await getCollaborator(collaboratorData);
|
||||
const collaborator: any = await getCollaborator(idNotUser);
|
||||
UserStore.instance.connect(collaborator);
|
||||
|
||||
MessageBus.getInstance().destroyMessageListener();
|
||||
|
Loading…
x
Reference in New Issue
Block a user