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, ""); +};