Skip to content

Commit

Permalink
Merge pull request #406 from bluewave-labs/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
erenfn authored Dec 20, 2024
2 parents 94a90d7 + f13ddd2 commit c203d9c
Show file tree
Hide file tree
Showing 184 changed files with 23,740 additions and 5,349 deletions.
Binary file modified .DS_Store
Binary file not shown.
46 changes: 23 additions & 23 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
check-latest: true

# Clear npm cache
- name: Clear npm cache
Expand All @@ -43,23 +44,23 @@ jobs:
run: |
rm -rf ./frontend/node_modules ./frontend/package-lock.json
# Cache backend dependencies
- name: Cache backend dependencies
uses: actions/cache@v3
with:
path: ./backend/node_modules
key: backend-node-modules-${{ matrix.node-version }}-${{ hashFiles('backend/package-lock.json') }}
restore-keys: |
backend-node-modules-${{ matrix.node-version }}-
# Cache frontend dependencies
- name: Cache frontend dependencies
uses: actions/cache@v3
with:
path: ./frontend/node_modules
key: frontend-node-modules-${{ matrix.node-version }}-${{ hashFiles('frontend/package-lock.json') }}
restore-keys: |
frontend-node-modules-${{ matrix.node-version }}-
# # Cache backend dependencies
# - name: Cache backend dependencies
# uses: actions/cache@v3
# with:
# path: ./backend/node_modules
# key: backend-node-modules-${{ matrix.node-version }}-${{ hashFiles('backend/package-lock.json') }}
# restore-keys: |
# backend-node-modules-${{ matrix.node-version }}-

# # Cache frontend dependencies
# - name: Cache frontend dependencies
# uses: actions/cache@v3
# with:
# path: ./frontend/node_modules
# key: frontend-node-modules-${{ matrix.node-version }}-${{ hashFiles('frontend/package-lock.json') }}
# restore-keys: |
# frontend-node-modules-${{ matrix.node-version }}-

- name: Install dependencies for backend
working-directory: ./backend
Expand Down Expand Up @@ -87,14 +88,13 @@ jobs:
working-directory: ./frontend
run: npm run build --if-present

# Uncomment the following lines to run tests
# - name: Run tests for backend
# working-directory: ./backend
# run: npm test

- name: Run tests for frontend
working-directory: ./frontend
run: npm test

- name: Run tests for backend
working-directory: ./backend
run: npm test

