Skip to content
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

Day 2 & 3 onbording #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
30 changes: 30 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"sqltools.connections": [
{
"mysqlOptions": {
"authProtocol": "default",
"enableSsl": "Disabled"
},
"previewLimit": 50,
"server": "localhost",
"port": 3306,
"driver": "MySQL",
"name": "nodejs-hapi-template",
"database": "temp_dev",
"username": "def_user",
"password": "password"
}
],
"redisXplorer.config": {
"profiles": [
{
"name": "nodejs-hapi-template",
"host": "redis:6379",
"accessKey": "",
"filter": "*",
"port": "6379"
}
],
"scanLimit": 200
}
}
2 changes: 1 addition & 1 deletion jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"allowJs": true,
"checkJs": true,
"baseUrl": "./",
"moduleResolution": "node",
"moduleResolution": "nodenext",
"resolveJsonModule": true,
"paths": {
"@root": ["./"],
Expand Down
64 changes: 64 additions & 0 deletions lib/models/cabs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
module.exports = function(sequelize, DataTypes) {
return sequelize.define('cabs', {
id: {
autoIncrement: true,
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true
},
driverId: {
field: "driver_id",
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'drivers',
key: 'id'
}
},
carDetailsId: {
field: "car_details_id",
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'car_details',
key: 'id'
}
},
location: {
type: DataTypes.GEOMETRY,
allowNull: false
},
status: {
type: DataTypes.ENUM('not-available','available'),
allowNull: false
}
}, {
sequelize,
tableName: 'cabs',
timestamps: true,
indexes: [
{
name: "PRIMARY",
unique: true,
using: "BTREE",
fields: [
{ name: "id" },
]
},
{
name: "fk_driver",
using: "BTREE",
fields: [
{ name: "driverId" },
]
},
{
name: "fk_car_details",
using: "BTREE",
fields: [
{ name: "carDetailsId" },
]
},
]
});
};
39 changes: 39 additions & 0 deletions lib/models/car_details.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module.exports = function(sequelize, DataTypes) {
return sequelize.define('car_details', {
id: {
autoIncrement: true,
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true
},
carName: {
field: "car_name",
type: DataTypes.STRING(50),
allowNull: false
},
licensePlateNumber: {
field: "license_plate_number",
type: DataTypes.STRING(50),
allowNull: false
},
carBrand: {
field:"car_brand",
type: DataTypes.STRING(50),
allowNull: true
}
}, {
sequelize,
tableName: 'car_details',
timestamps: false,
indexes: [
{
name: "PRIMARY",
unique: true,
using: "BTREE",
fields: [
{ name: "id" },
]
},
]
});
};
46 changes: 46 additions & 0 deletions lib/models/drivers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module.exports = function(sequelize, DataTypes) {
return sequelize.define('drivers', {
id: {
autoIncrement: true,
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true
},
name: {
type: DataTypes.STRING(255),
allowNull: false
},
licenseNumber: {
field: "license_number",
type: DataTypes.STRING(50),
allowNull: false
},
contactNumber: {
field: "contact_number",
type: DataTypes.STRING(20),
allowNull: false
},
ratings: {
type: DataTypes.DECIMAL(3,2),
allowNull: true
},
status: {
type: DataTypes.ENUM('active','inactive'),
allowNull: false
}
}, {
sequelize,
tableName: 'drivers',
timestamps: false,
indexes: [
{
name: "PRIMARY",
unique: true,
using: "BTREE",
fields: [
{ name: "id" },
]
},
]
});
};
8 changes: 8 additions & 0 deletions lib/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import oauthClientResources from './oauthClientResources';
import oauthClientScopes from './oauthClientScopes';
import oauthClients from './oauthClients';
import users from './users';
import cabs from './cabs';
import drivers from './drivers';
import carDetails from './car_details';
import rides from './rides';

let sequelize;
if (process.env.NODE_ENV === 'test') {
Expand All @@ -28,6 +32,10 @@ export const models = {
oauthClientScopes: oauthClientScopes(sequelize, Sequelize.DataTypes),
oauthClients: oauthClients(sequelize, Sequelize.DataTypes),
users: users(sequelize, Sequelize.DataTypes),
cabs: cabs(sequelize, Sequelize.DataTypes),
carDetails: carDetails(sequelize, Sequelize.DataTypes),
drivers: drivers(sequelize, Sequelize.DataTypes),
rides: rides(sequelize, Sequelize.DataTypes),
};

Object.keys(models).forEach((modelName) => {
Expand Down
85 changes: 85 additions & 0 deletions lib/models/rides.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
module.exports = function(sequelize, DataTypes) {
return sequelize.define('rides', {
id: {
autoIncrement: true,
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true
},
userId: {
field: "user_id",
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'users',
key: 'id'
}
},
cabId: {
field: "cab_id",
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'cabs',
key: 'id'
}
},
startPoint: {
field: "start_point",
type: DataTypes.GEOMETRY,
allowNull: false
},
endPoint: {
field: "end_point",
type: DataTypes.GEOMETRY,
allowNull: false
},
timeStart: {
field: "time_start",
type: DataTypes.DATE,
allowNull: false
},
timeEnd: {
field: "time_end",
type: DataTypes.DATE,
allowNull: false
},
fare: {
type: DataTypes.DECIMAL(10,2),
allowNull: false
},
rideTime: {
field: "ride_time",
type: DataTypes.DECIMAL(10,2),
allowNull: false
}
}, {
sequelize,
tableName: 'rides',
timestamps: true,
indexes: [
{
name: "PRIMARY",
unique: true,
using: "BTREE",
fields: [
{ name: "id" },
]
},
{
name: "fk_user",
using: "BTREE",
fields: [
{ name: "userId" },
]
},
{
name: "fk_cab",
using: "BTREE",
fields: [
{ name: "cabId" },
]
},
]
});
};
83 changes: 49 additions & 34 deletions lib/models/users.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,51 @@
export default function (sequelize, DataTypes) {
return sequelize.define(
'users',
{
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
},
firstName: {
field: 'first_name',
type: DataTypes.STRING(32),
allowNull: false,
},
lastName: {
field: 'last_name',
type: DataTypes.STRING(32),
allowNull: false,
},
email: {
type: DataTypes.STRING(32),
allowNull: false,
},
createdAt: {
field: 'created_at',
type: DataTypes.DATE,
allowNull: false,
defaultValue: sequelize.literal('CURRENT_TIMESTAMP'),
},
module.exports = function(sequelize, DataTypes) {
return sequelize.define('users', {
id: {
autoIncrement: true,
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true
},
{
tableName: 'users',
timestamps: false,
oauth_client_id: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'oauth_clients',
key: 'id'
}
},
);
}
first_name: {
type: DataTypes.STRING(32),
allowNull: false
},
last_name: {
type: DataTypes.STRING(32),
allowNull: false
},
email: {
type: DataTypes.STRING(32),
allowNull: false
}
}, {
sequelize,
tableName: 'users',
timestamps: true,
indexes: [
{
name: "PRIMARY",
unique: true,
using: "BTREE",
fields: [
{ name: "id" },
]
},
{
name: "users_oauth_clients_id_fk",
using: "BTREE",
fields: [
{ name: "oauth_client_id" },
]
},
]
});
};
6 changes: 6 additions & 0 deletions migrations/20240404070514-create-driver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { migrate } = require('./utils');

module.exports = {
up: (queryInterface) => migrate(__filename, queryInterface),
down: () => Promise.reject(new Error('error')),
};
Loading
Loading