json-server
json-server copied to clipboard
Intercepted PUT request and subsequent sorting
I'm mocking our production server which for some legacy reasons are using a PUT request rather than a POST when creating a specific new piece of data.
I am intercepting that PUT request and changing the req.method to a POST and providing a mocked req.body. The data is being stored to the in memory database and can be sorted on some fields but for some reason is not being sorted on the updated_on field or title field.
Here's what I have:
if (req.method === 'PUT' && req.originalUrl === '/v2/messages/announcements/') {
req.method = 'POST';
req.body = {
id: 101,
title: 'ZZ New Message',
content: 'ZZ New Message Sentence',
created_on: new Date().toISOString(),
updated_on: new Date().toISOString(),
};
}
next();
});```
I can sort by `content` and `id` not `created_on` or `updated_on`.