nicgirault / express-crud-router Goto Github PK
View Code? Open in Web Editor NEWSimply expose resource CRUD (Create Read Update Delete) routes for Express & Sequelize. Compatible with React Admin Simple Rest Data Provider
Simply expose resource CRUD (Create Read Update Delete) routes for Express & Sequelize. Compatible with React Admin Simple Rest Data Provider
I have some auth middleware which sets an auth interface to the express request object.
I would like to be able to get access to the auth interface in my "Custom behavior", so I can do something like this:
router.use(crud('/machines', {
...sequelizeCrud(Machine),
getList: ({ filter, limit, offset, order, req, res }) => {
return Machine.findAndCountAll({
limit,
offset,
order,
where: {
...filter,
userId: req.auth.getAuthenticatedUser().id,
}
})
}
}));
master
branch failed. π¨I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.
You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. Iβm sure you can resolve this πͺ.
Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.
Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master
branch. You can also manually restart the failed CI job that runs semantic-release.
If you are not sure how to resolve this, here is some links that can help you:
If those donβt help, or if this issue is reporting something you think isnβt right, you can always ask the humans behind semantic-release.
The npm token configured in the NPM_TOKEN
environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/
.
If you are using Two-Factor Authentication, make configure the auth-only
level is supported. semantic-release cannot publish with the default auth-and-writes
level.
Please make sure to set the NPM_TOKEN
environment variable in your CI with the exact value of the npm token.
Good luck with your project β¨
Your semantic-release bot π¦π
Nowadays we can only specify enabled actions
I get the following error trying to install the package:
npm ERR! Found: [email protected]
npm ERR! node_modules/sequelize
npm ERR! sequelize@"^6.5.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer sequelize@"^5.0.0" from [email protected]
I am running in a strange bug:
I think there is either a problem with my postgres config (running on Google Cloud SQL) in terms of autocommit or sth. else, but i have checked that with no result, or there is something wrong with a not returned promise in this adapter code?
Hi there
I was wondering if you've thought about adding an option to allow users to provide a middleware function. For instance a permission check on a given route.
import authCheck from './authCheck';
const ROLES = ['ROLE_1', 'ROLE_2']
express.Router()
.get('/some/resource', authCheck(ROLES), (req, res, next) => {})
As far as I can see there is no ability to add any validator or permission-checking middleware.
When I try to run the project with just bare minimum code, I am getting the below error. (Node - 13.1400, npm - 6.14.4)
F:\Freelance\seq-crud-1>node --experimental-modules index.js
file:///F:/Freelance/seq-crud-1/index.js:3
import crud, { sequelizeCrud } from 'express-sequelize-crud'
^^^^^^^^^^^^^
SyntaxError: The requested module 'express-sequelize-crud' does not provide an export named 'sequelizeCrud'
Code :
import express from 'express'
import crud, { sequelizeCrud } from 'express-sequelize-crud'
const Role = require('./models')
const app = new express()
app.use(crud('/admin/users', sequelizeCrud(Role)))
Nice library. Thanks for that. I notice that if we define a custom primary key, some part of the library breaks due to assumption that an 'id' column exists.
I took a look at the code - for example in the getList flow, there is this method parseQuery() which makes the assumption of using ['id', 'ASC'] if an order option is not present.
Can someone fix this? Or point me in the right direction - in case I can help. Thanks in advance.
Hi,
I want to implement filters like the ones exposed by FakeRest, that should be the dialect used by React Admin Simple Rest Data Provider.
For example, if I pass the filter {"id_gt":100}
I would like to have a query such as
SELECT * from x WHERE id > 100;
while now I get something like:
SELECT * from x WHERE id_gt = 100;
I'm not sure where and how I should implement those kind of filters
I have sequelize afterFind hooks which rely on the instance.get('propertyName') method to read a proprety value.
The hooks work fine except on the getList call.
Turns out the raw: true line caused this:
https://github.com/lalalilo/express-sequelize-crud/blob/master/src/sequelize/index.ts#L24
An option for example like this would be very helpfull:
app.use(
crud('/admin/users', sequelizeCrud(User), {
getListRaw: false
})
)
master
branch failed. π¨I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.
You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. Iβm sure you can fix this πͺ.
Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.
Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master
branch. You can also manually restart the failed CI job that runs semantic-release.
If you are not sure how to resolve this, here are some links that can help you:
If those donβt help, or if this issue is reporting something you think isnβt right, you can always ask the humans behind semantic-release.
An npm token must be created and set in the NPM_TOKEN
environment variable on your CI environment.
Please make sure to create an npm token and to set it in the NPM_TOKEN
environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org/
.
Good luck with your project β¨
Your semantic-release bot π¦π
Hello,
Thanks for creating this library! Helps a lot.
I've noticed that update
function doesn't return id
field which triggers ra.notification.data_provider_error
with the following message:
The response to 'update' must be like { data: { id: 123, ... } }, but the received data does not have an 'id' key. The dataProvider is probably wrong for 'update'
It seems that update
function is not compatible with ra-data-simple-rest
stated here: React-Admin Data Providers
Replacing line with:
res.json({ id: (await doUpdate(req.params.id, req.body))[0] });
resolved issue for me.
Please let me know what you think.
Thanks!
How do I access req from Express?
I see req.user.id in the example, but I don't know how..
Missed "searchFields" export. index.js contains only "crud" export.
i tried but it doesn't work((
please fix
`const insertStandardTag: Create<number, StandardTag> = (
parameters: StandardTag
) => {
return StandardTag.create(parameters)
}
adminRouter.use(
crud('/standard-tags', {
...sequelizeCrud(StandardTag),
create: insertStandardTag,
update: null,
getOne: null,
})
)`
This code produce the following issue:
Type 'Create<number, StandardTag>' is not assignable to type 'Create<number, unknown>'.
Types of parameters 'body' and 'body' are incompatible.
Type 'unknown' is not assignable to type 'StandardTag'.
The issue might be link to the following todo
First of all thanks for a lot for express-sequelize-crud <3
And I am wondering if it's possible to let express-sequelize-crud act as middleware?
So instead of:
async (req, res, next) => {
...
res.json(rows);
}
I would like it to do something like this:
async (req, res, next) => {
...
res.bodyInterface.setData(rows);
next();
}
So I can do other stuff like logging after express-sequelize-crud did his thing.
Hi,
I got this error while trying to access API.
model.findAndCountAll is not a function
TypeError: model.findAndCountAll is not a function
at getList (/Users/user/Documents/GitHub/jantungku/node_modules/express-sequelize-crud/lib/sequelize/index.js:27:20)
at /Users/user/Documents/GitHub/jantungku/node_modules/express-sequelize-crud/lib/getList/index.js:32:17
at Layer.handle [as handle_request] (/Users/user/Documents/GitHub/jantungku/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/user/Documents/GitHub/jantungku/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/Users/user/Documents/GitHub/jantungku/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Users/user/Documents/GitHub/jantungku/node_modules/express/lib/router/layer.js:95:5)
at /Users/user/Documents/GitHub/jantungku/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/Users/user/Documents/GitHub/jantungku/node_modules/express/lib/router/index.js:335:12)
at next (/Users/user/Documents/GitHub/jantungku/node_modules/express/lib/router/index.js:275:10)
at jsonParser (/Users/user/Documents/GitHub/jantungku/node_modules/express-sequelize-crud/node_modules/body-parser/lib/types/json.js:110:7)
FYI, my dependencies are:
"dependencies": {
"cookie-parser": "~1.4.4",
"debug": "~2.6.9",
"express": "~4.16.1",
"express-sequelize-crud": "^6.1.2",
"http-errors": "~1.6.3",
"jade": "~1.11.0",
"morgan": "~1.9.1",
"mysql2": "^2.2.5",
"sequelize": "^6.3.5",
"sequelize-auto": "^0.7.6"
}
My code:
var { crud, sequelizeCrud } = require('express-sequelize-crud');
var patients = require('./models/patients');
app.use(crud('/admin/patients', sequelizeCrud(patients)))
Thank you for your help!
From RA v3 - I get the following error:
The X-Total-Count header is missing in the HTTP Response. The jsonServer Data Provider expects responses for lists of resources to contain this header with the total number of results to build the pagination. If you are using CORS, did you declare X-Total-Count in the Access-Control-Expose-Headers header?
Server side, I've enabled CORS to expose the header, but doesn't seem like your package is adding it to the getList and getManyReference actions - required/specified in this doc:
https://github.com/marmelab/react-admin/blob/master/packages/ra-data-json-server/README.md#rest-dialect
Am I missing something or is this something you need to add?
Big thanks - and promising package.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.