@specverse/engines 4.1.17 → 4.1.18
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.
|
@@ -148,18 +148,13 @@ function generateCreateMethod(model, modelName, modelVar, prismaDelegate, contro
|
|
|
148
148
|
function generateRetrieveMethod(model, modelName, modelVar, prismaDelegate) {
|
|
149
149
|
return `
|
|
150
150
|
/**
|
|
151
|
-
* Retrieve ${modelName} by ID
|
|
151
|
+
* Retrieve ${modelName} by ID. Returns null when not found so the
|
|
152
|
+
* route handler can translate that into HTTP 404 instead of 500.
|
|
152
153
|
*/
|
|
153
|
-
public async retrieve(id: string): Promise<any> {
|
|
154
|
-
|
|
154
|
+
public async retrieve(id: string): Promise<any | null> {
|
|
155
|
+
return await ${prismaDelegate}.findUnique({
|
|
155
156
|
where: { id: parseId(id) }${generateIncludeRelationships(model)}
|
|
156
157
|
});
|
|
157
|
-
|
|
158
|
-
if (!${modelVar}) {
|
|
159
|
-
throw new Error('${modelName} not found');
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return ${modelVar};
|
|
163
158
|
}
|
|
164
159
|
|
|
165
160
|
/**
|
|
@@ -204,18 +204,13 @@ function generateCreateMethod(model: any, modelName: string, modelVar: string, p
|
|
|
204
204
|
function generateRetrieveMethod(model: any, modelName: string, modelVar: string, prismaDelegate: string): string {
|
|
205
205
|
return `
|
|
206
206
|
/**
|
|
207
|
-
* Retrieve ${modelName} by ID
|
|
207
|
+
* Retrieve ${modelName} by ID. Returns null when not found so the
|
|
208
|
+
* route handler can translate that into HTTP 404 instead of 500.
|
|
208
209
|
*/
|
|
209
|
-
public async retrieve(id: string): Promise<any> {
|
|
210
|
-
|
|
210
|
+
public async retrieve(id: string): Promise<any | null> {
|
|
211
|
+
return await ${prismaDelegate}.findUnique({
|
|
211
212
|
where: { id: parseId(id) }${generateIncludeRelationships(model)}
|
|
212
213
|
});
|
|
213
|
-
|
|
214
|
-
if (!${modelVar}) {
|
|
215
|
-
throw new Error('${modelName} not found');
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return ${modelVar};
|
|
219
214
|
}
|
|
220
215
|
|
|
221
216
|
/**
|