From fb64c3c9b51f3834406a7d2c77ce45cbd536abb2 Mon Sep 17 00:00:00 2001 From: Nicolas KREMER Date: Thu, 12 Dec 2024 16:17:48 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20mise=20=C3=A0=20jour=20de=20l'ID=20uniqu?= =?UTF-8?q?e=20ERP=20en=20format=20slug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/common/actions/erp.actions.ts | 5 ++++- server/src/common/utils/stringUtils.ts | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 server/src/common/utils/stringUtils.ts diff --git a/server/src/common/actions/erp.actions.ts b/server/src/common/actions/erp.actions.ts index 20beadb14..596d0c5ad 100644 --- a/server/src/common/actions/erp.actions.ts +++ b/server/src/common/actions/erp.actions.ts @@ -2,14 +2,17 @@ import Boom from "boom"; import { ObjectId } from "mongodb"; import { erpDb } from "../model/collections"; +import { slugify } from "../utils/stringUtils"; export const createERP = async (name: string) => { + const uniqueId = slugify(name); + return erpDb().insertOne({ _id: new ObjectId(), name, created_at: new Date(), apiV3: true, - unique_id: name.toLowerCase(), + unique_id: uniqueId, }); }; diff --git a/server/src/common/utils/stringUtils.ts b/server/src/common/utils/stringUtils.ts new file mode 100644 index 000000000..26a96634b --- /dev/null +++ b/server/src/common/utils/stringUtils.ts @@ -0,0 +1,8 @@ +export const slugify = (text: string): string => { + return text + .toString() + .toLowerCase() + .trim() + .replace(/[\s_]+/g, "-") + .replace(/[^\w-]+/g, ""); +};