fixed linting issue
Test Workflow / test-and-lint (pull_request) Successful in 38s
Build and Push Image / build-and-push (pull_request) Successful in 1m40s

This commit is contained in:
2026-05-17 22:41:41 -07:00
parent a960c0fec8
commit 14d4641fbe
+94 -15
View File
@@ -36,7 +36,9 @@ router.get('/:id', async (req, res) => {
})
// Create a new item
router.post('/', [
router.post(
'/',
[
check('collection_id').not().isEmpty(),
check('image_id').not().isEmpty(),
check('productId').not().isEmpty(),
@@ -45,21 +47,46 @@ router.post('/', [
check('extCardText').not().isEmpty(),
check('marketPrice').not().isEmpty(),
check('extRarity').not().isEmpty(),
check('set_id').not().isEmpty() // Add validation for set_id
], async (req, res) => {
check('set_id').not().isEmpty(), // Add validation for set_id
],
async (req, res) => {
const errors = validationResult(req)
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() })
}
const { collection_id, image_id, productId, name, cleanName, extCardText, marketPrice, extRarity, set_id } = req.body
const {
collection_id,
image_id,
productId,
name,
cleanName,
extCardText,
marketPrice,
extRarity,
set_id,
} = req.body
const client = await pool.connect()
try {
const result = await client.query('INSERT INTO items (collection_id, image_id, productId, name, cleanName, extCardText, marketPrice, extRarity, set_id, created_at, updated_at) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, NOW(), NOW()) RETURNING *', [collection_id, image_id, productId, name, cleanName, extCardText, marketPrice, extRarity, set_id])
const result = await client.query(
'INSERT INTO items (collection_id, image_id, productId, name, cleanName, extCardText, marketPrice, extRarity, set_id, created_at, updated_at) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, NOW(), NOW()) RETURNING *',
[
collection_id,
image_id,
productId,
name,
cleanName,
extCardText,
marketPrice,
extRarity,
set_id,
]
)
res.status(201).json(result.rows[0])
} finally {
client.release()
}
})
}
)
// Update an existing item
router.put('/:id', async (req, res) => {
@@ -76,9 +103,14 @@ router.put('/:id', async (req, res) => {
const client = await pool.connect()
try {
if (Object.keys(updates).length > 0) {
const updateFields = Object.keys(updates).map(key => `${key} = $${Object.keys(updates).indexOf(key) + 2}`).join(', ')
const updateFields = Object.keys(updates)
.map((key) => `${key} = $${Object.keys(updates).indexOf(key) + 2}`)
.join(', ')
updates.updated_at = 'NOW()'
const result = await client.query(`UPDATE items SET ${updateFields}, updated_at = $${Object.keys(updates).length + 1} WHERE id = $1 RETURNING *`, [id, ...Object.values(updates)])
const result = await client.query(
`UPDATE items SET ${updateFields}, updated_at = $${Object.keys(updates).length + 1} WHERE id = $1 RETURNING *`,
[id, ...Object.values(updates)]
)
return res.json(result.rows[0])
}
if (result.rows.length === 0) {
@@ -107,22 +139,55 @@ router.delete('/:id', async (req, res) => {
})
// Create a new item from CSV
router.post('/csv', [
router.post(
'/csv',
[
check('collection_id').not().isEmpty(),
check('set_id').not().isEmpty() // Add validation for set_id
], async (req, res) => {
check('set_id').not().isEmpty(), // Add validation for set_id
],
async (req, res) => {
const errors = validationResult(req)
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() })
}
const { collection_id, set_id } = req.body
const csvBuffer = req.files.file.buffer.toString('utf8')
const csvLines = csvBuffer.split('\n').filter(line => line.trim().length > 0)
const csvLines = csvBuffer
.split('\n')
.filter((line) => line.trim().length > 0)
const client = await pool.connect()
try {
// Insert each row into the items table
for (const line of csvLines) {
const [productId, name, cleanName, imageUrl, categoryId, groupId, url, modifiedOn, imageCount, extCardText, extUPC, lowPrice, midPrice, highPrice, marketPrice, directLowPrice, subTypeName, extNumber, extRarity, extCardType, extHP, extStage, extAttack1, extWeakness, extRetreatCost, extAttack2, extResistance] = line.split(',').map(value => value.trim())
const [
productId,
name,
cleanName,
imageUrl,
categoryId,
groupId,
url,
modifiedOn,
imageCount,
extCardText,
extUPC,
lowPrice,
midPrice,
highPrice,
marketPrice,
directLowPrice,
subTypeName,
extNumber,
extRarity,
extCardType,
extHP,
extStage,
extAttack1,
extWeakness,
extRetreatCost,
extAttack2,
extResistance,
] = line.split(',').map((value) => value.trim())
// Fetch the image from imageUrl
const imageResponse = await fetch(imageUrl)
const imageBuffer = await imageResponse.buffer()
@@ -133,12 +198,26 @@ router.post('/csv', [
[`${productId}.jpg`, imageBuffer]
)
await client.query('INSERT INTO items (collection_id, image_id, productId, name, cleanName, extCardText, marketPrice, extRarity, set_id, created_at, updated_at) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, NOW(), NOW())', [collection_id, insertImageResult.rows[0].id, productId, name, cleanName, extCardText, marketPrice, extRarity, set_id])
await client.query(
'INSERT INTO items (collection_id, image_id, productId, name, cleanName, extCardText, marketPrice, extRarity, set_id, created_at, updated_at) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, NOW(), NOW())',
[
collection_id,
insertImageResult.rows[0].id,
productId,
name,
cleanName,
extCardText,
marketPrice,
extRarity,
set_id,
]
)
}
res.status(201).json({ message: 'Items created' })
} finally {
client.release()
}
})
}
)
export default router