@fonderie/customers 6.1.4 → 6.1.6
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/dist/index.cjs +24 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +24 -5
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1042,11 +1042,23 @@ var CustomerLabelModel = class {
|
|
|
1042
1042
|
[type]
|
|
1043
1043
|
);
|
|
1044
1044
|
}
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1045
|
+
/**
|
|
1046
|
+
* Returns false when the label is still referenced. Labels are a SHARED
|
|
1047
|
+
* table (no workspace column), so an unconditional delete would let one
|
|
1048
|
+
* tenant destroy a label other tenants' emails/phones/addresses point at.
|
|
1049
|
+
* Until labels are workspace-scoped, only an unreferenced label may go.
|
|
1050
|
+
*/
|
|
1051
|
+
async remove(id) {
|
|
1052
|
+
const rows = await this.store.query(
|
|
1053
|
+
`DELETE FROM fonderie_customer_labels l
|
|
1054
|
+
WHERE l.id = $1
|
|
1055
|
+
AND NOT EXISTS (SELECT 1 FROM fonderie_customer_emails WHERE label_id = l.id)
|
|
1056
|
+
AND NOT EXISTS (SELECT 1 FROM fonderie_customer_phones WHERE label_id = l.id)
|
|
1057
|
+
AND NOT EXISTS (SELECT 1 FROM fonderie_customer_addresses WHERE label_id = l.id)
|
|
1058
|
+
RETURNING l.id`,
|
|
1048
1059
|
[id]
|
|
1049
|
-
)
|
|
1060
|
+
);
|
|
1061
|
+
return rows.length > 0;
|
|
1050
1062
|
}
|
|
1051
1063
|
async findOrCreate(type, raw) {
|
|
1052
1064
|
const value = raw.trim().toLowerCase();
|
|
@@ -2159,7 +2171,14 @@ function customerLabelController(store) {
|
|
|
2159
2171
|
if (!isUuid(labelId)) {
|
|
2160
2172
|
return setApiResponse7(HTTP7.UNPROCESSABLE, "INVALID_PARAMETER", "labelId must be a valid UUID");
|
|
2161
2173
|
}
|
|
2162
|
-
await labels.remove(labelId);
|
|
2174
|
+
const removed = await labels.remove(labelId);
|
|
2175
|
+
if (!removed) {
|
|
2176
|
+
return setApiResponse7(
|
|
2177
|
+
HTTP7.CONFLICT,
|
|
2178
|
+
"LABEL_IN_USE",
|
|
2179
|
+
"Label is still referenced by customer records and cannot be deleted."
|
|
2180
|
+
);
|
|
2181
|
+
}
|
|
2163
2182
|
return setApiResponse7(HTTP7.OK, "LABEL_DELETED", "Label deleted successfully.");
|
|
2164
2183
|
}
|
|
2165
2184
|
};
|