Improve data import
All checks were successful
Build and Push to Registry / build-and-push (push) Successful in 4m27s

This commit is contained in:
Sosthene 2025-08-22 11:51:59 +02:00
parent f87f7f747d
commit b6b0522b59
7 changed files with 153 additions and 189 deletions

View File

@ -20,6 +20,7 @@ const nextConfig = {
NEXT_PUBLIC_HOTJAR_SITE_ID: process.env.NEXT_PUBLIC_HOTJAR_SITE_ID, NEXT_PUBLIC_HOTJAR_SITE_ID: process.env.NEXT_PUBLIC_HOTJAR_SITE_ID,
NEXT_PUBLIC_HOTJAR_VERSION: process.env.NEXT_PUBLIC_HOTJAR_VERSION, NEXT_PUBLIC_HOTJAR_VERSION: process.env.NEXT_PUBLIC_HOTJAR_VERSION,
NEXT_PUBLIC_4NK_URL: process.env.NEXT_PUBLIC_4NK_URL, NEXT_PUBLIC_4NK_URL: process.env.NEXT_PUBLIC_4NK_URL,
NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL,
}, },
serverRuntimeConfig: { serverRuntimeConfig: {
@ -36,6 +37,7 @@ const nextConfig = {
NEXT_PUBLIC_HOTJAR_SITE_ID: process.env.NEXT_PUBLIC_HOTJAR_SITE_ID, NEXT_PUBLIC_HOTJAR_SITE_ID: process.env.NEXT_PUBLIC_HOTJAR_SITE_ID,
NEXT_PUBLIC_HOTJAR_VERSION: process.env.NEXT_PUBLIC_HOTJAR_VERSION, NEXT_PUBLIC_HOTJAR_VERSION: process.env.NEXT_PUBLIC_HOTJAR_VERSION,
NEXT_PUBLIC_4NK_URL: process.env.NEXT_PUBLIC_4NK_URL, NEXT_PUBLIC_4NK_URL: process.env.NEXT_PUBLIC_4NK_URL,
NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL,
}, },
env: { env: {
@ -52,6 +54,7 @@ const nextConfig = {
NEXT_PUBLIC_HOTJAR_SITE_ID: process.env.NEXT_PUBLIC_HOTJAR_SITE_ID, NEXT_PUBLIC_HOTJAR_SITE_ID: process.env.NEXT_PUBLIC_HOTJAR_SITE_ID,
NEXT_PUBLIC_HOTJAR_VERSION: process.env.NEXT_PUBLIC_HOTJAR_VERSION, NEXT_PUBLIC_HOTJAR_VERSION: process.env.NEXT_PUBLIC_HOTJAR_VERSION,
NEXT_PUBLIC_4NK_URL: process.env.NEXT_PUBLIC_4NK_URL, NEXT_PUBLIC_4NK_URL: process.env.NEXT_PUBLIC_4NK_URL,
NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL,
}, },
// webpack: config => { // webpack: config => {

View File

@ -0,0 +1,52 @@
import getConfig from 'next/config';
const { publicRuntimeConfig } = getConfig();
export default class DatabaseService {
// Empêcher l'instanciation de cette classe utilitaire
private constructor() { }
/**
* Récupère les données d'une table avec pagination
* @param tableName Nom de la table à consulter
* @param page Numéro de page (commence à 1)
* @param limit Nombre d'éléments par page
* @returns Données de la table avec pagination
*/
public static async getTableData(tableName: string, page: number = 1, limit: number = 10): Promise<any> {
// Vérification des paramètres
if (!tableName) {
throw new Error('Le nom de la table est requis');
}
// Validation du nom de la table (par sécurité)
const tableNameRegex = /^[a-zA-Z0-9_]+$/;
if (!tableNameRegex.test(tableName)) {
throw new Error('Nom de table invalide');
}
try {
// Construction de l'URL avec paramètres de pagination
const url = `${publicRuntimeConfig.NEXT_PUBLIC_API_URL}/db/${tableName}?page=${page}&limit=${limit}`;
// Appel à l'API REST
const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.message || 'Erreur lors de la récupération des données');
}
const data = await response.json();
return data;
} catch (error) {
console.error('Erreur lors de l\'accès à la base de données:', error);
throw error;
}
}
}

View File

