Skip to content

Commit

Permalink
Merge pull request #15 from mslfh/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
mslfh authored Oct 6, 2024
2 parents 352cded + 2143ee5 commit 8479f1a
Show file tree
Hide file tree
Showing 26 changed files with 520 additions and 212 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ githubinfo.txt
uidesign.pptx
videos.txt
server_sec.txt
.env
6 changes: 4 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ DATABASE_DIALECT=mysql
DATABASE_NAME=adminjs
DATABASE_HOST=localhost
DATABASE_USER=root
DATABASE_PASSWORD=adminjs
DATABASE_PASSWORD=12345abc
COOKIE_SECRET=QmutO5X71dgE4p8GiU57YAxMCb6f6vm9
SESSION_SECRET=6f8e023b1f1a4b32a915aa7f6725f3d1
PORT=5000
ORIGIN=https://localhost:5000

RP_NAME=exertime_application
RP_ID=localhost
TIMEOUT_MS=60000
COOKIE_MAX_AGE=86400000 # 1 day in milliseconds
JWT_SECRET=9a0b0cc4b03b47c9a1c8c16f7a0569a6
JWT_EXPIRATION=1h

#Quasar-xt Frontend Address
FRONTEND_ORIGIN=https://localhost:9000
29 changes: 18 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,29 @@ FROM node:20

WORKDIR /admin

#ENV NODE_ENV="production"
# Set timezone
ENV TZ="UTC"

COPY package.json ./
#COPY yarn.lock ./
# Install netcat-openbsd
RUN apt-get update && apt-get install -y netcat-openbsd

#RUN yarn install --frozen-lockfile --production
RUN yarn install
COPY . .
# Copy package.json and package-lock.json
COPY package.json package-lock.json ./

# Install dependencies using npm
RUN npm install

# Install Typescript globally
RUN npm i -g typescript
RUN yarn build
#RUN npx prisma generate
#RUN rm -rf src

#ENV ADMIN_JS_SKIP_BUNDLE="true"
# Copy the rest of the application
COPY . .

# Build the project using npm
RUN npm run build

# Expose port 5000
EXPOSE 5000
CMD yarn start

# Start the application using npm
CMD ["npm", "run", "start"]
66 changes: 46 additions & 20 deletions adminjs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Target Server Version : 80039
File Encoding : 65001
Date: 11/09/2024 18:30:36
Date: 26/09/2024 13:23:59
*/

