rez_core 2.1.70 → 2.1.71
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/package.json
CHANGED
|
@@ -61,54 +61,93 @@ export class ListMasterItemService {
|
|
|
61
61
|
): Promise<any> {
|
|
62
62
|
const orgId = loggedInUser.organization_id;
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
const errors: any[] = [];
|
|
65
|
+
|
|
66
|
+
for (let i = 0; i < items.length; i++) {
|
|
67
|
+
const item = items[i];
|
|
65
68
|
const name = item.name?.trim();
|
|
66
69
|
const code = item.code?.trim();
|
|
67
70
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
let existingItem;
|
|
71
|
+
try {
|
|
72
|
+
if (!name) {
|
|
73
|
+
throw new BadRequestException(`name is missing at index ${i}`);
|
|
74
|
+
}
|
|
73
75
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
if (code) {
|
|
77
|
+
// Check if code exists
|
|
78
|
+
const existingItem = await this.listItemsRepo.findOneByCondition({
|
|
79
|
+
code,
|
|
80
|
+
listtype: listType,
|
|
81
|
+
organization_id: orgId,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
if (existingItem) {
|
|
85
|
+
// It's an update — check if name is changing to a used name
|
|
86
|
+
if (existingItem.name.toLowerCase() !== name.toLowerCase()) {
|
|
87
|
+
const nameExists = await this.listItemsRepo.findOneByCondition({
|
|
88
|
+
name,
|
|
89
|
+
listtype: listType,
|
|
90
|
+
organization_id: orgId,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
if (nameExists && nameExists.id !== existingItem.id) {
|
|
94
|
+
throw new BadRequestException(
|
|
95
|
+
`${name} already used by another item`,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Update the existing item
|
|
101
|
+
await this.updateEntity(
|
|
102
|
+
{
|
|
103
|
+
...existingItem,
|
|
104
|
+
...item,
|
|
105
|
+
name,
|
|
106
|
+
listtype: listType,
|
|
107
|
+
},
|
|
108
|
+
loggedInUser,
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Creation path
|
|
116
|
+
const nameExists = await this.listItemsRepo.findOneByCondition({
|
|
78
117
|
name,
|
|
79
118
|
listtype: listType,
|
|
80
119
|
organization_id: orgId,
|
|
81
120
|
});
|
|
82
|
-
}
|
|
83
121
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
122
|
+
if (nameExists) {
|
|
123
|
+
throw new BadRequestException(
|
|
124
|
+
`list item with name ${name} already exists`,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const finalCode = code || ''; // Could generate code here if needed
|
|
92
129
|
|
|
93
|
-
if (existingItem) {
|
|
94
|
-
await this.updateEntity(
|
|
95
|
-
{
|
|
96
|
-
...existingItem,
|
|
97
|
-
...item,
|
|
98
|
-
listtype: listType,
|
|
99
|
-
},
|
|
100
|
-
loggedInUser,
|
|
101
|
-
);
|
|
102
|
-
} else {
|
|
103
130
|
await this.createEntity(
|
|
104
131
|
{
|
|
105
132
|
...item,
|
|
106
|
-
listtype: listType,
|
|
107
133
|
name,
|
|
134
|
+
code: finalCode,
|
|
135
|
+
listtype: listType,
|
|
108
136
|
value: '',
|
|
109
137
|
},
|
|
110
138
|
loggedInUser,
|
|
111
139
|
);
|
|
140
|
+
} catch (error) {
|
|
141
|
+
errors.push({
|
|
142
|
+
row: i,
|
|
143
|
+
error: [
|
|
144
|
+
{
|
|
145
|
+
field: 'name',
|
|
146
|
+
message:
|
|
147
|
+
error.message || 'An error occurred while processing the item',
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
});
|
|
112
151
|
}
|
|
113
152
|
}
|
|
114
153
|
|
|
@@ -119,7 +158,9 @@ export class ListMasterItemService {
|
|
|
119
158
|
);
|
|
120
159
|
|
|
121
160
|
return {
|
|
161
|
+
success: errors.length === 0,
|
|
122
162
|
listType,
|
|
163
|
+
errors,
|
|
123
164
|
items: updatedItems,
|
|
124
165
|
};
|
|
125
166
|
}
|