fixed linting issue
Test Workflow / test-and-lint (pull_request) Failing after 46s

This commit is contained in:
2026-05-16 22:33:48 -07:00
parent f3a7fe6cbe
commit 2b921b697e
2 changed files with 96 additions and 76 deletions
+35 -19
View File
@@ -1,26 +1,31 @@
import express from 'express'
import { check, validationResult } from 'express-validator/check'
import { Pool } from 'pg'
import { database } from '../../config'
const { check, validationResult } = require('express-validator/check')
const router = express.Router()
// Create a connection pool to the database
const pool = new Pool(database)
// CREATE AN IMAGE
router.post('/', [
check('file').isString(),
check('image').isBase64()
], async (req, res) => {
router.post(
'/',
[check('file').isString(), check('image').isBase64()],
async (req, res) => {
try {
const errors = validationResult(req)
if (!errors.isEmpty()) return res.status(400).json({ errors: errors.array() })
if (!errors.isEmpty())
return res.status(400).json({ errors: errors.array() })
const { file, image } = req.body
const client = await pool.connect()
const result = await client.query('INSERT INTO images (file, image, created_at, updated_at) VALUES ($1, $2, NOW(), NOW()) RETURNING *', [file, image])
const result = await client.query(
'INSERT INTO images (file, image, created_at, updated_at) VALUES ($1, $2, NOW(), NOW()) RETURNING *',
[file, image]
)
client.release()
return res.status(201).json(result.rows[0])
@@ -28,7 +33,8 @@ router.post('/', [
console.error(err.stack)
return res.status(500).json({ error: 'Server error' })
}
})
}
)
// READ AN IMAGE
router.get('/:id', async (req, res) => {
@@ -36,10 +42,13 @@ router.get('/:id', async (req, res) => {
const { id } = req.params
const client = await pool.connect()
const result = await client.query('SELECT * FROM images WHERE id = $1', [id])
const result = await client.query('SELECT * FROM images WHERE id = $1', [
id,
])
client.release()
if (result.rows.length === 0) return res.status(404).json({ error: 'Image not found' })
if (result.rows.length === 0)
return res.status(404).json({ error: 'Image not found' })
return res.status(200).json(result.rows[0])
} catch (err) {
@@ -49,13 +58,14 @@ router.get('/:id', async (req, res) => {
})
// UPDATE AN IMAGE
router.put('/:id', [
check('file').optional().isString(),
check('image').optional().isBase64()
], async (req, res) => {
router.put(
'/:id',
[check('file').optional().isString(), check('image').optional().isBase64()],
async (req, res) => {
try {
const errors = validationResult(req)
if (!errors.isEmpty()) return res.status(400).json({ errors: errors.array() })
if (!errors.isEmpty())
return res.status(400).json({ errors: errors.array() })
const { id } = req.params
const { file, image } = req.body
@@ -83,14 +93,16 @@ router.put('/:id', [
const result = await client.query(query, values)
client.release()
if (result.rows.length === 0) return res.status(404).json({ error: 'Image not found' })
if (result.rows.length === 0)
return res.status(404).json({ error: 'Image not found' })
return res.status(200).json(result.rows[0])
} catch (err) {
console.error(err.stack)
return res.status(500).json({ error: 'Server error' })
}
})
}
)
// DELETE AN IMAGE
router.delete('/:id', async (req, res) => {
@@ -98,10 +110,14 @@ router.delete('/:id', async (req, res) => {
const { id } = req.params
const client = await pool.connect()
const result = await client.query('DELETE FROM images WHERE id = $1 RETURNING *', [id])
const result = await client.query(
'DELETE FROM images WHERE id = $1 RETURNING *',
[id]
)
client.release()
if (result.rows.length === 0) return res.status(404).json({ error: 'Image not found' })
if (result.rows.length === 0)
return res.status(404).json({ error: 'Image not found' })
return res.status(200).json(result.rows[0])
} catch (err) {
+7 -3
View File
@@ -1,8 +1,9 @@
import express from 'express'
import { check, validationResult } from 'express-validator/check'
import { Pool } from 'pg'
import { database } from '../../config'
const { check, validationResult } = require('express-validator/check')
const router = express.Router()
// Create a connection pool to the database
@@ -45,8 +46,11 @@ router.get('/', async (req, res) => {
// Get a single location by ID
router.get('/:id', async (req, res) => {
try {
const result = await pool.query('SELECT * FROM locations WHERE id = $1', [req.params.id])
if (result.rows.length === 0) return res.status(404).send('Location not found')
const result = await pool.query('SELECT * FROM locations WHERE id = $1', [
req.params.id,
])
if (result.rows.length === 0)
return res.status(404).send('Location not found')
res.send(result.rows[0])
} catch (err) {
console.error(err.message)