Skip to content

Commit

Permalink
fix: mise à jour de l'ID unique ERP en format slug (#3938)
Browse files Browse the repository at this point in the history
  • Loading branch information
nkrmr authored Dec 17, 2024
1 parent 42f8e63 commit 778e87f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion server/src/common/actions/erp.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
};

Expand Down
8 changes: 8 additions & 0 deletions server/src/common/utils/stringUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const slugify = (text: string): string => {
return text
.toString()
.toLowerCase()
.trim()
.replace(/[\s_]+/g, "-")
.replace(/[^\w-]+/g, "");
};

0 comments on commit 778e87f

Please sign in to comment.