|
|
@@ -501,10 +501,10 @@ export const handleCreateItem: Middleware = ({ |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
await theResource.dataSource.initialize(); |
|
|
|
const newId = await theResource.newId(theResource.dataSource); |
|
|
|
const params = bodyDeserialized as Record<string, unknown>; |
|
|
|
params[theResource.idAttr] = newId; |
|
|
|
await theResource.dataSource.initialize(); |
|
|
|
const newObject = await theResource.dataSource.create(params); |
|
|
|
const theFormatted = theSerializerPair.serialize(newObject); |
|
|
|
res.writeHead(constants.HTTP_STATUS_OK, { |
|
|
@@ -622,16 +622,20 @@ export const handleEmplaceItem: Middleware = ({ |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
const newId = await theResource.newId(theResource.dataSource); |
|
|
|
const params = bodyDeserialized as Record<string, unknown>; |
|
|
|
params[theResource.idAttr] = newId; |
|
|
|
await theResource.dataSource.initialize(); |
|
|
|
const newObject = await theResource.dataSource.emplace(mainResourceId, params); |
|
|
|
const params = bodyDeserialized as Record<string, unknown>; |
|
|
|
const [newObject, isCreated] = await theResource.dataSource.emplace(mainResourceId, params); |
|
|
|
const theFormatted = theSerializerPair.serialize(newObject); |
|
|
|
res.writeHead(constants.HTTP_STATUS_OK, { |
|
|
|
'Content-Type': theMediaType, |
|
|
|
'Location': `${serverParams.baseUrl}/${theResource.routeName}/${newId}` |
|
|
|
}); |
|
|
|
if (isCreated) { |
|
|
|
res.writeHead(constants.HTTP_STATUS_CREATED, { |
|
|
|
'Content-Type': theMediaType, |
|
|
|
'Location': `${serverParams.baseUrl}/${theResource.routeName}/${mainResourceId}` |
|
|
|
}); |
|
|
|
} else { |
|
|
|
res.writeHead(constants.HTTP_STATUS_OK, { |
|
|
|
'Content-Type': theMediaType, |
|
|
|
}); |
|
|
|
} |
|
|
|
res.end(theFormatted); |
|
|
|
} catch { |
|
|
|
res.statusCode = constants.HTTP_STATUS_INTERNAL_SERVER_ERROR; |
|
|
|