@nestledjs/api 0.1.7 → 0.1.8

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestledjs/api",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "generators": "./generators.json",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -125,16 +125,21 @@ function generateRelationHandling(model, operation) {
125
125
  // Generate the improved iteration logic
126
126
  code += ' for (const [relationName, config] of Object.entries(relationMappings)) {\n';
127
127
  code += ' if (config.ids !== undefined && config.ids !== null) {\n';
128
- code += ' // Virtual list relationships use set for updates, connect for creates\n';
129
- code += ' // All other relationships always use connect\n';
130
- code += ' const useSet = config.isVirtual && config.isList && operation === \'update\';\n';
131
- code += ' const relationOperation = useSet ? \'set\' : \'connect\';\n';
132
128
  code += ' const ids = Array.isArray(config.ids) ? config.ids.map(id => ({ id })) : [{ id: config.ids }];\n';
133
129
  code += ' \n';
134
- code += ' if (config.isList || useSet) {\n';
130
+ code += ' if (config.isList) {\n';
131
+
132
+ if (operation === 'update') {
133
+ code += ' // List relationships: use set for updates on virtual relations, connect for foreign key relations\n';
134
+ code += ' const relationOperation = config.isVirtual ? \'set\' : \'connect\';\n';
135
+ } else {
136
+ code += ' // List relationships: always use connect for creates\n';
137
+ code += ' const relationOperation = \'connect\';\n';
138
+ }
139
+
135
140
  code += ' data[relationName] = { [relationOperation]: ids };\n';
136
141
  code += ' } else {\n';
137
- code += ' // Single relationship - extract the single id\n';
142
+ code += ' // Single relationship - always use connect\n';
138
143
  code += ' data[relationName] = { connect: { id: config.ids } };\n';
139
144
  code += ' }\n';
140
145
  code += ' }\n';
@@ -170,8 +175,8 @@ export class ApiCrudDataAccessService {
170
175
  const count = await this.data['<%= model.modelPropertyName %>'].count({
171
176
  ...this.data.filter(input)
172
177
  });
173
- const take = input?.take || 10
174
- const skip = input?.skip || 0
178
+ const take = input?.take ?? 10
179
+ const skip = input?.skip ?? 0
175
180
  const page = Math.floor(skip / take)
176
181
  return {
177
182
  take,