Compare commits
13 Commits
a6a67d4b7c
...
eb0ae9e967
Author | SHA1 | Date | |
---|---|---|---|
![]() |
eb0ae9e967 | ||
![]() |
223baaed7e | ||
![]() |
64f6b4ed98 | ||
![]() |
66befaa7ed | ||
![]() |
903668139f | ||
![]() |
8a09d0135e | ||
![]() |
4481c39751 | ||
![]() |
72fc3ff790 | ||
![]() |
f7d6661f20 | ||
![]() |
7923a29ce2 | ||
![]() |
9d8e477f63 | ||
![]() |
10ad0c3ca8 | ||
![]() |
01c041c11b |
@ -261,34 +261,26 @@ export default class CollaboratorService extends AbstractService {
|
|||||||
|
|
||||||
if (process.processData.office) {
|
if (process.processData.office) {
|
||||||
const office: any = (await OfficeService.getOfficeByUid(process.processData.office.uid)).processData;
|
const office: any = (await OfficeService.getOfficeByUid(process.processData.office.uid)).processData;
|
||||||
if (office) {
|
process.processData.office = {
|
||||||
process.processData.office = {
|
uid: office.uid,
|
||||||
uid: office.uid,
|
idNot: office.idNot,
|
||||||
idNot: office.idNot,
|
crpcen: office.crpcen,
|
||||||
crpcen: office.crpcen,
|
name: office.name,
|
||||||
name: office.name,
|
office_status: office.office_status
|
||||||
office_status: office.office_status
|
};
|
||||||
};
|
|
||||||
|
|
||||||
if (progressCallback) {
|
if (progressCallback) {
|
||||||
progressiveProcess.processData.office = process.processData.office;
|
progressiveProcess.processData.office = process.processData.office;
|
||||||
progressCallback(JSON.parse(JSON.stringify(progressiveProcess)));
|
progressCallback(JSON.parse(JSON.stringify(progressiveProcess)));
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.error('Office not found');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.processData.role) {
|
if (process.processData.role) {
|
||||||
const role: any = (await RoleService.getRoleByUid(process.processData.role.uid)).processData;
|
const role: any = (await RoleService.getRoleByUid(process.processData.role.uid)).processData;
|
||||||
if (!role) {
|
process.processData.role = {
|
||||||
console.error('Role not found');
|
uid: role.uid,
|
||||||
} else {
|
name: role.name
|
||||||
process.processData.role = {
|
};
|
||||||
uid: role.uid,
|
|
||||||
name: role.name
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (progressCallback) {
|
if (progressCallback) {
|
||||||
progressiveProcess.processData.role = process.processData.role;
|
progressiveProcess.processData.role = process.processData.role;
|
||||||
@ -298,20 +290,16 @@ export default class CollaboratorService extends AbstractService {
|
|||||||
|
|
||||||
if (process.processData.office_role) {
|
if (process.processData.office_role) {
|
||||||
const officeRole: any = (await OfficeRoleService.getOfficeRoleByUid(process.processData.office_role.uid)).processData;
|
const officeRole: any = (await OfficeRoleService.getOfficeRoleByUid(process.processData.office_role.uid)).processData;
|
||||||
if (!officeRole) {
|
process.processData.office_role = {
|
||||||
console.error('Office role not found');
|
uid: officeRole.uid,
|
||||||
} else {
|
name: officeRole.name,
|
||||||
process.processData.office_role = {
|
rules: officeRole.rules?.map((rule: any) => {
|
||||||
uid: officeRole.uid,
|
return {
|
||||||
name: officeRole.name,
|
uid: rule.uid,
|
||||||
rules: officeRole.rules?.map((rule: any) => {
|
name: rule.name
|
||||||
return {
|
};
|
||||||
uid: rule.uid,
|
})
|
||||||
name: rule.name
|
};
|
||||||
};
|
|
||||||
})
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (progressCallback) {
|
if (progressCallback) {
|
||||||
progressiveProcess.processData.office_role = process.processData.office_role;
|
progressiveProcess.processData.office_role = process.processData.office_role;
|
||||||
|
@ -4,7 +4,7 @@ import User from 'src/sdk/User';
|
|||||||
|
|
||||||
import AbstractService from './AbstractService';
|
import AbstractService from './AbstractService';
|
||||||
|
|
||||||
import { DEFAULT_STORAGE_URLS } from '@Front/Config/AppConstants';
|
import DocumentTypeService from './DocumentTypeService';
|
||||||
|
|
||||||
export default class DeedTypeService extends AbstractService {
|
export default class DeedTypeService extends AbstractService {
|
||||||
|
|
||||||
@ -12,7 +12,7 @@ export default class DeedTypeService extends AbstractService {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async createDeedType(deedTypeData: any, validatorId: string): Promise<{ processId: string, processData: any }> {
|
public static createDeedType(deedTypeData: any, validatorId: string): Promise<any> {
|
||||||
const ownerId: string = User.getInstance().getPairingId()!;
|
const ownerId: string = User.getInstance().getPairingId()!;
|
||||||
|
|
||||||
const processData: any = {
|
const processData: any = {
|
||||||
@ -25,65 +25,105 @@ export default class DeedTypeService extends AbstractService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const privateFields: string[] = Object.keys(processData);
|
const privateFields: string[] = Object.keys(processData);
|
||||||
const allFields: string[] = [...privateFields, 'roles'];
|
privateFields.splice(privateFields.indexOf('uid'), 1);
|
||||||
|
privateFields.splice(privateFields.indexOf('utype'), 1);
|
||||||
|
privateFields.splice(privateFields.indexOf('isDeleted'), 1);
|
||||||
|
|
||||||
const roles: any = {
|
const roles: any = {
|
||||||
demiurge: {
|
demiurge: {
|
||||||
members: [ownerId],
|
members: [...[ownerId], validatorId],
|
||||||
validation_rules: [],
|
validation_rules: [],
|
||||||
storages: []
|
storages: []
|
||||||
},
|
},
|
||||||
owner: {
|
owner: {
|
||||||
members: [ownerId, validatorId],
|
members: [ownerId],
|
||||||
validation_rules: [
|
validation_rules: [
|
||||||
{
|
{
|
||||||
quorum: 0.01,
|
quorum: 0.5,
|
||||||
fields: allFields,
|
fields: [...privateFields, 'roles', 'uid', 'utype'],
|
||||||
min_sig_member: 0.01,
|
min_sig_member: 1,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
storages: [...DEFAULT_STORAGE_URLS]
|
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: {
|
apophis: {
|
||||||
members: [ownerId, validatorId],
|
members: [ownerId],
|
||||||
validation_rules: [],
|
validation_rules: [],
|
||||||
storages: []
|
storages: []
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
return new Promise<any>((resolve: (processCreated: any) => void, reject: (error: string) => void) => {
|
||||||
const processCreated = await this.messageBus.createProcess(processData, privateFields, roles);
|
this.messageBus.createProcess(processData, privateFields, roles).then((processCreated: any) => {
|
||||||
await this.messageBus.notifyUpdate(processCreated.processId, processCreated.process.states[0].state_id);
|
this.messageBus.notifyUpdate(processCreated.processId, processCreated.process.states[0].state_id).then(() => {
|
||||||
await this.messageBus.validateState(processCreated.processId, processCreated.process.states[0].state_id);
|
this.messageBus.validateState(processCreated.processId, processCreated.process.states[0].state_id).then((_stateValidated: any) => {
|
||||||
const finalProcessData = await this.messageBus.getProcessData(processCreated.processId);
|
this.getDeedTypeByUid(processCreated.processData.uid).then(resolve).catch(reject);
|
||||||
|
}).catch(reject);
|
||||||
return { processId: processCreated.processId, processData: finalProcessData };
|
}).catch(reject);
|
||||||
} catch (error) {
|
}).catch(reject);
|
||||||
throw error;
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getDeedTypes(callback: (processes: any[]) => void): void {
|
public static getDeedTypes(callback: (processes: any[]) => void, waitForAll: boolean = false): void {
|
||||||
// Check if we have valid cache
|
// Check if we have valid cache
|
||||||
const items: any[] = this.getItems('_deed_types_');
|
const items: any[] = this.getItems('_deed_types_');
|
||||||
if (items.length > 0) {
|
if (items.length > 0 && !waitForAll) {
|
||||||
setTimeout(() => callback([...items]), 0);
|
setTimeout(() => callback([...items]), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.messageBus.getProcessesDecoded((values: any) => {
|
this.messageBus.getProcessesDecoded((publicValues: any) =>
|
||||||
return values['utype'] === 'deedType'
|
publicValues['uid'] &&
|
||||||
&& values['isDeleted'] === 'false';
|
publicValues['utype'] &&
|
||||||
}).then(async (processes: any) => {
|
publicValues['utype'] === 'deedType' &&
|
||||||
|
publicValues['isDeleted'] &&
|
||||||
|
publicValues['isDeleted'] === 'false' &&
|
||||||
|
!items.map((item: any) => item.processData.uid).includes(publicValues['uid'])
|
||||||
|
).then(async (processes: any[]) => {
|
||||||
if (processes.length === 0) {
|
if (processes.length === 0) {
|
||||||
callback([...items]);
|
if (waitForAll) {
|
||||||
|
callback([...items]);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedItems: any[] = [...items];
|
const updatedItems: any[] = [...items];
|
||||||
|
|
||||||
for (let processIndex = 0; processIndex < processes.length; processIndex++) {
|
for (let processIndex = 0; processIndex < processes.length; processIndex++) {
|
||||||
const process = processes[processIndex];
|
let process = processes[processIndex];
|
||||||
|
|
||||||
|
if (!waitForAll) {
|
||||||
|
process = await this.completeDeedType(process, (processInProgress: any) => {
|
||||||
|
const currentItems: any[] = [...updatedItems];
|
||||||
|
|
||||||
|
const existingIndex: number = currentItems.findIndex(item => item.processData?.uid === processInProgress.processData?.uid);
|
||||||
|
if (existingIndex >= 0) {
|
||||||
|
currentItems[existingIndex] = processInProgress;
|
||||||
|
} else {
|
||||||
|
currentItems.push(processInProgress);
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(currentItems);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
process = await this.completeDeedType(process);
|
||||||
|
}
|
||||||
|
|
||||||
// Update cache
|
// Update cache
|
||||||
this.setItem('_deed_types_', process);
|
this.setItem('_deed_types_', process);
|
||||||
|
|
||||||
@ -93,33 +133,90 @@ export default class DeedTypeService extends AbstractService {
|
|||||||
} else {
|
} else {
|
||||||
updatedItems.push(process);
|
updatedItems.push(process);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!waitForAll) {
|
||||||
|
callback([...updatedItems]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
callback([...updatedItems]);
|
if (waitForAll) {
|
||||||
|
callback([...updatedItems]);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async updateDeedType(processId: string, newData: any): Promise<void> {
|
public static getDeedTypeByUid(uid: string): Promise<any> {
|
||||||
try {
|
// Check if we have valid cache
|
||||||
const processUpdated = await this.messageBus.updateProcess(
|
const item: any = this.getItem('_deed_types_', uid);
|
||||||
processId,
|
if (item) {
|
||||||
{ updated_at: new Date().toISOString(), ...newData },
|
return Promise.resolve(item);
|
||||||
[],
|
|
||||||
null
|
|
||||||
);
|
|
||||||
|
|
||||||
const newStateId: string = processUpdated.diffs[0]?.state_id;
|
|
||||||
await this.messageBus.notifyUpdate(processId, newStateId);
|
|
||||||
await this.messageBus.validateState(processId, newStateId);
|
|
||||||
|
|
||||||
const processData = await this.messageBus.getProcessData(processId);
|
|
||||||
|
|
||||||
// Update cache
|
|
||||||
this.setItem('_deed_types_', processData);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to update deed type:', error);
|
|
||||||
throw error; // Re-throw to allow caller to handle
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new Promise<any>((resolve: (process: any) => void, reject: (error: string) => void) => {
|
||||||
|
this.messageBus.getProcessesDecoded((publicValues: any) =>
|
||||||
|
publicValues['uid'] &&
|
||||||
|
publicValues['uid'] === uid &&
|
||||||
|
publicValues['utype'] &&
|
||||||
|
publicValues['utype'] === 'deedType' &&
|
||||||
|
publicValues['isDeleted'] &&
|
||||||
|
publicValues['isDeleted'] === 'false'
|
||||||
|
).then(async (processes: any[]) => {
|
||||||
|
if (processes.length === 0) {
|
||||||
|
resolve(null);
|
||||||
|
} else {
|
||||||
|
let process: any = processes[0];
|
||||||
|
process = await this.completeDeedType(process);
|
||||||
|
|
||||||
|
// Update cache
|
||||||
|
this.setItem('_deed_types_', process);
|
||||||
|
|
||||||
|
resolve(process);
|
||||||
|
}
|
||||||
|
}).catch(reject);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static updateDeedType(process: any, newData: any): Promise<void> {
|
||||||
|
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_', process);
|
||||||
|
|
||||||
|
resolve();
|
||||||
|
}).catch((error) => console.error('Failed to validate state', error));
|
||||||
|
}).catch((error) => console.error('Failed to notify update', error));
|
||||||
|
}).catch((error) => console.error('Failed to update', error));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async completeDeedType(process: any, progressCallback?: (processInProgress: any) => void): Promise<any> {
|
||||||
|
const progressiveProcess: any = JSON.parse(JSON.stringify(process));
|
||||||
|
|
||||||
|
if (process.processData.document_types && process.processData.document_types.length > 0) {
|
||||||
|
progressiveProcess.processData.document_types = [];
|
||||||
|
if (progressCallback) {
|
||||||
|
progressCallback(progressiveProcess);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const document_type of process.processData.document_types) {
|
||||||
|
const documentTypeData = (await DocumentTypeService.getDocumentTypeByUid(document_type.uid)).processData;
|
||||||
|
progressiveProcess.processData.document_types.push(documentTypeData);
|
||||||
|
|
||||||
|
// Remove duplicates
|
||||||
|
progressiveProcess.processData.document_types = progressiveProcess.processData.document_types
|
||||||
|
.filter((item: any, index: number) => progressiveProcess.processData.document_types.findIndex((t: any) => t.uid === item.uid) === index);
|
||||||
|
|
||||||
|
if (progressCallback) {
|
||||||
|
progressCallback(JSON.parse(JSON.stringify(progressiveProcess)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
process.processData.document_types = progressiveProcess.processData.document_types;
|
||||||
|
}
|
||||||
|
|
||||||
|
return process;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ import { v4 as uuidv4 } from 'uuid';
|
|||||||
import User from 'src/sdk/User';
|
import User from 'src/sdk/User';
|
||||||
|
|
||||||
import AbstractService from './AbstractService';
|
import AbstractService from './AbstractService';
|
||||||
import { DEFAULT_STORAGE_URLS } from '@Front/Config/AppConstants';
|
|
||||||
|
|
||||||
export default class DocumentTypeService extends AbstractService {
|
export default class DocumentTypeService extends AbstractService {
|
||||||
|
|
||||||
@ -11,7 +10,7 @@ export default class DocumentTypeService extends AbstractService {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static createDocumentType(documentTypeData: any, validatorId: string): Promise<{ processId: string, processData: any }> {
|
public static createDocumentType(documentTypeData: any, validatorId: string): Promise<any> {
|
||||||
const ownerId: string = User.getInstance().getPairingId()!;
|
const ownerId: string = User.getInstance().getPairingId()!;
|
||||||
|
|
||||||
const processData: any = {
|
const processData: any = {
|
||||||
@ -24,27 +23,45 @@ export default class DocumentTypeService extends AbstractService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const privateFields: string[] = Object.keys(processData);
|
const privateFields: string[] = Object.keys(processData);
|
||||||
const allFields: string[] = [...privateFields, 'roles'];
|
privateFields.splice(privateFields.indexOf('uid'), 1);
|
||||||
|
privateFields.splice(privateFields.indexOf('utype'), 1);
|
||||||
|
privateFields.splice(privateFields.indexOf('isDeleted'), 1);
|
||||||
|
|
||||||
const roles: any = {
|
const roles: any = {
|
||||||
demiurge: {
|
demiurge: {
|
||||||
members: [ownerId],
|
members: [...[ownerId], validatorId],
|
||||||
validation_rules: [],
|
validation_rules: [],
|
||||||
storages: []
|
storages: []
|
||||||
},
|
},
|
||||||
owner: {
|
owner: {
|
||||||
members: [ownerId, validatorId],
|
members: [ownerId],
|
||||||
validation_rules: [
|
validation_rules: [
|
||||||
{
|
{
|
||||||
quorum: 0.01,
|
quorum: 0.5,
|
||||||
fields: allFields,
|
fields: [...privateFields, 'roles', 'uid', 'utype'],
|
||||||
min_sig_member: 0.01,
|
min_sig_member: 1,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
storages: [...DEFAULT_STORAGE_URLS]
|
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: {
|
apophis: {
|
||||||
members: [ownerId, validatorId],
|
members: [ownerId],
|
||||||
validation_rules: [],
|
validation_rules: [],
|
||||||
storages: []
|
storages: []
|
||||||
}
|
}
|
||||||
@ -54,80 +71,39 @@ export default class DocumentTypeService extends AbstractService {
|
|||||||
this.messageBus.createProcess(processData, privateFields, roles).then((processCreated: any) => {
|
this.messageBus.createProcess(processData, privateFields, roles).then((processCreated: any) => {
|
||||||
this.messageBus.notifyUpdate(processCreated.processId, processCreated.process.states[0].state_id).then(() => {
|
this.messageBus.notifyUpdate(processCreated.processId, processCreated.process.states[0].state_id).then(() => {
|
||||||
this.messageBus.validateState(processCreated.processId, processCreated.process.states[0].state_id).then((_stateValidated: any) => {
|
this.messageBus.validateState(processCreated.processId, processCreated.process.states[0].state_id).then((_stateValidated: any) => {
|
||||||
this.messageBus.getProcessData(processCreated.processId).then((processData: any) => {
|
this.getDocumentTypeByUid(processCreated.processData.uid).then(resolve).catch(reject);
|
||||||
resolve({ processId: processCreated.processId, processData: processData });
|
|
||||||
}).catch(reject);
|
|
||||||
}).catch(reject);
|
}).catch(reject);
|
||||||
}).catch(reject);
|
}).catch(reject);
|
||||||
}).catch(reject);
|
}).catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getDocumentTypes(callback: (processes: any[]) => void): void {
|
public static getDocumentTypes(): Promise<any[]> {
|
||||||
// Check if we have valid cache
|
// Check if we have valid cache
|
||||||
const items: any[] = this.getItems('_document_types_');
|
const items: any[] = this.getItems('_document_types_');
|
||||||
if (items.length > 0) {
|
|
||||||
setTimeout(() => callback([...items]), 0);
|
return this.messageBus.getProcessesDecoded((publicValues: any) =>
|
||||||
}
|
publicValues['uid'] &&
|
||||||
|
publicValues['utype'] &&
|
||||||
this.messageBus.getProcessesDecoded((values: any) => {
|
publicValues['utype'] === 'documentType' &&
|
||||||
return values['utype'] === 'documentType'
|
publicValues['isDeleted'] &&
|
||||||
&& values['isDeleted'] === 'false';
|
publicValues['isDeleted'] === 'false' &&
|
||||||
}).then(async (processes: any) => {
|
!items.map((item: any) => item.processData.uid).includes(publicValues['uid'])
|
||||||
|
).then(async (processes: any[]) => {
|
||||||
if (processes.length === 0) {
|
if (processes.length === 0) {
|
||||||
callback([...items]);
|
return items;
|
||||||
return;
|
} else {
|
||||||
}
|
for (const process of processes) {
|
||||||
|
// Update cache
|
||||||
|
this.setItem('_document_types_', process);
|
||||||
|
|
||||||
const updatedItems: any[] = [...items];
|
items.push(process);
|
||||||
|
|
||||||
for (let processIndex = 0; processIndex < processes.length; processIndex++) {
|
|
||||||
const process = processes[processIndex];
|
|
||||||
|
|
||||||
// Update cache
|
|
||||||
this.setItem('_document_types_', process);
|
|
||||||
|
|
||||||
const existingIndex: number = updatedItems.findIndex(item => item.processId === process.processId);
|
|
||||||
if (existingIndex >= 0) {
|
|
||||||
updatedItems[existingIndex] = process;
|
|
||||||
} else {
|
|
||||||
updatedItems.push(process);
|
|
||||||
}
|
}
|
||||||
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
callback([...updatedItems]);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getDocumentTypeByProcessId(processId: string): Promise<any> {
|
|
||||||
// Check if we have valid cache
|
|
||||||
const item: any = this.getItem('_document_types_', processId);
|
|
||||||
if (item) {
|
|
||||||
return Promise.resolve(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Promise<any>((resolve: (process: any) => void, reject: (error: string) => void) => {
|
|
||||||
this.messageBus.getProcessesDecoded((publicValues: any) => {
|
|
||||||
return publicValues['utype'] === 'documentType' && publicValues['isDeleted'] === 'false';
|
|
||||||
}).then((processes: any[]) => {
|
|
||||||
// Find the process with matching processId
|
|
||||||
const process = processes.find((p: any) => p.processId === processId);
|
|
||||||
|
|
||||||
if (!process) {
|
|
||||||
resolve(null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update cache
|
|
||||||
this.setItem('_document_types_', process);
|
|
||||||
|
|
||||||
resolve(process);
|
|
||||||
}).catch(reject);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Keep the old method for backward compatibility but mark as deprecated
|
|
||||||
/** @deprecated Use getDocumentTypeByProcessId instead */
|
|
||||||
public static getDocumentTypeByUid(uid: string): Promise<any> {
|
public static getDocumentTypeByUid(uid: string): Promise<any> {
|
||||||
// Check if we have valid cache
|
// Check if we have valid cache
|
||||||
const item: any = this.getItem('_document_types_', uid);
|
const item: any = this.getItem('_document_types_', uid);
|
||||||
@ -157,9 +133,10 @@ export default class DocumentTypeService extends AbstractService {
|
|||||||
const newStateId: string = processUpdated.diffs[0]?.state_id;
|
const newStateId: string = processUpdated.diffs[0]?.state_id;
|
||||||
this.messageBus.notifyUpdate(process.processId, newStateId).then(() => {
|
this.messageBus.notifyUpdate(process.processId, newStateId).then(() => {
|
||||||
this.messageBus.validateState(process.processId, newStateId).then((_stateValidated) => {
|
this.messageBus.validateState(process.processId, newStateId).then((_stateValidated) => {
|
||||||
this.removeItem('_document_types_', process.processId);
|
const documentTypeUid: string = process.processData.uid;
|
||||||
|
this.removeItem('_document_types_', documentTypeUid);
|
||||||
|
|
||||||
this.getDocumentTypeByProcessId(process.processId).then(resolve).catch(reject);
|
this.getDocumentTypeByUid(documentTypeUid).then(resolve).catch(reject);
|
||||||
}).catch(reject);
|
}).catch(reject);
|
||||||
}).catch(reject);
|
}).catch(reject);
|
||||||
}).catch(reject);
|
}).catch(reject);
|
||||||
|
@ -28,8 +28,6 @@ export default function DefaultDeedTypeDashboard(props: IProps) {
|
|||||||
deedTypes.sort((a: any, b: any) => a.name.localeCompare(b.name));
|
deedTypes.sort((a: any, b: any) => a.name.localeCompare(b.name));
|
||||||
|
|
||||||
setDeedTypes(deedTypes);
|
setDeedTypes(deedTypes);
|
||||||
} else {
|
|
||||||
console.log('[DefaultDeedTypeDashboard] No deed types found');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
@ -53,7 +51,7 @@ export default function DefaultDeedTypeDashboard(props: IProps) {
|
|||||||
}
|
}
|
||||||
bottomButton={{
|
bottomButton={{
|
||||||
link: Module.getInstance().get().modules.pages.DeedTypes.pages.Create.props.path,
|
link: Module.getInstance().get().modules.pages.DeedTypes.pages.Create.props.path,
|
||||||
text: "Créer une liste de pièces", // TODO I think this is misleading, should be "Créer un type d'acte"
|
text: "Créer une liste de pièces",
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@ -24,74 +24,44 @@ export default function DocumentTypesCreate(props: IProps) {
|
|||||||
const [validationError, setValidationError] = useState<ValidationError[]>([]);
|
const [validationError, setValidationError] = useState<ValidationError[]>([]);
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const handleCancel = useCallback(() => {
|
|
||||||
router.push(Module.getInstance().get().modules.pages.DocumentTypes.props.path);
|
|
||||||
}, [router]);
|
|
||||||
|
|
||||||
const onSubmitHandler = useCallback(
|
const onSubmitHandler = useCallback(
|
||||||
async (e: React.FormEvent<HTMLFormElement> | null, values: { [key: string]: string }) => {
|
async (e: React.FormEvent<HTMLFormElement> | null, values: { [key: string]: string }) => {
|
||||||
try {
|
try {
|
||||||
const user: any = UserStore.instance.getUser();
|
const user: any = UserStore.instance.getUser();
|
||||||
if (!user) {
|
const officeId: string = user.office.uid;
|
||||||
console.error("DocumentTypesCreate: User not found - user is null or undefined");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const office = UserStore.instance.getOffice();
|
|
||||||
if (!office) {
|
|
||||||
console.error("DocumentTypesCreate: office not found - office is undefined or null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const officeId = office.processId;
|
|
||||||
const officeIdNot = office.processData.idNot;
|
|
||||||
|
|
||||||
// const documentFormModel = DocumentType.hydrate<DocumentType>({
|
const documentFormModel = DocumentType.hydrate<DocumentType>({
|
||||||
// ...values,
|
...values,
|
||||||
// office: Office.hydrate<Office>({
|
office: Office.hydrate<Office>({
|
||||||
// uid: officeId,
|
uid: officeId,
|
||||||
// })
|
})
|
||||||
// });
|
});
|
||||||
// await validateOrReject(documentFormModel, { groups: ["createDocumentType"] });
|
await validateOrReject(documentFormModel, { groups: ["createDocumentType"] });
|
||||||
|
|
||||||
const documentTypeData: any = {
|
const documentTypeData: any = {
|
||||||
...values,
|
...values,
|
||||||
office: {
|
office: {
|
||||||
uid: officeId,
|
uid: officeId,
|
||||||
idNot: officeIdNot,
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
LoaderService.getInstance().show();
|
LoaderService.getInstance().show();
|
||||||
try {
|
DocumentTypeService.createDocumentType(documentTypeData, DEFAULT_VALIDATOR_ID).then((processCreated: any) => {
|
||||||
const processCreated = await DocumentTypeService.createDocumentType(documentTypeData, DEFAULT_VALIDATOR_ID);
|
|
||||||
ToasterService.getInstance().success({
|
ToasterService.getInstance().success({
|
||||||
title: "Succès !",
|
title: "Succès !",
|
||||||
description: "Type de document créé avec succès"
|
description: "Type de document créé avec succès"
|
||||||
});
|
});
|
||||||
const documentTypeUid = processCreated.processId.split(':')[0];
|
|
||||||
if (!documentTypeUid) {
|
|
||||||
console.error("DocumentTypesCreate: documentTypeUid is undefined - processCreated.processId is missing");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
router.push(
|
router.push(
|
||||||
Module.getInstance()
|
Module.getInstance()
|
||||||
.get()
|
.get()
|
||||||
.modules.pages.DocumentTypes.pages.DocumentTypesInformations.props.path.replace("[uid]", documentTypeUid),
|
.modules.pages.DocumentTypes.pages.DocumentTypesInformations.props.path.replace("[uid]", processCreated.processData.uid),
|
||||||
);
|
);
|
||||||
} catch (apiError) {
|
|
||||||
ToasterService.getInstance().error({
|
|
||||||
title: "Erreur !",
|
|
||||||
description: "Une erreur est survenue lors de la création du type de document"
|
|
||||||
});
|
|
||||||
console.error("Document type creation error:", apiError);
|
|
||||||
} finally {
|
|
||||||
LoaderService.getInstance().hide();
|
LoaderService.getInstance().hide();
|
||||||
}
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof Array) {
|
if (e instanceof Array) {
|
||||||
setValidationError(e);
|
setValidationError(e);
|
||||||
}
|
}
|
||||||
LoaderService.getInstance().hide();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[router],
|
[router],
|
||||||
@ -120,7 +90,7 @@ export default function DocumentTypesCreate(props: IProps) {
|
|||||||
validationError={validationError.find((error) => error.property === "public_description")}
|
validationError={validationError.find((error) => error.property === "public_description")}
|
||||||
/>
|
/>
|
||||||
<div className={classes["buttons-container"]}>
|
<div className={classes["buttons-container"]}>
|
||||||
<Button variant={EButtonVariant.PRIMARY} styletype={EButtonstyletype.OUTLINED} onClick={handleCancel}>
|
<Button variant={EButtonVariant.PRIMARY} styletype={EButtonstyletype.OUTLINED}>
|
||||||
Annuler
|
Annuler
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="submit">Créer le document</Button>
|
<Button type="submit">Créer le document</Button>
|
||||||
|
@ -26,12 +26,9 @@ export default function DocumentTypesEdit() {
|
|||||||
async function getDocumentType() {
|
async function getDocumentType() {
|
||||||
if (!documentTypeUid) return;
|
if (!documentTypeUid) return;
|
||||||
LoaderService.getInstance().show();
|
LoaderService.getInstance().show();
|
||||||
DocumentTypeService.getDocumentTypeByProcessId(documentTypeUid as string).then((process: any) => {
|
DocumentTypeService.getDocumentTypeByUid(documentTypeUid as string).then((process: any) => {
|
||||||
if (process) {
|
if (process) {
|
||||||
const documentType: any = {
|
const documentType: any = process.processData;
|
||||||
...process.processData,
|
|
||||||
processId: process.processId
|
|
||||||
};
|
|
||||||
setDocumentTypeSelected(documentType);
|
setDocumentTypeSelected(documentType);
|
||||||
}
|
}
|
||||||
LoaderService.getInstance().hide();
|
LoaderService.getInstance().hide();
|
||||||
@ -56,7 +53,7 @@ export default function DocumentTypesEdit() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LoaderService.getInstance().show();
|
LoaderService.getInstance().show();
|
||||||
DocumentTypeService.getDocumentTypeByProcessId(documentTypeUid as string).then((process: any) => {
|
DocumentTypeService.getDocumentTypeByUid(documentTypeUid as string).then((process: any) => {
|
||||||
if (process) {
|
if (process) {
|
||||||
DocumentTypeService.updateDocumentType(process, values).then(() => {
|
DocumentTypeService.updateDocumentType(process, values).then(() => {
|
||||||
router.push(
|
router.push(
|
||||||
|
@ -22,23 +22,13 @@ export default function DocumentTypesInformations() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function getDocument() {
|
async function getDocument() {
|
||||||
if (!documentTypeUid) {
|
if (!documentTypeUid) return;
|
||||||
console.log('DocumentTypesInformations: documentTypeUid is not available yet');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DocumentTypeService.getDocumentTypeByProcessId(documentTypeUid as string).then((process: any) => {
|
DocumentTypeService.getDocumentTypeByUid(documentTypeUid as string).then((process: any) => {
|
||||||
if (process) {
|
if (process) {
|
||||||
const document: any = {
|
const document: any = process.processData;
|
||||||
...process.processData,
|
|
||||||
processId: process.processId
|
|
||||||
};
|
|
||||||
setDocumentSelected(document);
|
setDocumentSelected(document);
|
||||||
} else {
|
|
||||||
console.log('DocumentTypesInformations: No process found for processId:', documentTypeUid);
|
|
||||||
}
|
}
|
||||||
}).catch((error) => {
|
|
||||||
console.error('DocumentTypesInformations: Error fetching document:', error);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,15 +69,13 @@ export default function DocumentTypesInformations() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className={classes["right"]}>
|
<div className={classes["right"]}>
|
||||||
{(documentSelected as any)?.processId && (
|
<Link
|
||||||
<Link
|
href={Module.getInstance()
|
||||||
href={Module.getInstance()
|
.get()
|
||||||
.get()
|
.modules.pages.DocumentTypes.pages.Edit.props.path.replace("[uid]", documentSelected?.uid ?? "")}
|
||||||
.modules.pages.DocumentTypes.pages.Edit.props.path.replace("[uid]", (documentSelected as any).processId)}
|
className={classes["edit-icon-container"]}>
|
||||||
className={classes["edit-icon-container"]}>
|
<Image src={PenICon} alt="edit informations" />
|
||||||
<Image src={PenICon} alt="edit informations" />
|
</Link>
|
||||||
</Link>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -51,7 +51,7 @@ export default function StepEmail(props: IProps) {
|
|||||||
);
|
);
|
||||||
*/
|
*/
|
||||||
router.push(
|
router.push(
|
||||||
`https://qual-connexion.idnot.fr/user/IdPOAuth2/authorize/idnot_idp_v1?client_id=B3CE56353EDB15A9&redirect_uri=http://127.0.0.1:3000/authorized-client&scope=openid,profile&response_type=code`,
|
`https://qual-connexion.idnot.fr/user/IdPOAuth2/authorize/idnot_idp_v1?client_id=B3CE56353EDB15A9&redirect_uri=http://local.lecoffreio.4nkweb:3000/authorized-client&scope=openid,profile&response_type=code`,
|
||||||
);
|
);
|
||||||
}, [router]);
|
}, [router]);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user