Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ module.exports = {
'consistent-return': 'off',
'no-return-assign': 'off',
},
}
},
{
files: ['./lib/models/**/*.js'],
rules: {
'no-unused-vars': 'off',
'import/first': 'off',
'import/extensions': 'off',
'import/newline-after-import': 'off',
'prefer-destructuring': 'off',

},
},
],
};
6 changes: 4 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
version: '3'
services:
db_mysql:
image: mysql:5.7
image: mysql:8.0.33
platform: linux/arm64/v8
ports:
- '3306:3306'
restart: always
Expand All @@ -11,7 +12,8 @@ services:
MYSQL_ROOT_PASSWORD: password

redis:
image: 'redis:alpine'
image: 'redis:7-alpine'
platform: linux/arm64/v8
ports:
- '6379:6379'
command: ['redis-server', '--bind', 'redis', '--port', '6379']
Expand Down
55 changes: 55 additions & 0 deletions lib/models/DriverLocations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import _sequelize from 'sequelize';
const { Model, Sequelize } = _sequelize;

export default class DriverLocations extends Model {
static init(sequelize, DataTypes) {
return sequelize.define('DriverLocations', {
id: {
type: DataTypes.CHAR(36),
allowNull: false,
defaultValue: Sequelize.Sequelize.fn('uuid'),
primaryKey: true
},
driverId: {
type: DataTypes.CHAR(36),
allowNull: false,
references: {
model: 'users',
key: 'id'
},
field: 'driver_id'
},
location: {
type: "POINT",
allowNull: false
}
}, {
tableName: 'driver_locations',
timestamps: true,
indexes: [
{
name: "PRIMARY",
unique: true,
using: "BTREE",
fields: [
{ name: "id" },
]
},
{
name: "idx_driver_locations_driver_id",
using: "BTREE",
fields: [
{ name: "driver_id" },
]
},
{
name: "idx_driver_locations_location",
type: "SPATIAL",
fields: [
{ name: "location", length: 32 },
]
},
]
});
}
}
72 changes: 72 additions & 0 deletions lib/models/OauthAccessTokens.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import _sequelize from 'sequelize';
const { Model, Sequelize } = _sequelize;

export default class OauthAccessTokens extends Model {
static init(sequelize, DataTypes) {
return sequelize.define('OauthAccessTokens', {
id: {
autoIncrement: true,
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true
},
oauthClientId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'oauth_clients',
key: 'id'
},
field: 'oauth_client_id'
},
accessToken: {
type: DataTypes.STRING(64),
allowNull: false,
unique: "oauth_access_tokens_access_token_uindex",
field: 'access_token'
},
expiresIn: {
type: DataTypes.MEDIUMINT.UNSIGNED,
allowNull: false,
field: 'expires_in'
},
expiresOn: {
type: DataTypes.DATE,
allowNull: false,
field: 'expires_on'
},
metadata: {
type: DataTypes.JSON,
allowNull: false
}
}, {
tableName: 'oauth_access_tokens',
timestamps: true,
indexes: [
{
name: "PRIMARY",
unique: true,
using: "BTREE",
fields: [
{ name: "id" },
]
},
{
name: "oauth_access_tokens_access_token_uindex",
unique: true,
using: "BTREE",
fields: [
{ name: "access_token" },
]
},
{
name: "oauth_access_tokens_oauth_clients_id_fk",
using: "BTREE",
fields: [
{ name: "oauth_client_id" },
]
},
]
});
}
}
71 changes: 71 additions & 0 deletions lib/models/OauthClientResources.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import _sequelize from 'sequelize';
const { Model, Sequelize } = _sequelize;

