Skip to content

Commit

Permalink
Merge pull request #437 from bluewave-labs/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
erenfn authored Dec 26, 2024
2 parents c203d9c + e5a1d23 commit dcd5abb
Show file tree
Hide file tree
Showing 64 changed files with 1,223 additions and 522 deletions.
19 changes: 19 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Describe your changes

Briefly describe the changes you made and their purpose.

## Issue number

Mention the issue number(s) this PR addresses (e.g., #123).

## Please ensure all items are checked off before requesting a review:

- [ ] I deployed the code locally.
- [ ] I have performed a self-review of my code.
- [ ] I have included the issue # in the PR.
- [ ] I have labelled the PR correctly.
- [ ] The issue I am working on is assigned to me.
- [ ] I didn't use any hardcoded values (otherwise it will not scale, and will make it difficult to maintain consistency across the application).
- [ ] I made sure font sizes, color choices etc are all referenced from the theme.
- [ ] My PR is granular and targeted to one specific feature.
- [ ] I took a screenshot or a video and attached to this PR if there is a UI change.
81 changes: 81 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,87 @@ This is a work-in-progress application. The source code is available under GNU A
- [Node.js](https://nodejs.org/en)
- [PostgreSQL](https://postgresql.org)


## Installation

1. Make sure Docker is installed to your machine where the server will run.
2. Make sure git is installed to your machine Git.
3. Make sure nginx is installed.

4. Clone GitHub Repository

```
cd ~
git clone https://github.com/bluewave-labs/bluewave-onboarding.git
cd bluewave-onboarding
```

5. Configure Nginx

Open the Nginx configuration file:

``sudo nano /etc/nginx/sites-available/onboarding-demo``

Add the following configuration. Change YOUR_DOMAIN_NAME with your domain name:

```server {
listen 80;
server_name YOUR_DOMAIN_NAME;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name YOUR_DOMAIN_NAME;
ssl_certificate /etc/letsencrypt/live/YOUR_DOMAIN_NAME/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/YOUR_DOMAIN_NAME/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
location / {
proxy_pass http://localhost:4173;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /api/ {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
```


6. Create a symbolic link to enable the configuration:

``sudo ln -s /etc/nginx/sites-available/onboarding-demo /etc/nginx/sites-enabled/``

7. Install Certbot and its Nginx plugin:

``sudo apt install certbot python3-certbot-nginx``

8. Obtain SSL Certificate. Run Certbot to obtain a certificate for your domain:

``sudo certbot --nginx``

9. Verify the Nginx configuration:

``sudo nginx -t``

10. Restart Nginx to apply the changes:

``sudo systemctl restart nginx``

11. Start the project

``cd ~/bluewave-onboarding
docker compose up -d``

## Contributing

Here's how you can contribute to the Onboarding product.
Expand Down
1 change: 1 addition & 0 deletions backend/.env
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ TEST_DB_NAME=onboarding_db_test
TEST_DB_HOST=localhost
TEST_DB_PORT=5432

ENABLE_IP_CHECK=false
# Allowed IP range for the API "baseIp/rangeStart-rangeEnd" (e.g. 192.168.1/1-255) separated by comma
ALLOWED_IP_RANGE=11.22.33/10-200, 192.168.65/1-255
# Allowed IP addresses for the API separated by comma
Expand Down
1 change: 1 addition & 0 deletions backend/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ PROD_DB_PORT=5432
# JWT Secret Key
JWT_SECRET=your_prod_jwt_secret_key_here

ENABLE_IP_CHECK=false
# Allowed IP range for the API "baseIp/rangeStart-rangeEnd" (e.g. 192.168.1/1-255) separated by comma
ALLOWED_IP_RANGE=11.22.33/10-200
# Allowed IP addresses for the API separated by comma
Expand Down
1 change: 1 addition & 0 deletions backend/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ POSTGRES_DB=onboarding_db_test
# JWT Secret Key
JWT_SECRET=your_test_jwt_secret_key_here

ENABLE_IP_CHECK=false
# Allowed IP range for the API "baseIp/rangeStart-rangeEnd" (e.g. 192.168.1/1-255) separated by comma
ALLOWED_IP_RANGE=11.22.33/10-200, 192.168.65/1-255
# Allowed IP addresses for the API separated by comma
Expand Down
28 changes: 28 additions & 0 deletions backend/migrations/20241219181037-add-index-guidelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"use strict";

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
/**
* Add altering commands here.
*
* Example:
* await queryInterface.createTable('users', { id: Sequelize.INTEGER });
*/
await queryInterface.addIndex("guide_logs", ["showingTime"], {
name: "idx_guide_logs_showingTime",
});
},

async down(queryInterface, Sequelize) {
await queryInterface.removeIndex("guide_logs", ["showingTime"], {
name: "idx_guide_logs_showingTime",
});
/**
* Add reverting commands here.
*
* Example:
* await queryInterface.dropTable('users');
*/
},
};
2 changes: 1 addition & 1 deletion backend/src/controllers/guide.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const bannerService = require("../service/banner.service");
const guidelogService = require("../service/guidelog.service");
const helperLinkService = require("../service/helperLink.service");
const popupService = require("../service/popup.service");

const { internalServerError } = require("../utils/errors.helper");
class GuideController {
async getGuidesByUrl(req, res) {
try {
Expand Down
23 changes: 23 additions & 0 deletions backend/src/controllers/statistics.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const statisticsService = require("../service/statistics.service");
const { internalServerError } = require("../utils/errors.helper");

class StatisticsController {
async getStatistics(req, res) {
try {
const userId = req.user.id;
const statistics = await statisticsService.generateStatistics({
userId: userId.toString(),
});
res.status(200).json(statistics);
} catch (e) {
console.log(e)
const { statusCode, payload } = internalServerError(
"GET_STATISTICS_ERROR",
e.message
);
res.status(statusCode).json(payload);
}
}
}

module.exports = new StatisticsController();
104 changes: 55 additions & 49 deletions backend/src/models/GuideLog.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,64 @@
const { GuideType } = require('../utils/guidelog.helper');
const { GuideType } = require("../utils/guidelog.helper");

module.exports = (sequelize, DataTypes) => {
const GuideLog = sequelize.define('GuideLog', {
guideType: {
type: DataTypes.INTEGER,
allowNull: false,
validate: {
isIn: {
args: [
Object.values(GuideType),
],
msg: 'guideType must be a valid value.',
},
},
const GuideLog = sequelize.define(
"GuideLog",
{
guideType: {
type: DataTypes.INTEGER,
allowNull: false,
validate: {
isIn: {
args: [Object.values(GuideType)],
msg: "guideType must be a valid value.",
},
},
guideId: {
type: DataTypes.INTEGER,
allowNull: false,
},
guideId: {
type: DataTypes.INTEGER,
allowNull: false,
},
userId: {
type: DataTypes.STRING,
allowNull: false,
},
showingTime: {
type: DataTypes.DATE,
defaultValue: DataTypes.NOW,
},
completed: {
type: DataTypes.BOOLEAN,
defaultValue: false,
},
},
{
timestamps: false,
tableName: "guide_logs",
indexes: [
{
name: "idx_guide_logs_userId",
fields: ["userId"],
},
userId: {
type: DataTypes.STRING,
allowNull: false,
{
name: "idx_guide_logs_guideId",
fields: ["guideId"],
},
showingTime: {
type: DataTypes.DATE,
defaultValue: DataTypes.NOW,
{
name: "idx_guide_logs_guideType",
fields: ["guideType"],
},
completed: {
type: DataTypes.BOOLEAN,
defaultValue: false,
{
name: "idx_guide_logs_userId_guideId_guideType",
fields: ["userId", "guideId", "guideType"],
unique: false,
},
}, {
timestamps: false,
tableName: 'guide_logs',
indexes: [
{
name: 'idx_guide_logs_userId',
fields: ['userId'],
},
{
name: 'idx_guide_logs_guideId',
fields: ['guideId'],
},
{
name: 'idx_guide_logs_guideType',
fields: ['guideType'],
},
{
name: 'idx_guide_logs_userId_guideId_guideType',
fields: ['userId', 'guideId', 'guideType'],
unique: false,
},
],
});
{
name: "idx_guide_logs_showingTime",
fields: ["showingTime"],
},
],
}
);

return GuideLog;
return GuideLog;
};
9 changes: 9 additions & 0 deletions backend/src/routes/statistics.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const express = require("express");
const statisticsController = require("../controllers/statistics.controller");
const authenticateJWT = require("../middleware/auth.middleware");

const router = express.Router();
router.use(authenticateJWT)
router.get("/", statisticsController.getStatistics);

module.exports = router;
6 changes: 5 additions & 1 deletion backend/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ const tourRoutes = require("./routes/tour.routes");
const linkRoutes = require("./routes/link.routes");
const helperLinkRoutes = require("./routes/helperLink.routes");
const guideRoutes = require("./routes/guide.routes");
const statisticsRoutes = require("./routes/statistics.routes");

const app = express();

app.use(cors());
app.use(helmet());
app.use(bodyParser.json({ limit: MAX_FILE_SIZE }));
app.use(jsonErrorMiddleware);
app.use(ipFilter);
if (process.env.ENABLE_IP_CHECK === 'true') {
app.use(ipFilter);
}
// app.use(fileSizeValidator);

const { sequelize } = require("./models");
Expand All @@ -57,6 +60,7 @@ app.use("/api/hint", hint);
app.use("/api/tour", tourRoutes);
app.use("/api/link", linkRoutes);
app.use("/api/helper-link", helperLinkRoutes);
app.use("/api/statistics", statisticsRoutes);

app.use((err, req, res, next) => {
console.error(err.stack);
Expand Down
Loading

0 comments on commit dcd5abb

Please sign in to comment.