Feature/settings page #17
5 changed files with 58 additions and 1363 deletions
1349
api/package-lock.json
generated
1349
api/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,9 @@
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import cors from 'cors';
|
import cors from 'cors';
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
|
import userRouter from './services/user/index.js';
|
||||||
|
import departmentRouter from './services/department/index.js';
|
||||||
|
import pool from './services/postgres/postgresServices.js';
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
import { routes } from './router/routes.js';
|
import { routes } from './router/routes.js';
|
||||||
|
|
||||||
|
|
@ -22,6 +25,31 @@ app.get('*route', (req, res) => {
|
||||||
res.send("Hello from ShiftSync");
|
res.send("Hello from ShiftSync");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.use(express.json());
|
||||||
|
|
||||||
|
const apiRouter = express.Router();
|
||||||
|
|
||||||
|
apiRouter.use('/user', userRouter);
|
||||||
|
apiRouter.use('/department', departmentRouter);
|
||||||
|
|
||||||
|
app.get("/api", (req, res) => {
|
||||||
|
res.json('Welcome to Shift Sync API');
|
||||||
|
});
|
||||||
|
|
||||||
|
app.use('/api', apiRouter);
|
||||||
|
|
||||||
|
app.get('/db-health', async (req, res) => {
|
||||||
|
try {
|
||||||
|
console.log('in');
|
||||||
|
const result = await pool.query('SELECT NOW()');
|
||||||
|
console.log('after result');
|
||||||
|
res.json({ connected: true, time: result.rows[0].now });
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
res.status(500).json({ connected: false, error: err.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
app.listen(5172, () => {
|
app.listen(5172, () => {
|
||||||
console.log('Server Started on port 5172');
|
console.log('Server Started on port 5172');
|
||||||
});
|
});
|
||||||
14
api/services/department/index.js
Normal file
14
api/services/department/index.js
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
import express from 'express';
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
// GET /api/departments
|
||||||
|
router.get('/', (req, res) => {
|
||||||
|
res.json([{ id: 1, name: 'Fire Department' }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
// POST /api/departments
|
||||||
|
router.post('/', (req, res) => {
|
||||||
|
res.status(201).json({ message: 'Department created' });
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
export const postgresServices = {
|
|
||||||
getUsers: async (args) => {
|
|
||||||
try {
|
|
||||||
const dataResp = await runQuery('SELECT * FROM users');
|
|
||||||
return dataResp;
|
|
||||||
} catch (err) {
|
|
||||||
console.log('GET USERS ERROR: ', err);
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
getDepartments: async (args) => {
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
16
api/services/user/index.js
Normal file
16
api/services/user/index.js
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
import express from 'express';
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
// GET /api/users
|
||||||
|
router.get('/', (req, res) => {
|
||||||
|
res.json([{ id: 1, name: 'John Doe' }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
// POST /api/users
|
||||||
|
router.post('/', (req, res) => {
|
||||||
|
res.status(201).json({ message: 'User created' });
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add more routes like PUT, DELETE here later
|
||||||
|
|
||||||
|
export default router;
|
||||||
Loading…
Reference in a new issue