Skip to content

Commit

Permalink
CMS-348: Add CSV export feature (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
duncan-oxd authored Dec 20, 2024
1 parent 7eb9ba5 commit 7d60d3e
Show file tree
Hide file tree
Showing 13 changed files with 548 additions and 159 deletions.
22 changes: 22 additions & 0 deletions backend/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,26 @@ export default [
"new-cap": "off",
},
},

// Limit linting in seeders/migrations directories
{
files: ["migrations/**/*.js", "seeders/**/*.js"],

languageOptions: {
globals: { ...globals.node },

parserOptions: {
sourceType: "script", // Auto-generated files are CJS modules
},
},

rules: {
"no-unused-vars": "off", // Ignore parameters added by Sequelize
},
},

// Ignore Admin JS bundle directory
{
ignores: [".adminjs/"],
},
];
12 changes: 10 additions & 2 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import homeRoutes from "./routes/home.js";
import helloRoute from "./routes/nested-path-example/hello.js";
import parkRoutes from "./routes/api/parks.js";
import seasonRoutes from "./routes/api/seasons.js";
import exportRoutes from "./routes/api/export.js";

if (!process.env.POSTGRES_SERVER || !process.env.ADMIN_PASSWORD) {
throw new Error("Required environment variables are not set");
Expand Down Expand Up @@ -54,8 +55,15 @@ app.use("/", homeRoutes); // example stuff for testing

// Routes with JWT check middleware
app.use("/nested-path-example/", checkJwt, helloRoute); // example stuff for testing
app.use("/api/", parkRoutes);
app.use("/api/", seasonRoutes);

// API routes
const apiRouter = express.Router();

apiRouter.use("/parks", parkRoutes);
apiRouter.use("/seasons", seasonRoutes);
apiRouter.use("/export", exportRoutes);

app.use("/api", apiRouter);

// AdminJS routes
app.use(admin.options.rootPath, adminRouter);
Expand Down
14 changes: 14 additions & 0 deletions backend/migrations/20241218185747-add-mgmt-area-jsonb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
// Add managementAreaIds to Parks table
await queryInterface.addColumn("Parks", "managementAreas", {
type: Sequelize.JSONB,
allowNull: true,
});
},

async down(queryInterface, Sequelize) {
await queryInterface.removeColumn("Parks", "managementAreas");
},
};
3 changes: 3 additions & 0 deletions backend/models/park.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export default (sequelize) => {
orcs: DataTypes.STRING,
dateableId: DataTypes.INTEGER,
strapiId: DataTypes.INTEGER,
// store raw json for Management Area and Section names,
// since they're only needed for display in the CSV export
managementAreas: DataTypes.JSONB,
},
{
sequelize,
Expand Down
97 changes: 86 additions & 11 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
"dependencies": {
"@adminjs/express": "^6.1.0",
"@adminjs/sequelize": "^4.1.1",
"@fast-csv/format": "^5.0.2",
"adminjs": "^7.8.13",
"axios": "^1.7.8",
"compression": "^1.7.4",
"connect-pg-simple": "^10.0.0",
"cors": "^2.8.5",
"date-fns-tz": "^3.2.0",
"express": "^4.19.2",
"express-async-handler": "^1.2.0",
"express-formidable": "^1.2.0",
Expand Down
Loading

0 comments on commit 7d60d3e

Please sign in to comment.