- name: Run Docker container
run: docker compose up --build -d
run: docker compose up --build -d
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ All types of contributions are encouraged and valued. See the [Table of Contents
> - Refer this project in your project's readme
> - Mention the project at local meetups and tell your friends/colleagues

## Table of Contents

- [I Have a Question](#i-have-a-question)
Expand Down
Binary file added backend/.DS_Store
Binary file not shown.
9 changes: 7 additions & 2 deletions backend/.env
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ JWT_SECRET="NKrbO2lpCsOpVAlqAPsjZ0tZXzIoKru7gAmYZ7XlHn0=qqwqeq"

TEST_DB_USERNAME=user123
TEST_DB_PASSWORD=password123
TEST_DB_NAME=onboarding_db
TEST_DB_NAME=onboarding_db_test
TEST_DB_HOST=localhost
TEST_DB_PORT=5432
TEST_DB_PORT=5432

# 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
ALLOWED_IPS=127.0.0.1, 11.22.33.44, 11.22.33.45, 11.22.33.46, 192.168.65.1
5 changes: 5 additions & 0 deletions backend/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ PROD_DB_PORT=5432

# JWT Secret Key
JWT_SECRET=your_prod_jwt_secret_key_here

# 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
ALLOWED_IPS=11.22.33.44, 11.22.33.45, 11.22.33.46
15 changes: 12 additions & 3 deletions backend/.env.test
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
# Test Environment Configuration

# Database Configuration
TEST_DB_USERNAME=test_user
TEST_DB_PASSWORD=test_password
TEST_DB_NAME=test_db
TEST_DB_USERNAME=user123
TEST_DB_PASSWORD=password123
TEST_DB_NAME=onboarding_db_test
TEST_DB_HOST=localhost
TEST_DB_PORT=5432

POSTGRES_USER=user123
POSTGRES_PASSWORD=password123
POSTGRES_DB=onboarding_db_test

# JWT Secret Key
JWT_SECRET=your_test_jwt_secret_key_here

# 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
ALLOWED_IPS=127.0.0.1, 11.22.33.44, 11.22.33.45, 11.22.33.46, 192.168.65.1
1 change: 1 addition & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules/
.env
logs/
dist/
.nyc_output
6 changes: 4 additions & 2 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
FROM node:22
FROM node:22-alpine3.21

RUN apk update && apk add bash && rm -rf /var/cache/apk/*

WORKDIR /app

COPY package*.json ./
COPY package.json ./

RUN npm install

Expand Down
4 changes: 4 additions & 0 deletions backend/config/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ module.exports = {
update: [userRole.ADMIN],
changeRole: [userRole.ADMIN],
setOrg: [userRole.ADMIN],
serverUrl: [userRole.ADMIN],
popups: [userRole.ADMIN],
hints: [userRole.ADMIN],
banners: [userRole.ADMIN],
links: [userRole.ADMIN],
tours: [userRole.ADMIN],
helpers: [userRole.ADMIN],
}
}
};
63 changes: 1 addition & 62 deletions backend/index.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,4 @@
const express = require('express');
const cors = require('cors');
const helmet = require('helmet');
const dotenv = require('dotenv');
const bodyParser = require('body-parser');
const jsonErrorMiddleware = require('./src/middleware/jsonError.middleware');
const fileSizeValidator = require('./src/middleware/fileSizeValidator.middleware');
const { MAX_FILE_SIZE } = require('./src/utils/constants.helper');

// Load environment variables from .env file
dotenv.config();

const authRoutes = require('./src/routes/auth.routes');
const userRoutes = require('./src/routes/user.routes');
const mocks = require('./src/routes/mocks.routes');
const popup = require('./src/routes/popup.routes');
const popup_log = require('./src/routes/popuplog.routes');
const banner = require('./src/routes/banner.routes');
const teamRoutes = require('./src/routes/team.routes');
const hint = require('./src/routes/hint.routes');
const tourRoutes = require('./src/routes/tour.routes');
const linkRoutes = require('./src/routes/link.routes');
const helperLinkRoutes = require('./src/routes/helperLink.routes');

const app = express();

app.use(cors());
app.use(helmet());
app.use(bodyParser.json({ limit: MAX_FILE_SIZE }));
app.use(jsonErrorMiddleware);
// app.use(fileSizeValidator);

const { sequelize, Team } = require("./src/models");
const config = require("./config/config");

sequelize
.authenticate()
.then(() => console.log('Database connected...'))
.catch((err) => console.log('Error: ' + err));

sequelize
.sync({ force: true })
.then(() => console.log("Models synced with the database..."))
.catch((err) => console.log("Error syncing models: " + err));

app.use('/api/auth', authRoutes);
app.use('/api/users', userRoutes);
app.use('/api/mock/', mocks);
app.use('/api/popup', popup);
app.use('/api/popup_log', popup_log);
app.use('/api/banner', banner);
app.use('/api/team', teamRoutes);
// app.use('/api/tours', tourRoutes);
app.use('/api/hint', hint);
app.use('/api/tour', tourRoutes);
app.use('/api/link', linkRoutes);
app.use('/api/helper-link', helperLinkRoutes);

app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).json({ message: 'Internal Server Error' });
});
const app = require("./src/server");

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
Expand Down
4 changes: 0 additions & 4 deletions backend/migrations/20240916052017-create_teams_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ module.exports = {
defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
},
});

await queryInterface.bulkInsert("teams", [{
name: config.defaultTeamName
}]);
},

down: async (queryInterface, Sequelize) => {
Expand Down
99 changes: 99 additions & 0 deletions backend/migrations/20241203005208-change-popup-log-to-guide-log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
'use strict';
/** @type {import('sequelize-cli').Migration} */
module.exports = {
up: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.renameTable('popup_logs', 'guide_logs', { transaction });
await queryInterface.renameColumn('guide_logs', 'popupType', 'guideType', { transaction });

await queryInterface.sequelize.query(`
ALTER TABLE "guide_logs"
ALTER COLUMN "guideType" TYPE INTEGER
USING
CASE
WHEN "guideType" = 'guide' THEN 1
WHEN "guideType" = 'tooltip' THEN 2
WHEN "guideType" = 'hotspot' THEN 3
WHEN "guideType" = 'checklist' THEN 4
ELSE 9
END
`, { transaction });

await queryInterface.changeColumn('guide_logs', 'guideType', {
type: Sequelize.INTEGER,
allowNull: false,
}, { transaction });

await queryInterface.addColumn('guide_logs', 'guideId', {
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 0,
}, { transaction });

await queryInterface.addIndex('guide_logs', ['userId'], {
name: 'idx_guide_logs_userId',
transaction,
});
await queryInterface.addIndex('guide_logs', ['guideId'], {
name: 'idx_guide_logs_guideId',
transaction,
});
await queryInterface.addIndex('guide_logs', ['guideType'], {
name: 'idx_guide_logs_guideType',
transaction,
});
await queryInterface.addIndex('guide_logs', ['userId', 'guideId', 'guideType'], {
name: 'idx_guide_logs_userId_guideId_guideType',
unique: false,
transaction,
});

await transaction.commit();
} catch (error) {
await transaction.rollback();
throw error;
}
},

down: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.renameTable('guide_logs', 'popup_logs', { transaction });
await queryInterface.renameColumn('popup_logs', 'guideType', 'popupType', { transaction });

await queryInterface.sequelize.query(`
ALTER TABLE "popup_logs"
ALTER COLUMN "popupType" TYPE VARCHAR(255)
USING
CASE
WHEN "popupType" = 1 THEN 'guide'
WHEN "popupType" = 2 THEN 'tooltip'
WHEN "popupType" = 3 THEN 'hotspot'
WHEN "popupType" = 4 THEN 'checklist'
ELSE 'guide'
END
`, { transaction });

await queryInterface.changeColumn('popup_logs', 'popupType', {
type: Sequelize.STRING,
allowNull: false,
validate: {
isIn: [['guide', 'tooltip', 'hotspot', 'checklist']],
}
}, { transaction });

await queryInterface.removeColumn('popup_logs', 'guideId', { transaction });

await queryInterface.removeIndex('popup_logs', 'idx_guide_logs_userId', { transaction });
await queryInterface.removeIndex('popup_logs', 'idx_guide_logs_guideId', { transaction });
await queryInterface.removeIndex('popup_logs', 'idx_guide_logs_guideType', { transaction });
await queryInterface.removeIndex('popup_logs', 'idx_guide_logs_userId_guideId_guideType', { transaction });

await transaction.commit();
} catch (error) {
await transaction.rollback();
throw error;
}
},
};
18 changes: 18 additions & 0 deletions backend/migrations/20241210225728-add-action-url-banner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use strict";

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.addColumn("banners", "actionUrl", {
type: Sequelize.STRING,
allowNull: true,
validate: {
isUrl: true,
},
});
},

async down(queryInterface, Sequelize) {
await queryInterface.removeColumn("banners", "actionUrl");
},
};
18 changes: 18 additions & 0 deletions backend/migrations/20241210225734-add-action-url-popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use strict";

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.addColumn("popup", "actionUrl", {
type: Sequelize.STRING,
allowNull: true,
validate: {
isUrl: true,
},
});
},

async down(queryInterface, Sequelize) {
await queryInterface.removeColumn("popup", "actionUrl");
},
};
14 changes: 14 additions & 0 deletions backend/migrations/20241216195934-server_url_col_team_rel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

module.exports = {
async up (queryInterface, Sequelize) {
await queryInterface.addColumn('teams', 'serverUrl', {
type: Sequelize.STRING(255),
allowNull: true,
})
},

async down (queryInterface, Sequelize) {
await queryInterface.removeColumn('teams', 'serverUrl')
}
};
Loading

0 comments on commit c203d9c

Please sign in to comment.