Skip to content

Commit 06b1bdf

Browse files
greatly improved apis data operations
1 parent df1ab80 commit 06b1bdf

2 files changed

Lines changed: 69 additions & 25 deletions

File tree

src/devices/devices.controller.ts

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
ApiInternalServerErrorResponse,
1717
ApiNotFoundResponse,
1818
ApiOkResponse,
19+
ApiOperation,
1920
ApiParam,
2021
ApiQuery,
2122
ApiSecurity,
@@ -115,6 +116,11 @@ export class DevicesController {
115116
@ApiParam({ name: 'dev_eui', description: 'Device dev_eui' })
116117
@ApiParam({ name: 'skip (0)', description: 'Number of records to skip for pagination', required: false })
117118
@ApiParam({ name: 'take (144)', description: 'Number of records to take for pagination', required: false })
119+
@ApiOperation({
120+
summary: 'Get the latest FULL data for a device (paginated)',
121+
description: `
122+
Returns the latest, data from the table record for a device paginated.`,
123+
})
118124
data(@Req() req, @Param('dev_eui') devEui: string) {
119125
if (!devEui?.trim()) {
120126
throw new BadRequestException('dev_eui is required');
@@ -127,30 +133,49 @@ export class DevicesController {
127133
@Get(':dev_eui/data-within-range')
128134
@UseGuards(JwtAuthGuard)
129135
@ApiParam({ name: 'dev_eui', description: 'Device dev_eui' })
130-
@ApiQuery({
131-
name: 'start',
132-
required: false,
133-
description: 'ISO 8601 date/time. Defaults to 24 hours before end/now.',
134-
schema: {
135-
type: 'string',
136-
format: 'date-time',
137-
default: new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(),
138-
},
139-
example: new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(),
140-
})
141-
@ApiQuery({
142-
name: 'end',
143-
required: false,
144-
description: 'ISO 8601 date/time. Defaults to now.',
145-
schema: {
146-
type: 'string',
147-
format: 'date-time',
148-
default: new Date().toISOString(),
149-
},
150-
example: new Date().toISOString(),
151-
})
152-
@ApiParam({ name: 'skip (0)', description: 'Number of records to skip for pagination', required: false })
153-
@ApiParam({ name: 'take (144)', description: 'Number of records to take for pagination', required: false })
136+
@ApiQuery({
137+
name: 'start',
138+
required: false,
139+
description: 'ISO 8601 date/time. Defaults to 24 hours before end/now.',
140+
schema: {
141+
type: 'string',
142+
format: 'date-time',
143+
default: new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(),
144+
},
145+
example: new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(),
146+
})
147+
@ApiQuery({
148+
name: 'end',
149+
required: false,
150+
description: 'ISO 8601 date/time. Defaults to now.',
151+
schema: {
152+
type: 'string',
153+
format: 'date-time',
154+
default: new Date().toISOString(),
155+
},
156+
example: new Date().toISOString(),
157+
})
158+
@ApiParam({
159+
name: 'skip (0)', description: 'Number of records to skip for pagination', schema: {
160+
type: 'number',
161+
format: 'int32',
162+
default: 0,
163+
}, required: false
164+
})
165+
@ApiParam({
166+
name: 'take (144)', description: 'Number of records to take for pagination', schema: {
167+
type: 'number',
168+
format: 'int32',
169+
default: 144,
170+
}, required: false
171+
})
172+
@ApiOperation({
173+
summary: 'Get device FULL data within a date/time range and paginated',
174+
description: `
175+
Returns paginated sensor full data for a device filtered to a specific date/time window.
176+
Within the time window, the skip/take will be applied to the filtered data for pagination. For example, if there are 100 records in the time window and skip=10 and take=20, records 11-30 will be returned.
177+
Defaults to the last 24 hours if no range is provided.`,
178+
})
154179
dataWithinRange(@Req() req, @Param('dev_eui') devEui: string) {
155180
if (!devEui?.trim()) {
156181
throw new BadRequestException('dev_eui is required');
@@ -165,6 +190,11 @@ export class DevicesController {
165190
@Get(':dev_eui/latest-data')
166191
@UseGuards(JwtAuthGuard)
167192
@ApiParam({ name: 'dev_eui', description: 'Device dev_eui' })
193+
@ApiOperation({
194+
summary: 'Get the 1 latest FULL data value for a device',
195+
description: `
196+
Returns the full latest data record for a device.`,
197+
})
168198
latestData(@Req() req, @Param('dev_eui') devEui: string) {
169199
if (!devEui?.trim()) {
170200
throw new BadRequestException('dev_eui is required');
@@ -175,6 +205,11 @@ export class DevicesController {
175205
@Get(':dev_eui/latest-primary-data')
176206
@UseGuards(JwtAuthGuard)
177207
@ApiParam({ name: 'dev_eui', description: 'Device dev_eui' })
208+
@ApiOperation({
209+
summary: 'Get the latest primary data for a device',
210+
description: `
211+
Returns the latest, 2 primary data values from the table record for a device.`,
212+
})
178213
latestPrimaryData(@Req() req, @Param('dev_eui') devEui: string) {
179214
if (!devEui?.trim()) {
180215
throw new BadRequestException('dev_eui is required');

static/cw-swagger.css

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,13 @@
3333
.dark-mode-toggle {
3434
position: absolute !important;
3535
right: 30px;
36-
}
36+
}
37+
38+
.opblock-summary-path-description-wrapper {
39+
display: flex !important;
40+
align-items: center !important;
41+
}
42+
43+
.opblock-summary-description {
44+
margin-left: auto !important;
45+
}

0 commit comments

Comments
 (0)