-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'hotfix-fixing-census-quadrat-relation' into forestgeo-a…
…pp-baobab
- Loading branch information
Showing
7 changed files
with
83 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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 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 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,45 @@ | ||
import { SpecialProcessingProps } from '@/components/processors/processormacros'; | ||
import { createError, handleUpsert } from '@/config/utils'; | ||
import { CensusQuadratResult, QuadratResult } from '@/config/sqlrdsdefinitions/zones'; | ||
|
||
export async function processQuadrats(props: Readonly<SpecialProcessingProps>) { | ||
const { connection, rowData, schema, censusID } = props; | ||
if (!censusID) throw createError('CensusID missing', { censusID }); | ||
|
||
const { quadrat, startx, starty, coordinateunit, dimx, dimy, dimensionunit, area, areaunit, quadratshape } = rowData; | ||
|
||
try { | ||
await connection.beginTransaction(); | ||
const quadratsData = { | ||
QuadratName: quadrat, | ||
StartX: startx, | ||
StartY: starty, | ||
CoordinateUnit: coordinateunit, | ||
DimensionX: dimx, | ||
DimensionY: dimy, | ||
DimensionUnit: dimensionunit, | ||
Area: area, | ||
AreaUnit: areaunit, | ||
QuadratShape: quadratshape | ||
}; | ||
|
||
const quadratID = await handleUpsert<QuadratResult>(connection, schema, 'quadrats', quadratsData, 'QuadratID'); | ||
if (!quadratID) throw createError('upsert failure for row: ', { quadratsData }); | ||
|
||
// need to update censusquadrat | ||
|
||
const cqData = { | ||
CensusID: censusID, | ||
QuadratID: quadratID | ||
}; | ||
const cqID = await handleUpsert<CensusQuadratResult>(connection, schema, 'censusquadrat', cqData, 'CQID'); | ||
if (!cqID) throw createError('upsert failure on censusquadrat for row: ', { cqData }); | ||
|
||
await connection.commit(); | ||
return quadratID; | ||
} catch (error: any) { | ||
await connection.rollback(); | ||
console.error('Upsert failed:', error.message); | ||
throw createError('Upsert failed', { error }); | ||
} | ||
} |
This file contains 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 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 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 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