Skip to content

Conversation

@scheidtdav
Copy link
Collaborator

Type of Change

  • Dependency upgrade
  • Bug fix (non-breaking change)
  • Breaking change
    • e.g. a fixed bug or new feature that may break something else
  • New feature
  • Code quality improvements
    • e.g. refactoring, documentation, tests, tooling, ...

Implementation

Implementation of existing endpoint

Checklist

  • I gave this pull request a meaningful title
  • My pull request is targeting the dev branch
  • I have added documentation to my code
  • I have deleted code that I have commented out

Additional Information

scheidtdav and others added 30 commits May 14, 2025 16:26
* feat(api): add api routes for /users/me

* fix(tests): api me PUT

* feat(api): add delete me endpoint
@scheidtdav scheidtdav linked an issue Nov 19, 2025 that may be closed by this pull request
@scheidtdav scheidtdav marked this pull request as ready for review January 13, 2026 10:12
): Promise<z.infer<typeof DeleteQueryParams>> => {
const url = new URL(request.url)
let params: Record<string, any>
if (request.method !== 'GET') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ì think this endpoint should only support the delete method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember why its there and you are perfectly correct.. removing it!

try {
params = await request.json()
} catch {
params = Object.fromEntries(url.searchParams)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in principle it is a good idea to fall back to params, but i am a bit unsure if we should do this here with regards to backwards-compatibility. In the old docs the endpoint is described as using the request body, so i guess this would introduce a new behaviour? Also if the content type is invalid (so != application/json) the old app would have thrown a 415 if i see it correctly

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying it with the existing API, even though the docs specify it to work with body parameters, I actually does not seem to work with those at all.
Thus I better remove the request.json() part, right?

(funnily enough, you have to set content-type: application/json for it to work even though you never send json data. Definitely an inconsistency. The question is if we should loosen that or keep it for now?)

const userDevices = await getUserDevices(jwtResponse.id)
if (!userDevices.some((d) => d.id === deviceId))
return StandardResponse.forbidden(
'You are not allowed to delete data of the given device',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlikely to break anything, but the message in the old api was User does not own this senseBox (mentioning this because in the old app there was also a test for this: ```expect(response).to.have.json({ code: 'Forbidden', message: 'User does not own this senseBox' });

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes good point, I'm thinking we should still changes this, because we should get rid of the strict "senseBox" branding and use the more generic "device" term. As you said its unlikely to break anything, so I guess we can keep the message?

)

const device = userDevices.find((d) => d.id === deviceId)
if (!device?.sensors.some((s) => s.id === sensorId))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the old app would have thrown a 404 here (see Box.js l. 387)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried with the existing api and it indeed returns 404. Thanks for pointing out!

},
]

describe('openSenseMap API Routes: /boxes/:deviceId/:sensorId/measurement', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to add a test for the case when the user does not own the device (see the test "should deny to delete sensordata of boxes not owned by the user" in the old app)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

migrate /boxes/:boxId/:sensorId/measurements

4 participants