prisma-mock 1.1.0-alpha.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/delegate.js +13 -0
- package/package.json +1 -1
package/lib/delegate.js
CHANGED
|
@@ -629,6 +629,19 @@ const createDelegate = ({ ref, prisma, datamodel = prisma.dmmf.datamodel, caseIn
|
|
|
629
629
|
return (0, fieldHelpers_1.getCamelCase)(model.name) === prop;
|
|
630
630
|
});
|
|
631
631
|
const d = nestedUpdate(args, true, null);
|
|
632
|
+
// Check compound @@unique constraint violations during creation
|
|
633
|
+
const compoundUniques = model.uniqueFields?.filter((uf) => uf.length > 1) || [];
|
|
634
|
+
for (const fields of compoundUniques) {
|
|
635
|
+
const hasAllValues = fields.every((f) => d[f] !== undefined && d[f] !== null);
|
|
636
|
+
if (hasAllValues) {
|
|
637
|
+
const whereKey = fields.join("_");
|
|
638
|
+
const whereClause = fields.reduce((acc, f) => ({ ...acc, [f]: d[f] }), {});
|
|
639
|
+
const existing = findOne({ where: { [whereKey]: whereClause } });
|
|
640
|
+
if (existing) {
|
|
641
|
+
(0, errors_1.throwKnownError)(prisma, `Unique constraint failed on the fields: (\`${fields.join("`, `")}\`)`, { code: "P2002", meta: { modelName: model.name, target: fields } });
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
632
645
|
ref.data = {
|
|
633
646
|
...ref.data,
|
|
634
647
|
[prop]: [...ref.data[prop] || [], d],
|