UNPKG

dry-node

Version:

Initialiseur de structure Node Express typée et modulaire

19 lines (16 loc) 616 B
const DryParams = require("../../dry-core/dry-params/dry-params"); async function DryGenerateUniqueId(Model, id, count) { const newId = count ? `${id}-${count}` : id; const idExists = await Model.exists({ id: newId }); if (!idExists) { return newId; }else{ id = ""; for (let i = 0; i < DryParams.lengthId; i++) { id += DryParams.stringNumber.charAt(Math.floor(Math.random() * DryParams.stringNumber.length)); } id = prefix + id } return DryGenerateUniqueId(Model, id, count + 1); } module.exports = DryGenerateUniqueId;