export default class OauthClientResources extends Model {
static init(sequelize, DataTypes) {
return sequelize.define('OauthClientResources', {
id: {
autoIncrement: true,
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true
},
oauthClientId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'oauth_clients',
key: 'id'
},
field: 'oauth_client_id'
},
resourceType: {
type: DataTypes.STRING(36),
allowNull: false,
field: 'resource_type'
},
resourceId: {
type: DataTypes.STRING(36),
allowNull: false,
field: 'resource_id'
}
}, {
tableName: 'oauth_client_resources',
timestamps: true,
indexes: [
{
name: "PRIMARY",
unique: true,
using: "BTREE",
fields: [
{ name: "id" },
]
},
{
name: "oauth_client_resources_oauth_client_id_resource_uindex",
unique: true,
using: "BTREE",
fields: [
{ name: "oauth_client_id" },
{ name: "resource_type" },
{ name: "resource_id" },
]
},
{
name: "resource_type",
using: "BTREE",
fields: [
{ name: "resource_type" },
]
},
{
name: "resource_id",
using: "BTREE",
fields: [
{ name: "resource_id" },
]
},
]
});
}
}
50 changes: 50 additions & 0 deletions lib/models/OauthClientScopes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import _sequelize from 'sequelize';
const { Model, Sequelize } = _sequelize;

export default class OauthClientScopes extends Model {
static init(sequelize, DataTypes) {
return sequelize.define('OauthClientScopes', {
id: {
autoIncrement: true,
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true
},
oauthClientId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'oauth_clients',
key: 'id'
},
unique: "oauth_client_scopes_oauth_clients_id_fk",
field: 'oauth_client_id'
},
scope: {
type: DataTypes.STRING(36),
allowNull: false
}
}, {
tableName: 'oauth_client_scopes',
timestamps: true,
indexes: [
{
name: "PRIMARY",
unique: true,
using: "BTREE",
fields: [
{ name: "id" },
]
},
{
name: "oauth_client_scopes_uindex",
unique: true,
using: "BTREE",
fields: [
{ name: "oauth_client_id" },
]
},
]
});
}
}
66 changes: 66 additions & 0 deletions lib/models/OauthClients.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import _sequelize from 'sequelize';
const { Model, Sequelize } = _sequelize;

export default class OauthClients extends Model {
static init(sequelize, DataTypes) {
return sequelize.define('OauthClients', {
id: {
autoIncrement: true,
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true
},
clientId: {
type: DataTypes.STRING(320),
allowNull: false,
unique: "oauth_clients_client_id",
field: 'client_id'
},
clientSecret: {
type: DataTypes.STRING(36),
allowNull: false,
field: 'client_secret'
},
grantType: {
type: DataTypes.ENUM('CLIENT_CREDENTIALS'),
allowNull: true,
field: 'grant_type'
}
Comment on lines +24 to +28
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Make grantType a required field.

The grantType field is currently nullable (allowNull: true), but this is typically a required field for OAuth clients as it determines the authentication flow. Consider making it required.

    grantType: {
      type: DataTypes.ENUM('CLIENT_CREDENTIALS'),
-      allowNull: true,
+      allowNull: false,
      field: 'grant_type'
    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
grantType: {
type: DataTypes.ENUM('CLIENT_CREDENTIALS'),
allowNull: true,
field: 'grant_type'
}
grantType: {
type: DataTypes.ENUM('CLIENT_CREDENTIALS'),
allowNull: false,
field: 'grant_type'
}

}, {
tableName: 'oauth_clients',
timestamps: true,
indexes: [
{
name: "PRIMARY",
unique: true,
using: "BTREE",
fields: [
{ name: "id" },
]
},
{
name: "oauth_clients_client_id",
unique: true,
using: "BTREE",
fields: [
{ name: "client_id" },
]
},
{
name: "client_id",
using: "BTREE",
fields: [
{ name: "client_id" },
]
},
Comment on lines +49 to +55
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove redundant index on client_id.

There's a redundant non-unique index client_id which duplicates the unique index oauth_clients_client_id. Having both indexes on the same column is unnecessary and could impact performance.

      {
        name: "oauth_clients_client_id",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "client_id" },
        ]
      },
-     {
-       name: "client_id",
-       using: "BTREE",
-       fields: [
-         { name: "client_id" },
-       ]
-     },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{
name: "client_id",
using: "BTREE",
fields: [
{ name: "client_id" },
]
},
{
name: "oauth_clients_client_id",
unique: true,
using: "BTREE",
fields: [
{ name: "client_id" },
]
},

{
name: "client_secret",
using: "BTREE",
fields: [
{ name: "client_secret" },
]
},
]
});
}
}
Loading
Loading