seed stuff

This commit is contained in:
Jake Kasper
2025-09-03 10:56:17 -04:00
parent 6dbdba0e38
commit e7cbaf844f
8 changed files with 271 additions and 28 deletions

View File

@@ -110,7 +110,7 @@ router.get('/:id', validateParams(idParamSchema), async (req, res, next) => {
// Get lawn sections
const sectionsResult = await pool.query(
'SELECT * FROM lawn_sections WHERE property_id = $1 ORDER BY name',
'SELECT *, grass_types FROM lawn_sections WHERE property_id = $1 ORDER BY name',
[propertyId]
);
@@ -132,6 +132,7 @@ router.get('/:id', validateParams(idParamSchema), async (req, res, next) => {
area: parseFloat(section.area),
polygonData: section.polygon_data,
grassType: section.grass_type,
grassTypes: section.grass_types || null,
soilType: section.soil_type,
createdAt: section.created_at,
updatedAt: section.updated_at
@@ -277,7 +278,7 @@ router.delete('/:id', validateParams(idParamSchema), async (req, res, next) => {
router.post('/:id/sections', validateParams(idParamSchema), validateRequest(lawnSectionSchema), async (req, res, next) => {
try {
const propertyId = req.params.id;
const { name, area, polygonData, grassType, soilType } = req.body;
const { name, area, polygonData, grassType, grassTypes, soilType } = req.body;
// Check if property exists and belongs to user
const propertyResult = await pool.query(
@@ -299,10 +300,18 @@ router.post('/:id/sections', validateParams(idParamSchema), validateRequest(lawn
}
const result = await pool.query(
`INSERT INTO lawn_sections (property_id, name, area, polygon_data, grass_type, soil_type)
VALUES ($1, $2, $3, $4, $5, $6)
`INSERT INTO lawn_sections (property_id, name, area, polygon_data, grass_type, grass_types, soil_type)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING *`,
[propertyId, name, calculatedArea, JSON.stringify(polygonData), grassType, soilType]
[
propertyId,
name,
calculatedArea,
JSON.stringify(polygonData),
grassType || (Array.isArray(grassTypes) ? grassTypes.join(', ') : null),
grassTypes ? JSON.stringify(grassTypes) : null,
soilType
]
);
const section = result.rows[0];
@@ -317,6 +326,7 @@ router.post('/:id/sections', validateParams(idParamSchema), validateRequest(lawn
area: parseFloat(section.area),
polygonData: section.polygon_data,
grassType: section.grass_type,
grassTypes: section.grass_types,
soilType: section.soil_type,
createdAt: section.created_at,
updatedAt: section.updated_at
@@ -334,7 +344,7 @@ router.post('/:id/sections', validateParams(idParamSchema), validateRequest(lawn
router.put('/:propertyId/sections/:sectionId', async (req, res, next) => {
try {
const { propertyId, sectionId } = req.params;
const { name, area, polygonData, grassType, soilType } = req.body;
const { name, area, polygonData, grassType, grassTypes, soilType } = req.body;
// Check if section exists and user owns the property
const checkResult = await pool.query(
@@ -357,10 +367,18 @@ router.put('/:propertyId/sections/:sectionId', async (req, res, next) => {
const result = await pool.query(
`UPDATE lawn_sections
SET name = $1, area = $2, polygon_data = $3, grass_type = $4, soil_type = $5, updated_at = CURRENT_TIMESTAMP
WHERE id = $6
SET name = $1, area = $2, polygon_data = $3, grass_type = $4, grass_types=$5, soil_type = $6, updated_at = CURRENT_TIMESTAMP
WHERE id = $7
RETURNING *`,
[name, calculatedArea, JSON.stringify(polygonData), grassType, soilType, sectionId]
[
name,
calculatedArea,
JSON.stringify(polygonData),
grassType || (Array.isArray(grassTypes) ? grassTypes.join(', ') : null),
grassTypes ? JSON.stringify(grassTypes) : null,
soilType,
sectionId
]
);
const section = result.rows[0];
@@ -375,6 +393,7 @@ router.put('/:propertyId/sections/:sectionId', async (req, res, next) => {
area: parseFloat(section.area),
polygonData: section.polygon_data,
grassType: section.grass_type,
grassTypes: section.grass_types,
soilType: section.soil_type,
createdAt: section.created_at,
updatedAt: section.updated_at
@@ -429,4 +448,4 @@ router.delete('/:propertyId/sections/:sectionId', async (req, res, next) => {
}
});
module.exports = router;
module.exports = router;