Refactor ApiServerContext to streamline data fetching and improve query structure
Some checks failed
farmcontrol/farmcontrol-ui/pipeline/head There was a failure building this commit

- Simplified fetchTemplatePDF function by consolidating parameters into a single line for better readability.
- Updated userNotifier fetch queries to use nested object syntax for improved clarity and consistency in data retrieval.
- Enhanced overall code maintainability by reducing unnecessary line breaks and optimizing filter structures.
This commit is contained in:
Tom Butcher 2026-08-19 18:58:20 +01:00
parent 3b69be7584
commit c69c4cf3dd

View File

@ -1841,15 +1841,8 @@ const ApiServerProvider = ({ children }) => {
const fetchTemplatePDF = async (id, content, testObject, callback) => { const fetchTemplatePDF = async (id, content, testObject, callback) => {
logger.debug('Fetching pdf template...') logger.debug('Fetching pdf template...')
try { try {
const result = await fetchTemplateDownload( const result = await fetchTemplateDownload(id, content, testObject, 'pdf')
id, const payload = result.error ? result : { pdf: result.buffer || result }
content,
testObject,
'pdf'
)
const payload = result.error
? result
: { pdf: result.buffer || result }
if (typeof callback === 'function') { if (typeof callback === 'function') {
callback(payload) callback(payload)
} }
@ -2017,8 +2010,8 @@ const ApiServerProvider = ({ children }) => {
if (!userProfile?._id) return { data: [] } if (!userProfile?._id) return { data: [] }
const result = await fetchObjects('userNotifier', { const result = await fetchObjects('userNotifier', {
filter: { filter: {
user: userProfile._id, 'user._id': userProfile._id,
object: objectId, 'object._id': objectId,
objectType objectType
}, },
limit: 1 limit: 1
@ -2029,7 +2022,7 @@ const ApiServerProvider = ({ children }) => {
const fetchAllUserNotifiersForObject = async (objectId, objectType) => { const fetchAllUserNotifiersForObject = async (objectId, objectType) => {
const result = await fetchObjects('userNotifier', { const result = await fetchObjects('userNotifier', {
filter: { filter: {
object: objectId, 'object._id': objectId,
objectType objectType
}, },
limit: 100 limit: 100