-
Notifications
You must be signed in to change notification settings - Fork 102
Lf 4765 create get endpoint to fetch list of i ps #3755
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
Merged
kathyavini
merged 63 commits into
integration
from
LF-4765-create-get-endpoint-to-fetch-list-of-i-ps
May 26, 2025
Merged
Changes from all commits
Commits
Show all changes
63 commits
Select commit
Hold shift + click to select a range
a959860
LF-4765 Add get prescriptions route to routes
Duncan-Brain 3b38070
LF-4765 Add get prescriptions wireframe to controller
Duncan-Brain 0f9e03e
LF-4765 WIP - add basic mock and get farmaddon function
Duncan-Brain 07c4a5b
LF-4765 send response for postman testing
Duncan-Brain 645fd4d
LF-4765 Add blocked model util
Duncan-Brain 549fd6c
LF-4765 update mocking function
Duncan-Brain 1ed1420
LF-4765 Was confused about which route I should use moved irrigation …
Duncan-Brain 8ca78c2
LF-4765 Add dayjs package
Duncan-Brain 89fa6b0
LF-4765 Add model function to return utc_offset
Duncan-Brain d489db1
LF-4765 Add new farm service and add farm specific date utils
Duncan-Brain 7149fa7
LF-4765 Add type guard and change syntax for task_id
Duncan-Brain c4ffe7d
LF-4765 Add ensemble call to service and remove and export mocked fun…
Duncan-Brain 72ac94d
LF-4765 Copy irrigation prescription request fromat for returning moc…
Duncan-Brain e6dbd57
LF-4765 Update task model with jsdoc, uncomment external id info now …
Duncan-Brain a44f01d
LF-4765 Export point type and update type guard to only test external…
Duncan-Brain 7f62c17
LF-4765 Finally stop cheating, just adding full types
Duncan-Brain 498fb9f
LF-4765 Add task id search to data formatting, refactor some types an…
Duncan-Brain 74671e1
LF-4765 Filter tasks by farm Id since org_id are not constrained to j…
Duncan-Brain e60d300
LF-4765 update scope check
Duncan-Brain 36bbde8
LF-4765 Fix data type in irrigation types
Duncan-Brain ce0a969
LF-4765 Add more types to type file
Duncan-Brain f82a34a
LF-4765 Update model function to return all tasks, update ensemble se…
Duncan-Brain f21d713
LF-4765 Add tests for get endpoint
Duncan-Brain d9c6532
LF-4765 Add after date to request query, remove farmDate utilities, a…
Duncan-Brain 335ba39
LF-4765 Add after date to tests
Duncan-Brain c62de99
LF-4765 Cleanup duplicated types
Duncan-Brain 1cb661d
LF-4765 Remove mistakenly added function
Duncan-Brain 76e4fbc
LF-4765 Farm date cleanup
Duncan-Brain 2e90e3a
LF-4765 Remove extra mocking function and move to tests, add todo for…
Duncan-Brain 867842f
LF-4765 improve/fix mock logic
Duncan-Brain 4860c06
LF-4765 Adjust frontend query to backend specs, move mocks to backend
Duncan-Brain 406ca29
LF-4765 Update date params for irrigation prescription endpoints
Duncan-Brain ed4a117
LF-4765 Add management plan type and dependencies
Duncan-Brain 43899c1
LF-4765 Add mamangement plan to expected return mock and type
Duncan-Brain f72a318
LF-4765 rename what was a temporary variable to a permanent one
Duncan-Brain 8e8c1f3
LF-4765 Update types file with farm addon and point
Duncan-Brain 3940875
LF-4765 Invalidate irrigation prescription query between logouts
Duncan-Brain 6aa5d17
LF-4765 Send empty array if no farm addons that provide irrigation pr…
Duncan-Brain 6edc866
LF-4765 Add frontend date utils to backend tests utils
Duncan-Brain cda8040
LF-4765 Fix tests to accomodate new values
Duncan-Brain e0dcf25
Merge branch 'integration' into LF-4765-create-get-endpoint-to-fetch-…
Duncan-Brain ff5aedf
LF-4765 Fix package lock
Duncan-Brain 7008086
LF-4765 Touch up comments and types
Duncan-Brain e00783b
LF-4765 Add query check middleware
Duncan-Brain 199247e
LF-4765 Update irrigation prescription types and type guard to use ne…
Duncan-Brain 7927a3a
LF-4765 Small fixes to update comments, error array and accessing rec…
Duncan-Brain e7a9115
LF-4765 Add comments to regex check for use when testing with postman
Duncan-Brain bf0310c
LF-4765 Update jsdoc
Duncan-Brain b461a6a
LF-4765 Refactor tests proper by creating facotries and mocking the e…
Duncan-Brain 7dae074
LF-4765 Make required query params in controller move type owner
Duncan-Brain 86cbd5c
LF-4765 Add query params to frontend
Duncan-Brain 66b0f86
LF-4765 Refactor mocking
Duncan-Brain 78d0cc3
LF-4765 undo type casting
Duncan-Brain 7207d69
LF-4765 Invalidate tags on task deletion and creation
Duncan-Brain 1e530ae
LF-4765 Plural url form
Duncan-Brain 4871eb3
LF-4765 Add addonPartner service
Duncan-Brain 39172f8
LF-4765 Move types and data formatting to service
Duncan-Brain 8d54eab
LF-4765 Move shouldSend boolean to only affect ESci
Duncan-Brain 3a6219f
LF-4765 rename mock
Duncan-Brain 6f14118
Merge branch 'integration' into LF-4765-create-get-endpoint-to-fetch-…
Duncan-Brain 009e46a
Merge branch 'integration' into LF-4765-create-get-endpoint-to-fetch-…
kathyavini 42b9df0
LF-4765 Wrong type for shouldSend
Duncan-Brain 8090cf4
Merge branch 'integration' into LF-4765-create-get-endpoint-to-fetch-…
Duncan-Brain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
packages/api/src/controllers/irrigationPrescriptionController.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Copyright 2025 LiteFarm.org | ||
| * This file is part of LiteFarm. | ||
| * | ||
| * LiteFarm is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * LiteFarm is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| import { Response } from 'express'; | ||
| import { LiteFarmRequest, HttpError } from '../types.js'; | ||
| import { IrrigationPrescriptionQueryParams } from '../middleware/validation/checkIrrigationPrescription.js'; | ||
| import { getAddonPartnerIrrigationPrescriptions } from '../services/addonPartner.js'; | ||
|
|
||
| const irrigationPrescriptionController = { | ||
| getPrescriptions() { | ||
| return async ( | ||
| req: LiteFarmRequest<Required<IrrigationPrescriptionQueryParams>>, | ||
| res: Response, | ||
| ) => { | ||
| try { | ||
| const { farm_id } = req.headers; | ||
| const { startTime, endTime, shouldSend } = req.query; | ||
|
|
||
| const irrigationPrescriptions = await getAddonPartnerIrrigationPrescriptions( | ||
| // @ts-expect-error - farm_id is guaranteed here by the checkScope middleware with single argument | ||
| farm_id, | ||
| startTime, | ||
| endTime, | ||
| shouldSend, | ||
| ); | ||
|
|
||
| return res.status(200).send(irrigationPrescriptions); | ||
| } catch (error: unknown) { | ||
| console.error(error); | ||
| const err = error as HttpError; | ||
| const status = err.status || err.code || 500; | ||
| return res.status(status).json({ | ||
| error: err.message || err, | ||
| }); | ||
| } | ||
| }; | ||
| }, | ||
| }; | ||
|
|
||
| export default irrigationPrescriptionController; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/api/src/middleware/validation/checkIrrigationPrescription.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Copyright (c) 2025 LiteFarm.org | ||
| * This file is part of LiteFarm. | ||
| * | ||
| * LiteFarm is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * LiteFarm is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| import { Request, Response, NextFunction } from 'express'; | ||
| import { isISO8601Format } from '../../util/validation.js'; | ||
|
|
||
| export interface IrrigationPrescriptionQueryParams { | ||
| startTime?: string; | ||
| endTime?: string; | ||
| shouldSend?: string; | ||
| } | ||
|
|
||
| export function checkGetIrrigationPrescription() { | ||
| return async ( | ||
| req: Request<unknown, unknown, unknown, IrrigationPrescriptionQueryParams>, | ||
| res: Response, | ||
| next: NextFunction, | ||
| ) => { | ||
| const { startTime, endTime, shouldSend } = req.query; | ||
|
|
||
| if (shouldSend != 'true' && shouldSend != 'false') { | ||
| return res.status(400).send('Please provide shouldSend as true or false'); | ||
| } | ||
|
|
||
| if (!startTime || !isISO8601Format(startTime)) { | ||
| return res.status(400).send('Please provide startTime in ISO 8601 format'); | ||
| } | ||
|
|
||
| if (!endTime || !isISO8601Format(endTime)) { | ||
| return res.status(400).send('Please provide endTime in ISO 8601 format'); | ||
| } | ||
|
|
||
| next(); | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ class IrrigationTypesModel extends BaseModel { | |
| type: 'object', | ||
| required: [''], | ||
| properties: { | ||
| irrigation_type_id: { type: 'string' }, | ||
| irrigation_type_id: { type: 'integer' }, | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error in model setup -- type is actually incrementing pk |
||
| irrigation_type_name: { type: 'string' }, | ||
| farm_id: { type: 'string' }, | ||
| default_measuring_type: { type: 'string' }, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.