SET NAMES utf8mb4;
Expand Down Expand Up @@ -85,7 +85,7 @@ CREATE TABLE `exercise` (
`ID` int UNSIGNED NOT NULL AUTO_INCREMENT,
`Caption` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`Status` enum('A','I','D') CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`Type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`Type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'repetition / duration',
`CategoryID` int NULL DEFAULT NULL,
`Image` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL,
`VideoURL` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL,
Expand Down Expand Up @@ -230,26 +230,32 @@ CREATE TABLE `exercise_log_question` (
DROP TABLE IF EXISTS `exercise_plan`;
CREATE TABLE `exercise_plan` (
`ID` int UNSIGNED NOT NULL AUTO_INCREMENT,
`Title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`Subject` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`ContentType` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`Content` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`OrganisationID` int NULL DEFAULT NULL,
`DepartmentID` int NULL DEFAULT NULL COMMENT 'optional',
`Status` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`Description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`Type` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`Status` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'active/inactive',
`Type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`Frequency` varchar(48) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'Day, WorkingDay, Weekend, Custom',
`CustomFrequency` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`StartDate` datetime NULL DEFAULT NULL,
`EndDate` datetime NULL DEFAULT NULL,
`Level` int NULL DEFAULT NULL,
`Priority` int NULL DEFAULT NULL,
`CustomFrequency` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'Mon,Tues,......',
`IsAllDay` tinyint NULL DEFAULT NULL COMMENT '1-yes 0-no',
`Intervals` int NULL DEFAULT NULL COMMENT 'minutes of interval between workout sessions',
`StartTimeZone` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`StartDateTime` datetime NULL DEFAULT NULL,
`EndTimeZone` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`EndDateTime` datetime NULL DEFAULT NULL,
`Priority` int NULL DEFAULT NULL COMMENT '0-highest',
`Attendees` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'emailAddress for Attendees',
`Remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`CreatedAt` datetime NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of exercise_plan
-- ----------------------------
INSERT INTO `exercise_plan` VALUES (1, 'DefaultPlan', 1, NULL, 'active', NULL, 'default', 'Day', NULL, '2024-08-14 21:37:15', '2025-01-01 21:37:24', 1, 1, '2024-08-13 21:37:37');
INSERT INTO `exercise_plan` VALUES (1, 'DefaultPlan', NULL, NULL, 1, NULL, 'active', 'default', 'Day', NULL, NULL, NULL, NULL, '2024-08-14 21:37:15', NULL, '2025-01-01 21:37:24', 1, NULL, NULL, '2024-08-13 21:37:37');

-- ----------------------------
-- Table structure for helpful_hint
Expand All @@ -271,6 +277,26 @@ CREATE TABLE `helpful_hint` (
INSERT INTO `helpful_hint` VALUES (1, 'edasdas', 122, 2);
INSERT INTO `helpful_hint` VALUES (2, 'hello', 0, 2);

-- ----------------------------
-- Table structure for microsoft_account
-- ----------------------------
DROP TABLE IF EXISTS `microsoft_account`;
CREATE TABLE `microsoft_account` (
`ID` int UNSIGNED NOT NULL AUTO_INCREMENT,
`UserID` char(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`microsoftEmail` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`oid` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`sub` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`isLinked` tinyint(1) NULL DEFAULT 0,
PRIMARY KEY (`ID`) USING BTREE,
INDEX `UserID`(`UserID` ASC) USING BTREE,
CONSTRAINT `microsoft_account_ibfk_1` FOREIGN KEY (`UserID`) REFERENCES `user` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of microsoft_account
-- ----------------------------

-- ----------------------------
-- Table structure for organisation
-- ----------------------------
Expand Down Expand Up @@ -329,7 +355,7 @@ CREATE TABLE `sessions` (
-- ----------------------------
-- Records of sessions
-- ----------------------------
INSERT INTO `sessions` VALUES ('ChARoIx1ol2d0YJIh07qrhJOs0VzCKJ6', '2024-09-12 08:27:06', '{\"cookie\":{\"originalMaxAge\":null,\"expires\":null,\"secure\":true,\"httpOnly\":true,\"path\":\"/\"},\"adminUser\":{\"email\":\"[email protected]\",\"role\":\"admin\"},\"challenge\":null}', '2024-09-11 07:07:26', '2024-09-11 08:27:06');
INSERT INTO `sessions` VALUES ('ChARoIx1ol2d0YJIh07qrhJOs0VzCKJ6', '2024-09-18 06:10:19', '{\"cookie\":{\"originalMaxAge\":null,\"expires\":null,\"secure\":true,\"httpOnly\":true,\"path\":\"/\"},\"adminUser\":{\"email\":\"[email protected]\",\"role\":\"admin\"},\"challenge\":null}', '2024-09-11 07:07:26', '2024-09-17 06:10:19');

-- ----------------------------
-- Table structure for survey_response
Expand Down Expand Up @@ -384,7 +410,7 @@ CREATE TABLE `user` (
PRIMARY KEY (`ID`) USING BTREE,
INDEX `DepartmentID`(`DepartmentID` ASC) USING BTREE,
CONSTRAINT `User_ibfk_1` FOREIGN KEY (`DepartmentID`) REFERENCES `department` (`ID`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 29 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of user
Expand All @@ -402,7 +428,7 @@ CREATE TABLE `user_event` (
`EventType` int NULL DEFAULT NULL,
PRIMARY KEY (`ID`) USING BTREE,
INDEX `UserID`(`UserID` ASC) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of user_event
Expand All @@ -421,7 +447,7 @@ CREATE TABLE `user_exercise_log` (
`Duration` double NULL DEFAULT NULL,
`CreatedAt` datetime NULL DEFAULT NULL,
PRIMARY KEY (`ID`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of user_exercise_log
Expand All @@ -438,7 +464,7 @@ CREATE TABLE `user_favorite` (
`CreatedAt` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`) USING BTREE,
INDEX `ExerciseID`(`ExerciseID` ASC) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of user_favorite
Expand All @@ -455,7 +481,7 @@ CREATE TABLE `user_position` (
`Position` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
PRIMARY KEY (`ID`) USING BTREE,
INDEX `UserID`(`UserID` ASC) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of user_position
Expand All @@ -471,7 +497,7 @@ CREATE TABLE `user_setting` (
`Content` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`Value` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
PRIMARY KEY (`ID`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = 'For store user setting like allow notification etc.' ROW_FORMAT = DYNAMIC;
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = 'For store user setting like allow notification etc.' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of user_setting
Expand All @@ -488,7 +514,7 @@ CREATE TABLE `user_weight` (
`Weight` int NULL DEFAULT NULL,
PRIMARY KEY (`ID`) USING BTREE,
INDEX `UserID`(`UserID` ASC) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of user_weight
Expand Down
36 changes: 21 additions & 15 deletions api_test_script/exercise_delay.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,53 @@

# Step 1: Log in to Admin API to generate session cookies
echo "Logging in as admin..."
curl -X POST http://localhost:5000/admin/login \
curl -X POST https://localhost:5000/admin/login \
-H "Content-Type: application/x-www-form-urlencoded" \
-d '[email protected]&password=password' \
-c cookies.txt
-c cookies.txt \
-k # This option skips SSL verification if necessary; remove if not needed

# Step 2: Create a new exercise delay
echo "Creating a new exercise delay..."
curl -X POST http://localhost:5000/admin/api/resources/exercise_delay/actions/new \
curl -X POST https://localhost:5000/admin/api/resources/exercise_delay/actions/new \
-b cookies.txt \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'Duration=30&DateTime=2024-09-07T14:00:00Z&ExerciseID=1&UserID=2'
-d 'Duration=30&DateTime=2024-09-07T14:00:00Z&ExerciseID=1&UserID=2' \
-k # Remove if SSL verification is not an issue

# Step 3: List all exercise delays to verify the creation
echo "Listing all exercise delays..."
curl -X GET "http://localhost:5000/admin/api/resources/exercise_delay/actions/list?direction=desc&sortBy=ID&page=1&perPage=10" \
curl -X GET "https://localhost:5000/admin/api/resources/exercise_delay/actions/list?direction=desc&sortBy=ID&page=1&perPage=10" \
-b cookies.txt \
-H "Content-Type: application/json" | jq
-H "Content-Type: application/json" | jq \
-k # Remove if SSL verification is not an issue

# Step 4: Retrieve details of a specific exercise delay (replace 1 with actual record ID from listing)
echo "Showing details of exercise delay ID=1..."
curl -X GET "http://localhost:5000/admin/api/resources/exercise_delay/records/1/show" \
curl -X GET "https://localhost:5000/admin/api/resources/exercise_delay/records/1/show" \
-b cookies.txt \
-H "Content-Type: application/json" | jq
-H "Content-Type: application/json" | jq \
-k # Remove if SSL verification is not an issue

# Step 5: Edit the exercise delay (updating the duration)
echo "Editing exercise delay with ID=1..."
curl -X POST "http://localhost:5000/admin/api/resources/exercise_delay/records/1/edit" \
curl -X POST "https://localhost:5000/admin/api/resources/exercise_delay/records/1/edit" \
-b cookies.txt \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'Duration=45'
-d 'Duration=45' \
-k # Remove if SSL verification is not an issue

# Step 6: Delete a specific exercise delay
echo "Deleting exercise delay ID=1..."
curl -X POST "http://localhost:5000/admin/api/resources/exercise_delay/records/1/delete" \
curl -X POST "https://localhost:5000/admin/api/resources/exercise_delay/records/1/delete" \
-b cookies.txt \
-H "Content-Type: application/x-www-form-urlencoded"
-H "Content-Type: application/x-www-form-urlencoded" \
-k # Remove if SSL verification is not an issue

# Step 7: Bulk delete exercise delays (IDs 2 and 3 as examples)
echo "Bulk deleting exercise delays with IDs 2 and 3..."
curl -X POST "http://localhost:5000/admin/api/resources/exercise_delay/bulk/bulkDelete" \
curl -X POST "https://localhost:5000/admin/api/resources/exercise_delay/bulk/bulkDelete" \
-b cookies.txt \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'recordIds=2&recordIds=3'

-d 'recordIds=2&recordIds=3' \
-k # Remove if SSL verification is not an issue
40 changes: 24 additions & 16 deletions api_test_script/exercise_log.sh
Original file line number Diff line number Diff line change
@@ -1,45 +1,53 @@
#!/bin/bash

# Log in and obtain the session cookies for authenticated access
curl -X POST http://localhost:5000/admin/login \
curl -X POST https://localhost:5000/admin/login \
-H "Content-Type: application/x-www-form-urlencoded" \
-d '[email protected]&password=password' \
-c cookies.txt
-c cookies.txt \
-k

# List all exercise log records with pagination and sorting
curl -X GET "http://localhost:5000/admin/api/resources/exercise_log/actions/list?direction=desc&sortBy=ID&page=1&perPage=10" \
curl -X GET "https://localhost:5000/admin/api/resources/exercise_log/actions/list?direction=desc&sortBy=ID&page=1&perPage=10" \
-b cookies.txt \
-H "Content-Type: application/json" | jq
-H "Content-Type: application/json" \
-k | jq

# Create a new exercise log entry
curl -X POST http://localhost:5000/admin/api/resources/exercise_log/actions/new \
curl -X POST https://localhost:5000/admin/api/resources/exercise_log/actions/new \
-b cookies.txt \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'UserID=2&ExerciseID=1&StartDateTime=2024-09-07&EndDateTime=2024-09-07&Source=M&Duration=30&Repetitions=10'
-d 'UserID=2&ExerciseID=1&StartDateTime=2024-09-07&EndDateTime=2024-09-07&Source=M&Duration=30&Repetitions=10' \
-k

# Retrieve details of a specific exercise log entry (ID=1)
curl -X GET "http://localhost:5000/admin/api/resources/exercise_log/records/1/show" \
curl -X GET "https://localhost:5000/admin/api/resources/exercise_log/records/1/show" \
-b cookies.txt \
-H "Content-Type: application/json" | jq
-H "Content-Type: application/json" \
-k | jq

# Update an existing exercise log entry (ID=1)
curl -X POST "http://localhost:5000/admin/api/resources/exercise_log/records/1/edit" \
curl -X POST "https://localhost:5000/admin/api/resources/exercise_log/records/1/edit" \
-b cookies.txt \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "Duration=60&Repetitions=15"
-d "Duration=60&Repetitions=15" \
-k

# Search for a specific exercise log entry based on filters and sort by ID
curl -X GET "http://localhost:5000/admin/api/resources/exercise_log/actions/search/3?filters.ID=1&sortBy=ID&direction=asc" \
curl -X GET "https://localhost:5000/admin/api/resources/exercise_log/actions/search/3?filters.ID=1&sortBy=ID&direction=asc" \
-b cookies.txt \
-H "Content-Type: application/x-www-form-urlencoded"
-H "Content-Type: application/x-www-form-urlencoded" \
-k

# Delete a specific exercise log entry (ID=5)
curl -X POST "http://localhost:5000/admin/api/resources/exercise_log/records/5/delete" \
curl -X POST "https://localhost:5000/admin/api/resources/exercise_log/records/5/delete" \
-b cookies.txt \
-H "Content-Type: application/x-www-form-urlencoded"
-H "Content-Type: application/x-www-form-urlencoded" \
-k

# Bulk delete multiple exercise log entries
curl -X POST "http://localhost:5000/admin/api/resources/exercise_log/bulk/bulkDelete" \
curl -X POST "https://localhost:5000/admin/api/resources/exercise_log/bulk/bulkDelete" \
-b cookies.txt \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'recordIds=1&recordIds=2&recordIds=3'
-d 'recordIds=1&recordIds=2&recordIds=3' \
-k
Loading

0 comments on commit 8479f1a

Please sign in to comment.