Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: list alerts (WIP) #41

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,50 @@ export default async function routes(
},
)

fastify.get(
'/projects/:projectPublicId/remoteDetectionAlerts',
{
schema: {
params: Type.Object({
projectPublicId: BASE32_STRING_32_BYTES,
}),
response: {
200: Type.Object({
data: Type.Array(schemas.remoteDetectionAlertResult),
}),
'4xx': schemas.errorResponse,
},
},
async preHandler(req) {
verifyBearerAuth(req)
await ensureProjectExists(this, req)
},
},
/**
* @this {FastifyInstance}
*/
async function (req) {
const { projectPublicId } = req.params
const project = await this.comapeo.getProject(projectPublicId)

return {
data: (
await project.remoteDetectionAlert.getMany({ includeDeleted: true })
).map((alert) => ({
docId: alert.docId,
createdAt: alert.createdAt,
updatedAt: alert.updatedAt,
deleted: alert.deleted,
detectionDateStart: alert.detectionDateStart,
detectionDateEnd: alert.detectionDateEnd,
sourceId: alert.sourceId,
metadata: alert.metadata,
geometry: alert.geometry,
})),
}
},
)

fastify.post(
'/projects/:projectPublicId/remoteDetectionAlerts',
{
Expand Down
14 changes: 13 additions & 1 deletion src/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const observationResult = Type.Object({
),
})

export const remoteDetectionAlertToAdd = Type.Object({
const remoteDetectionAlertCommon = {
detectionDateStart: dateTimeString,
detectionDateEnd: dateTimeString,
sourceId: Type.String({ minLength: 1 }),
Expand All @@ -72,4 +72,16 @@ export const remoteDetectionAlertToAdd = Type.Object({
type: Type.Literal('Point'),
coordinates: Type.Tuple([longitude, latitude]),
}),
}

export const remoteDetectionAlertToAdd = Type.Object({
...remoteDetectionAlertCommon,
})

export const remoteDetectionAlertResult = Type.Object({
docId: Type.String(),
createdAt: dateTimeString,
updatedAt: dateTimeString,
deleted: Type.Boolean(),
...remoteDetectionAlertCommon,
})
Loading