@ -177,8 +177,6 @@ export default class DeedTypeService extends AbstractService {
} }
public static updateDeedType(process: any, newData: any): Promise<void> { public static updateDeedType(process: any, newData: any): Promise<void> {
console.log(process);
return new Promise<void>((resolve: () => void) => { return new Promise<void>((resolve: () => void) => {
this.messageBus.updateProcess(process.processId, { updated_at: new Date().toISOString(), ...newData }, [], null).then((processUpdated: any) => { this.messageBus.updateProcess(process.processId, { updated_at: new Date().toISOString(), ...newData }, [], null).then((processUpdated: any) => {
const newStateId: string = processUpdated.diffs[0]?.state_id; const newStateId: string = processUpdated.diffs[0]?.state_id;

View File

@ -3,6 +3,7 @@ import { v4 as uuidv4 } from 'uuid';
import User from 'src/sdk/User'; import User from 'src/sdk/User';
import MessageBus from 'src/sdk/MessageBus'; import MessageBus from 'src/sdk/MessageBus';
import DatabaseService from './DatabaseService';
import RuleService from './RuleService'; import RuleService from './RuleService';
import RuleGroupService from './RuleGroupService'; import RuleGroupService from './RuleGroupService';
import RoleService from './RoleService'; import RoleService from './RoleService';
@ -36,8 +37,8 @@ export default class ImportData {
}, },
{ {
name: 'Groupes de règles', name: 'Groupes de règles',
function: async (progressCallback?: (subProgress: number, description?: string) => void, prevResults?: any[]) => function: async (progressCallback?: (subProgress: number, description?: string) => void) =>
await this.importRuleGroups(prevResults![0], progressCallback) await this.importRuleGroups(progressCallback)
}, },
{ {
name: 'Rôles', name: 'Rôles',
@ -171,190 +172,109 @@ export default class ImportData {
} }
private static async importRules(onProgress?: (progress: number, description?: string) => void): Promise<any[]> { private static async importRules(onProgress?: (progress: number, description?: string) => void): Promise<any[]> {
// Constantes de progression - pourraient être paramétrées const rules: any[] = [];
const INIT_PROGRESS = 0; const INIT_PROGRESS = 0;
const FETCH_PROGRESS = 30; const FETCH_PROGRESS = 30;
const CREATE_START_PROGRESS = FETCH_PROGRESS;
const CREATE_END_PROGRESS = 90; const CREATE_END_PROGRESS = 90;
const FINAL_PROGRESS = 100; const FINAL_PROGRESS = 100;
onProgress?.(INIT_PROGRESS, 'Initialisation'); onProgress?.(INIT_PROGRESS, 'Initialisation');
return await new Promise<any[]>((resolve: (rules: any[]) => void) => {
const defaultRules: any[] = [
// Actes et documents
{
name: "POST deeds",
label: "Créer un template de type d'acte",
namespace: "collaborator"
},
{
name: "PUT deeds",
label: "Modifier un type d'acte",
namespace: "collaborator"
},
{
name: "DELETE deeds",
label: "Supprimer des types d'actes",
namespace: "collaborator"
},
{
name: "GET deed-types",
label: "Lecture des types d'actes",
namespace: "collaborator"
},
{
name: "POST deed-types",
label: "Création des types d'actes",
namespace: "collaborator"
},
{
name: "PUT deed-types",
label: "Modification des types d'actes",
namespace: "collaborator"
},
{
name: "DELETE deed-types",
label: "Suppression des types d'actes",
namespace: "collaborator"
},
{
name: "GET document-types",
label: "Lecture des types de documents",
namespace: "collaborator"
},
{
name: "POST document-types",
label: "Création des types de documents",
namespace: "collaborator"
},
{
name: "PUT document-types",
label: "Modification des types de documents",
namespace: "collaborator"
},
{
name: "DELETE document-types",
label: "Suppression des types de documents",
namespace: "collaborator"
},
// RIB
{
name: "GET rib",
label: "Lire le RIB de l'office",
namespace: "collaborator"
},
{
name: "POST rib",
label: "Déposer le RIB de l'office",
namespace: "collaborator"
},
{
name: "PUT rib",
label: "Editer le RIB de l'office",
namespace: "collaborator"
},
{
name: "DELETE rib",
label: "Supprimer le RIB de l'office",
namespace: "collaborator"
},
// Abonnements
{
name: "GET subscriptions",
label: "Récupérer les abonnements",
namespace: "collaborator"
},
{
name: "POST subscriptions",
label: "Inviter un collaborateur à l'abonnement",
namespace: "collaborator"
},
{
name: "PUT subscriptions",
label: "Modifier l'abonnement",
namespace: "collaborator"
},
{
name: "GET stripe",
label: "Gérer l'abonnement de l'office",
namespace: "collaborator"
},
{
name: "POST stripe",
label: "Payer un abonnement",
namespace: "collaborator"
}
];
RuleService.getRules().then(async (processes: any[]) => {
onProgress?.(FETCH_PROGRESS, 'Récupération des règles existantes');
const rules: any[] = processes.map((process: any) => process.processData);
if (rules.length === 0) {
const totalRules = defaultRules.length;
for (let i = 0; i < totalRules; i++) {
const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0';
rules.push((await RuleService.createRule(defaultRules[i], validatorId)).processData);
// Progression dynamique pendant la création des règles let page = 1;
const progressRange = CREATE_END_PROGRESS - CREATE_START_PROGRESS; let limit = 10;
const progress = CREATE_START_PROGRESS + ((i + 1) / totalRules) * progressRange; let totalPages = 1;
onProgress?.(progress, `Création de la règle ${i + 1}/${totalRules} : ${defaultRules[i].label}`);
} onProgress?.(FETCH_PROGRESS, 'Récupération des règles existantes');
} let result = await DatabaseService.getTableData('rules', page, limit);
onProgress?.(FINAL_PROGRESS, 'Importation des règles terminée'); if (result && result.success && result.pagination) {
resolve(rules); totalPages = result.pagination.totalPages || 1;
}); }
});
const FETCH_PAGE_PROGRESS_START = FETCH_PROGRESS;
const FETCH_PAGE_PROGRESS_END = 60;
const CREATE_START_PROGRESS = 60;
while (result && result.success) {
const fetchPageProgress = FETCH_PAGE_PROGRESS_START + ((page / totalPages) * (FETCH_PAGE_PROGRESS_END - FETCH_PAGE_PROGRESS_START));
onProgress?.(fetchPageProgress, `Page ${page}/${totalPages} : Récupération des règles`);
const existingRules: any[] = (await RuleService.getRules()).map((process: any) => process.processData);
const filteredRules: any[] = result.data.filter((rule: any) => !existingRules.some((existingRule: any) => existingRule.uid === rule.uid));
const totalFilteredRules = filteredRules.length;
for (let i = 0; i < totalFilteredRules; i++) {
const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0';
rules.push((await RuleService.createRule(filteredRules[i], validatorId)).processData);
const progressRange = CREATE_END_PROGRESS - CREATE_START_PROGRESS;
const ruleProgressIncrement = progressRange / (totalFilteredRules * totalPages);
const progress = CREATE_START_PROGRESS + ((page - 1) * totalFilteredRules + i + 1) * ruleProgressIncrement;
onProgress?.(progress, `Page ${page}/${totalPages} : Création de la règle ${i + 1}/${totalFilteredRules} - ${filteredRules[i].label}`);
}
if (!result.pagination.hasNextPage) {
break;
}
page++;
result = await DatabaseService.getTableData('rules', page, limit);
}
onProgress?.(FINAL_PROGRESS, 'Importation des règles terminée');
return rules;
} }
private static async importRuleGroups(rules: any[], onProgress?: (progress: number, description?: string) => void): Promise<any[]> { private static async importRuleGroups(onProgress?: (progress: number, description?: string) => void): Promise<any[]> {
// Constantes de progression - pourraient être paramétrées const ruleGroups: any[] = [];
const INIT_PROGRESS = 0; const INIT_PROGRESS = 0;
const FETCH_PROGRESS = 30; const FETCH_PROGRESS = 30;
const CREATE_START_PROGRESS = FETCH_PROGRESS;
const CREATE_END_PROGRESS = 90; const CREATE_END_PROGRESS = 90;
const FINAL_PROGRESS = 100; const FINAL_PROGRESS = 100;
onProgress?.(INIT_PROGRESS, 'Initialisation'); onProgress?.(INIT_PROGRESS, 'Initialisation');
return await new Promise<any[]>((resolve: (ruleGroups: any[]) => void) => {
const defaultRuleGroups: any[] = [
{
name: "Gestion des matrices d'actes et des documents",
rules: rules
.filter((rule: any) => rule.name.includes("deeds") || rule.name.includes("deed-types") || rule.name.includes("document-types"))
.map((rule: any) => ({ uid: rule.uid }))
},
{
name: "Intégration du RIB",
rules: rules
.filter((rule: any) => rule.name.includes("rib"))
.map((rule: any) => ({ uid: rule.uid }))
},
{
name: "Gestion de l'abonnement",
rules: rules
.filter((rule: any) => rule.name.includes("subscriptions") || rule.name.includes("stripe"))
.map((rule: any) => ({ uid: rule.uid }))
}
];
RuleGroupService.getRuleGroups().then(async (processes: any[]) => {
onProgress?.(FETCH_PROGRESS, 'Récupération des groupes de règles existants');
const ruleGroups: any[] = processes.map((process: any) => process.processData);
if (ruleGroups.length === 0) {
const totalGroups = defaultRuleGroups.length;
for (let i = 0; i < totalGroups; i++) {
const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0';
ruleGroups.push((await RuleGroupService.createRuleGroup(defaultRuleGroups[i], validatorId)).processData);
// Progression dynamique pendant la création des groupes de règles let page = 1;
const progressRange = CREATE_END_PROGRESS - CREATE_START_PROGRESS; let limit = 10;
const progress = CREATE_START_PROGRESS + ((i + 1) / totalGroups) * progressRange; let totalPages = 1;
onProgress?.(progress, `Création du groupe de règles ${i + 1}/${totalGroups} : ${defaultRuleGroups[i].name}`);
} onProgress?.(FETCH_PROGRESS, 'Récupération des groupes de règles existants');
} let result = await DatabaseService.getTableData('rules_groups', page, limit);
onProgress?.(FINAL_PROGRESS, 'Importation des groupes de règles terminée'); if (result && result.success && result.pagination) {
resolve(ruleGroups); totalPages = result.pagination.totalPages || 1;
}); }
});
const FETCH_PAGE_PROGRESS_START = FETCH_PROGRESS;
const FETCH_PAGE_PROGRESS_END = 60;
const CREATE_START_PROGRESS = 60;
while (result && result.success) {
const fetchPageProgress = FETCH_PAGE_PROGRESS_START + ((page / totalPages) * (FETCH_PAGE_PROGRESS_END - FETCH_PAGE_PROGRESS_START));
onProgress?.(fetchPageProgress, `Page ${page}/${totalPages} : Récupération du groupe de règles`);
const existingRuleGroups: any[] = (await RuleGroupService.getRuleGroups()).map((process: any) => process.processData);
const filteredRuleGroups: any[] = result.data.filter((rule: any) => !existingRuleGroups.some((existingRule: any) => existingRule.uid === rule.uid));
const totalFilteredRuleGroups = filteredRuleGroups.length;
for (let i = 0; i < totalFilteredRuleGroups; i++) {
const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0';
ruleGroups.push((await RuleGroupService.createRuleGroup(filteredRuleGroups[i], validatorId)).processData);
const progressRange = CREATE_END_PROGRESS - CREATE_START_PROGRESS;
const ruleProgressIncrement = progressRange / (totalFilteredRuleGroups * totalPages);
const progress = CREATE_START_PROGRESS + ((page - 1) * totalFilteredRuleGroups + i + 1) * ruleProgressIncrement;
onProgress?.(progress, `Page ${page}/${totalPages} : Création du groupe de règles ${i + 1}/${totalFilteredRuleGroups} - ${filteredRuleGroups[i].label}`);
}
if (!result.pagination.hasNextPage) {
break;
}
page++;
result = await DatabaseService.getTableData('rules_groups', page, limit);
}
onProgress?.(FINAL_PROGRESS, 'Importation des groupes de règles terminée');
return ruleGroups;
} }
private static async importRoles(onProgress?: (progress: number, description?: string) => void): Promise<any[]> { private static async importRoles(onProgress?: (progress: number, description?: string) => void): Promise<any[]> {

View File

@ -30,12 +30,6 @@ export default function ClientBox(props: IProps) {
const { isOpen: isDeleteModalOpen, open: openDeleteModal, close: closeDeleteModal } = useOpenable(); const { isOpen: isDeleteModalOpen, open: openDeleteModal, close: closeDeleteModal } = useOpenable();
const { isOpen: isErrorModalOpen, open: openErrorModal, close: closeErrorModal } = useOpenable(); const { isOpen: isErrorModalOpen, open: openErrorModal, close: closeErrorModal } = useOpenable();
// TODO: review
const handleOpenConnectionLink = useCallback(() => {
const url = `http://localhost:3000/client-dashboard/${folderUid}/profile/${customer.uid}`;
alert(url);
}, [customer.uid, folderUid]);
const handleDelete = useCallback( const handleDelete = useCallback(
(customerUid: string) => { (customerUid: string) => {
LoaderService.getInstance().show(); LoaderService.getInstance().show();
@ -100,15 +94,6 @@ export default function ClientBox(props: IProps) {
</Menu> </Menu>
)} )}
</div> </div>
<div>
<Button
size={EButtonSize.SM}
variant={EButtonVariant.WARNING}
styletype={EButtonstyletype.TEXT}
onClick={handleOpenConnectionLink}>
Lien de connexion
</Button>
</div>
<div> <div>
<Typography typo={ETypo.TEXT_MD_REGULAR} color={ETypoColor.COLOR_NEUTRAL_700}> <Typography typo={ETypo.TEXT_MD_REGULAR} color={ETypoColor.COLOR_NEUTRAL_700}>
Numéro de téléphone Numéro de téléphone

View File

@ -31,6 +31,8 @@ export class FrontendVariables {
public _4NK_URL!: string; public _4NK_URL!: string;
public API_URL!: string;
private constructor() {} private constructor() {}
public static getInstance(): FrontendVariables { public static getInstance(): FrontendVariables {

View File

@ -36,6 +36,7 @@ type AppPropsWithLayout = AppProps & {
hotjarSiteId: number; hotjarSiteId: number;
hotjarVersion: number; hotjarVersion: number;
_4nkUrl: string; _4nkUrl: string;
apiUrl: string;
}; };
const { publicRuntimeConfig } = getConfig(); const { publicRuntimeConfig } = getConfig();
@ -57,6 +58,7 @@ const MyApp = (({
hotjarSiteId, hotjarSiteId,
hotjarVersion, hotjarVersion,
_4nkUrl, _4nkUrl,
apiUrl,
}: AppPropsWithLayout) => { }: AppPropsWithLayout) => {
const getLayout = Component.getLayout ?? ((page) => <DefaultLayout children={page}></DefaultLayout>); const getLayout = Component.getLayout ?? ((page) => <DefaultLayout children={page}></DefaultLayout>);
@ -75,6 +77,7 @@ const MyApp = (({
instance.HOTJAR_SITE_ID = hotjarSiteId; instance.HOTJAR_SITE_ID = hotjarSiteId;
instance.HOTJAR_VERSION = hotjarVersion; instance.HOTJAR_VERSION = hotjarVersion;
instance._4NK_URL = _4nkUrl; instance._4NK_URL = _4nkUrl;
instance.API_URL = apiUrl;
const [isConnected, setIsConnected] = useState(false); const [isConnected, setIsConnected] = useState(false);
const [isReady, setIsReady] = useState(false); const [isReady, setIsReady] = useState(false);
@ -139,6 +142,7 @@ MyApp.getInitialProps = async () => {
hotjarSiteId: publicRuntimeConfig.NEXT_PUBLIC_HOTJAR_SITE_ID, hotjarSiteId: publicRuntimeConfig.NEXT_PUBLIC_HOTJAR_SITE_ID,
hotjarVersion: publicRuntimeConfig.NEXT_PUBLIC_HOTJAR_VERSION, hotjarVersion: publicRuntimeConfig.NEXT_PUBLIC_HOTJAR_VERSION,
_4nkUrl: publicRuntimeConfig.NEXT_PUBLIC_4NK_URL, _4nkUrl: publicRuntimeConfig.NEXT_PUBLIC_4NK_URL,
apiUrl: publicRuntimeConfig.NEXT_PUBLIC_API_URL,
}; };
}; };