-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/clin 2095 #35
Feat/clin 2095 #35
Changes from 6 commits
e00fc46
f7891b4
ac4a9fd
294ed9b
79af369
6297a5e
5351675
7c108cf
422b292
2a43e2d
751d2ba
e88f956
9a28c1f
01030f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a custom validator for roles? making sure every role is alphanumerical only |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,31 +37,54 @@ SavedFilterModel.init( | |
type: DataTypes.STRING, | ||
allowNull: false, | ||
primaryKey: true, | ||
validate: { | ||
isUUID: 4, | ||
}, | ||
}, | ||
keycloak_id: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
validate: { | ||
isUUID: 4, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Magic number. |
||
}, | ||
}, | ||
title: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sommes-nous sûr qu'il n'y a pas de titre funky avec des tirets " |
||
type: DataTypes.TEXT, | ||
validate: { | ||
isAlphanumeric: true, | ||
}, | ||
}, | ||
title: DataTypes.TEXT, | ||
tag: DataTypes.TEXT, | ||
type: DataTypes.ENUM('query', 'filter'), | ||
favorite: { | ||
type: DataTypes.BOOLEAN, | ||
allowNull: false, | ||
defaultValue: false, | ||
validate: { | ||
isBoolean: true, | ||
}, | ||
}, | ||
queries: { | ||
type: DataTypes.ARRAY(DataTypes.JSONB), | ||
allowNull: false, | ||
defaultValue: [], | ||
validate: { | ||
isJSON: true, | ||
}, | ||
}, | ||
creation_date: { | ||
type: DataTypes.DATE, | ||
defaultValue: new Date(), | ||
validate: { | ||
isDate: true, | ||
}, | ||
}, | ||
updated_date: { | ||
type: DataTypes.DATE, | ||
defaultValue: new Date(), | ||
validate: { | ||
isDate: true, | ||
}, | ||
}, | ||
}, | ||
{ sequelize: sequelizeConnection, modelName: 'saved_filters', timestamps: false }, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je pense qu'on devrait ajouter plus de validation de longeur, mais on pourra le faire dans un 2ième temps. Faut s'assurer que dans les BDs actuelles, on mette pas des contraintes qui ne soient pas compatibles avec le contenu de certains champs |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,59 +57,145 @@ UserModel.init( | |
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
unique: true, | ||
validate: { | ||
isInt: true, | ||
}, | ||
}, | ||
keycloak_id: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
validate: { | ||
isUUID: 4, | ||
}, | ||
}, | ||
deleted: { | ||
type: DataTypes.BOOLEAN, | ||
defaultValue: false, | ||
validate: { | ||
isBoolean: true, | ||
}, | ||
}, | ||
first_name: { | ||
type: DataTypes.CITEXT, | ||
validate: { | ||
len: [1, 20], | ||
isAlpha: true, | ||
}, | ||
}, | ||
last_name: { | ||
type: DataTypes.CITEXT, | ||
validate: { | ||
len: [1, 20], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. go with MAX=70 |
||
isAlpha: true, | ||
}, | ||
}, | ||
era_commons_id: { | ||
type: DataTypes.STRING, | ||
validate: { | ||
isAlpha: true, | ||
}, | ||
}, | ||
nih_ned_id: { | ||
type: DataTypes.STRING, | ||
validate: { | ||
isAlpha: true, | ||
}, | ||
}, | ||
commercial_use_reason: { | ||
type: DataTypes.STRING, | ||
validate: { | ||
isAlpha: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. alphanumeric |
||
}, | ||
}, | ||
email: { | ||
type: DataTypes.STRING, | ||
validate: { | ||
isEmail: true, | ||
}, | ||
}, | ||
external_individual_fullname: { | ||
type: DataTypes.TEXT, | ||
validate: { | ||
isAlpha: true, | ||
}, | ||
}, | ||
external_individual_email: { | ||
type: DataTypes.TEXT, | ||
validate: { | ||
isEmail: true, | ||
}, | ||
}, | ||
first_name: DataTypes.CITEXT, | ||
last_name: DataTypes.CITEXT, | ||
era_commons_id: DataTypes.STRING, | ||
nih_ned_id: DataTypes.STRING, | ||
commercial_use_reason: DataTypes.STRING, | ||
email: DataTypes.STRING, | ||
external_individual_fullname: DataTypes.TEXT, | ||
external_individual_email: DataTypes.TEXT, | ||
roles: DataTypes.ARRAY(DataTypes.CITEXT), | ||
affiliation: DataTypes.CITEXT, | ||
public_email: DataTypes.TEXT, | ||
linkedin: DataTypes.TEXT, | ||
affiliation: { | ||
type: DataTypes.CITEXT, | ||
validate: { | ||
isAlphanumeric: true, | ||
}, | ||
}, | ||
public_email: { | ||
type: DataTypes.TEXT, | ||
validate: { | ||
isEmail: true, | ||
}, | ||
}, | ||
linkedin: { | ||
type: DataTypes.TEXT, | ||
validate: { | ||
isUrl: true, | ||
is: /^https?:\/\/(www\.)?linkedin\.com\/in\//i, | ||
}, | ||
}, | ||
portal_usages: DataTypes.ARRAY(DataTypes.CITEXT), | ||
research_domains: DataTypes.ARRAY(DataTypes.CITEXT), | ||
research_area_description: DataTypes.TEXT, | ||
profile_image_key: DataTypes.TEXT, | ||
creation_date: { | ||
type: DataTypes.DATE, | ||
defaultValue: new Date(), | ||
validate: { | ||
isDate: true, | ||
}, | ||
}, | ||
updated_date: { | ||
type: DataTypes.DATE, | ||
defaultValue: new Date(), | ||
validate: { | ||
isDate: true, | ||
}, | ||
}, | ||
consent_date: DataTypes.DATE, | ||
accepted_terms: { | ||
type: DataTypes.BOOLEAN, | ||
allowNull: false, | ||
defaultValue: false, | ||
validate: { | ||
isBoolean: true, | ||
}, | ||
}, | ||
understand_disclaimer: { | ||
type: DataTypes.BOOLEAN, | ||
allowNull: false, | ||
defaultValue: false, | ||
validate: { | ||
isBoolean: true, | ||
}, | ||
}, | ||
completed_registration: { | ||
type: DataTypes.BOOLEAN, | ||
allowNull: false, | ||
defaultValue: false, | ||
validate: { | ||
isBoolean: true, | ||
}, | ||
}, | ||
config: { | ||
type: DataTypes.JSONB, | ||
allowNull: false, | ||
defaultValue: {}, | ||
validate: { | ||
isJSON: true, | ||
}, | ||
}, | ||
}, | ||
{ sequelize: sequelizeConnection, modelName: 'users', timestamps: false }, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,32 +34,53 @@ UserSetModel.init( | |
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
validate: { | ||
isUUID: 4, | ||
}, | ||
}, | ||
keycloak_id: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
validate: { | ||
isUUID: 4, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. même commentaire que plus haut |
||
}, | ||
}, | ||
alias: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
validate: { | ||
isAlpha: true, | ||
}, | ||
}, | ||
sharedpublicly: { | ||
type: DataTypes.BOOLEAN, | ||
allowNull: false, | ||
defaultValue: false, | ||
validate: { | ||
isBoolean: true, | ||
}, | ||
}, | ||
content: { | ||
type: DataTypes.JSONB, | ||
allowNull: false, | ||
defaultValue: {}, | ||
validate: { | ||
isJSON: true, | ||
}, | ||
}, | ||
creation_date: { | ||
type: DataTypes.DATE, | ||
defaultValue: new Date(), | ||
validate: { | ||
isDate: true, | ||
}, | ||
}, | ||
updated_date: { | ||
type: DataTypes.DATE, | ||
defaultValue: new Date(), | ||
validate: { | ||
isDate: true, | ||
}, | ||
}, | ||
}, | ||
{ sequelize: sequelizeConnection, modelName: 'user_sets', timestamps: false }, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
import { NextFunction, Request, Response } from 'express'; | ||
import { HttpError } from 'http-errors'; | ||
import { getReasonPhrase, StatusCodes } from 'http-status-codes'; | ||
import { BaseError, UniqueConstraintError } from 'sequelize'; | ||
import { BaseError, UniqueConstraintError, ValidationError } from 'sequelize'; | ||
|
||
export const globalErrorHandler = (err: unknown, _req: Request, res: Response, _next: NextFunction): void => { | ||
if (err instanceof UniqueConstraintError) { | ||
res.status(StatusCodes.UNPROCESSABLE_ENTITY).json({ | ||
error: 'A resource with the same id already exists.', | ||
}); | ||
} else if (err instanceof ValidationError) { | ||
const error = { | ||
name: 'Invalid data', | ||
errors: err.errors.map((error) => error.message.replace('%s', error.path)), | ||
}; | ||
res.status(422).json({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
error, | ||
}); | ||
} else if (err instanceof HttpError) { | ||
res.status(err.status).json({ | ||
error: err.message, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