Spaces:
Running
Running
Upload 29 files
Browse files- src/routes/patti.js +8 -7
src/routes/patti.js
CHANGED
|
@@ -159,17 +159,18 @@ router.get('/lots/active', async (req, res) => {
|
|
| 159 |
}
|
| 160 |
});
|
| 161 |
|
| 162 |
-
// GET patti available lots by mirchi type (
|
| 163 |
router.get('/lots/available/:mirchiTypeId', async (req, res) => {
|
| 164 |
try {
|
| 165 |
const { mirchiTypeId } = req.params;
|
| 166 |
const result = await pool.query(
|
| 167 |
-
`SELECT *,
|
| 168 |
-
|
| 169 |
-
FROM patti_lots
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
|
|
|
| 173 |
[mirchiTypeId]
|
| 174 |
);
|
| 175 |
res.json(result.rows);
|
|
|
|
| 159 |
}
|
| 160 |
});
|
| 161 |
|
| 162 |
+
// GET patti available lots by mirchi type (all lots for dropdown)
|
| 163 |
router.get('/lots/available/:mirchiTypeId', async (req, res) => {
|
| 164 |
try {
|
| 165 |
const { mirchiTypeId } = req.params;
|
| 166 |
const result = await pool.query(
|
| 167 |
+
`SELECT pl.*,
|
| 168 |
+
COALESCE(SUM(pti.poti_count), 0) as poti_count
|
| 169 |
+
FROM patti_lots pl
|
| 170 |
+
LEFT JOIN patti_transaction_items pti ON pl.id = pti.lot_id
|
| 171 |
+
WHERE pl.mirchi_type_id = $1
|
| 172 |
+
GROUP BY pl.id
|
| 173 |
+
ORDER BY pl.purchase_date DESC`,
|
| 174 |
[mirchiTypeId]
|
| 175 |
);
|
| 176 |
res.json(result.rows);
|