Skip to content

Commit

Permalink
Merge pull request #59 from nuuxcode/dev
Browse files Browse the repository at this point in the history
Merge to production
  • Loading branch information
nuuxcode authored Dec 20, 2023
2 parents 1860f0c + 06fb7c3 commit 0c51865
Show file tree
Hide file tree
Showing 16 changed files with 175 additions and 59 deletions.
40 changes: 32 additions & 8 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
name: Deploy PROD
env:
JWT_SIGNATURE: ${{ vars.JWT_SIGNATURE }}
CORS_ALLOW_URL: ${{ vars.CORS_ALLOW_URL }}
API_PORT: ${{ vars.API_PORT }}
CLIENT_ID: ${{ vars.CLIENT_ID }}
CLIENT_SECRET: ${{ vars.CLIENT_SECRET }}
name: Deploy DEV
on:
push:
branches:
Expand All @@ -30,9 +24,17 @@ jobs:
with:
host: ${{ env.SERVER_HOST }}
username: ${{ env.SERVER_USERNAME }}
key: ${{ vars.SSH_PRIVATE_KEY }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ vars.SSH_PORT }}
script: |
export DATABASE_URL=${{ secrets.DATABASE_URL }}
export DATABASE_URL_LOCAL=${{ secrets.DATABASE_URL_LOCAL }}
export DATABASE_URL_DEV=${{ secrets.DEV_PDATABASE_URL }}
export DATABASE_URL_PROD=${{ secrets.PROD_PDATABASE_URL }}
export POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}
export JWT_SIGNATURE=${{ secrets.JWT_SIGNATURE }}
export CLIENT_ID=${{ secrets.CLIENT_ID }}
export CLIENT_SECRET=${{ secrets.CLIENT_SECRET }}
echo "--------"
echo "### CMD: cd BikeHub"
cd BikeHub
Expand Down Expand Up @@ -67,23 +69,34 @@ jobs:
echo "--------"
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
echo "start deploying in ${{ github.ref }}"
echo "### CMD: change VITE_MODE to prod"
sed -i 's/^VITE_MODE=.*/VITE_MODE=prod/' ~/BikeHub/frontend/.env
echo "Done!"
echo "### CMD: change DB_MODE/NODE_ENV to local"
sed -i 's/^NODE_ENV=.*/NODE_ENV=prod/' ~/BikeHub/api/.env
sed -i 's/^DB_MODE=.*/DB_MODE=local/' ~/BikeHub/api/.env
echo "Done!"
echo "### CMD: cd ~/BikeHub/admin && yarn build"
cd ~/BikeHub/admin && yarn build
echo "### CMD: pm2 reload startadmin --update-env"
pm2 reload startadmin --update-env
echo "### CMD: cd ~/BikeHub/api && yarn build"
cd ~/BikeHub/api && yarn build
echo "### CMD: pm2 reload startapi --update-env"
pm2 reload startapi --update-env
echo "### CMD: cd ~/BikeHub/frontend && yarn build"
cd ~/BikeHub/frontend && yarn build
echo "### CMD: pm2 reload startfrontend --update-env"
pm2 reload startfrontend --update-env
echo "### CMD: pm2 reload prisma --update-env"
pm2 reload prisma --update-env
echo "### CMD: update deploy.txt"
echo "---------------------------" >> deploy.txt
echo "Date: $(date)" >> deploy.txt
Expand All @@ -101,23 +114,34 @@ jobs:
fi
if [ "${{ github.ref }}" = "refs/heads/dev" ]; then
echo "start deploying in ${{ github.ref }}"
echo "### CMD: change VITE_MODE to dev"
sed -i 's/^VITE_MODE=.*/VITE_MODE=dev/' ~/BikeHub/frontend/.env
echo "Done!"
echo "### CMD: change DB_MODE/NODE_ENV to local"
sed -i 's/^NODE_ENV=.*/NODE_ENV=dev/' ~/BikeHub/api/.env
sed -i 's/^DB_MODE=.*/DB_MODE=local/' ~/BikeHub/api/.env
echo "Done!"
echo "### CMD: cd ~/BikeHub/admin && yarn build"
cd ~/BikeHub/admin && yarn build
echo "### CMD: pm2 reload startadmin --update-env"
pm2 reload startadmin --update-env
echo "### CMD: cd ~/BikeHub/api && yarn build"
cd ~/BikeHub/api && yarn build
echo "### CMD: pm2 reload startapi --update-env"
pm2 reload startapi --update-env
echo "### CMD: cd ~/BikeHub/frontend && yarn build"
cd ~/BikeHub/frontend && yarn build
echo "### CMD: pm2 reload startfrontend --update-env"
pm2 reload startfrontend --update-env
echo "### CMD: pm2 reload prisma --update-env"
pm2 reload prisma --update-env
echo "### CMD: update deploy.txt"
echo "---------------------------" >> deploy.txt
echo "Date: $(date)" >> deploy.txt
Expand Down
16 changes: 10 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
name: CI
env:
JWT_SIGNATURE: ${{ vars.JWT_SIGNATURE }}
CORS_ALLOW_URL: ${{ vars.CORS_ALLOW_URL }}
API_PORT: ${{ vars.API_PORT }}
CLIENT_ID: ${{ vars.CLIENT_ID }}
CLIENT_SECRET: ${{ vars.CLIENT_SECRET }}
on:
pull_request:
branches:
Expand All @@ -15,6 +9,15 @@ on:
jobs:
test:
runs-on: ubuntu-latest
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
DATABASE_URL_LOCAL: ${{ secrets.DATABASE_URL_LOCAL }}
DATABASE_URL_DEV: ${{ secrets.DEV_PDATABASE_URL }}
DATABASE_URL_PROD: ${{ secrets.PROD_PDATABASE_URL }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
JWT_SIGNATURE: ${{ secrets.JWT_SIGNATURE }}
CLIENT_ID: ${{ secrets.CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand Down Expand Up @@ -52,6 +55,7 @@ jobs:
- name: start api
run: |
cd api
cp .env.example .env
yarn build
yarn start:prod > api.log 2>&1 &
- name: Wait for API to start
Expand Down
20 changes: 10 additions & 10 deletions api/.env.example
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Database
POSTGRES_USER=bikehub
POSTGRES_PASSWORD=Bike-Hub
#POSTGRES_PASSWORD=
POSTGRES_DB=bikehub
DATABASE_URL=postgresql://bikehub:Bike-Hub@localhost:5432/bikehub?schema=public
DATABASE_URL_LOCAL=postgresql://bikehub:Bike-Hub@localhost:5432/bikehub?schema=public
DATABASE_URL_DEV=postgresql://bikehub:[email protected]:5432/bikehub?schema=public
DATABASE_URL_PROD=postgresql://bikehub:[email protected]:5432/bikehub?schema=public
#DATABASE_URL=
#DATABASE_URL_LOCAL=
#DATABASE_URL_DEV=
#DATABASE_URL_PROD=
# JWT
JWT_SIGNATURE=secret123456789
#JWT_SIGNATURE=
# CORS
CORS_ALLOW_URL=http://localhost:3002,https://localhost:3002,http://localhost:3000,http://34.175.134.108:*,http://142.93.105.168:*,https://localhost:3000,https://34.175.134.108:*,https://142.93.105.168:*,http://dev.bikehub.me,http://bikehub.me,https://dev.bikehub.me,https://bikehub.me
# API
Expand All @@ -17,16 +17,16 @@ BASE_URL_PROD=https://bikehub.me
BASE_URL_DEV=https://dev.bikehub.me
BASE_URL_LOCAL=http://localhost:3000
BASE_URL_API_LOCAL=http://localhost:3300
# Google OAuth
CLIENT_ID=1056307988139-cdpr08sgvae8m8r6ns8oh5cdd7akuo79.apps.googleusercontent.com
CLIENT_SECRET=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
# Google OAuth (manualy add in from server)
#CLIENT_ID=
#CLIENT_SECRET=
# dev OR prod OR local
NODE_ENV=local
# dev OR prod OR local
DB_MODE=dev
# email (manualy add in from server)
#EMAIL_USERNAME=
#EMAIL_PASSWORD=
# paypal
# paypal (manualy add in from server)
#PAYPAL_CLIENT_ID=
#PAYPAL_CLIENT_SECRET=
7 changes: 5 additions & 2 deletions api/src/modules/rental/rental.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { CreateRentalDto, UpdateRentalDto } from './rental.dto';
@ApiTags('rentals')
@Controller('/rentals')
export class RentalController {
constructor(private rentalService: RentalService) {}
constructor(private rentalService: RentalService) { }

@Get('/')
@Roles(ROLES_ENUM.ADMIN)
Expand Down Expand Up @@ -52,7 +52,10 @@ export class RentalController {
async getRentalsByUser(
@Param('id') id: string,
): Promise<RentalModel[]> {
return this.rentalService.findAll({ where: { user_id: Number(id) } });
return this.rentalService.findAll({
where: { user_id: Number(id) },
orderBy: { created_at: 'desc' }
});
}


Expand Down
18 changes: 9 additions & 9 deletions frontend/src/components/auth/loginForm/loginForm.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
Text,
InputRightElement,
InputGroup,
Toast,
useToast,
} from "@chakra-ui/react";
import { useAuth } from "../../../hooks/useAuth";

Expand All @@ -27,7 +27,7 @@ interface LoginCredentials {
const LoginForm: React.FC = () => {
const navigate = useNavigate();
const stateLocation = useLocation().state;

const toast = useToast({ position: "top" });
const { login } = useAuth();
const [data, setData] = useState<LoginCredentials>({
email: "",
Expand Down Expand Up @@ -99,17 +99,17 @@ const LoginForm: React.FC = () => {
setErrMsg("");
setIsSubmitting(false);
navigate(stateLocation?.from ? stateLocation.from : "/");
Toast({
title: "Account deleted",
description: "Your account has been deleted.",
toast({
title: "Login Successful",
description: "You have successfully logged in.",
status: "success",
duration: 5000,
duration: 2000,
isClosable: true,
});
} catch (error: any) {
if (!error?.response) {
setErrMsg("Something went wrong. Please try again later.");
Toast({
toast({
title: "Error",
description: "Something went wrong. Please try again later.",
status: "error",
Expand All @@ -118,7 +118,7 @@ const LoginForm: React.FC = () => {
});
} else if (error.response?.status === 400) {
setErrMsg(error.response.data?.message[0]);
Toast({
toast({
title: "Error",
description: error.response.data?.message[0],
status: "error",
Expand All @@ -127,7 +127,7 @@ const LoginForm: React.FC = () => {
});
} else if (error.response?.status === 401) {
setErrMsg(error.response.data?.message);
Toast({
toast({
title: "Error",
description: error.response.data?.message[0],
status: "error",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
FormErrorMessage,
Text,
Flex,
useToast,
InputGroup,
InputRightElement,
InputLeftElement,
Expand All @@ -30,7 +31,7 @@ const RegisterForm: React.FC = () => {
const navigate = useNavigate();
const { user } = useAuth();
const [confirmPassword, setConfirmPassword] = useState("");

const toast = useToast({ position: "top" });
const [data, setData] = useState<RegisterCredentials>({
name: "",
email: "",
Expand Down Expand Up @@ -104,15 +105,26 @@ const RegisterForm: React.FC = () => {
setData({ email: "", password: "", name: "", birthdate: "", phone: "" });
setErrMsg("");
navigate("/login");
toast.success("Successfully created!");
toast({
title: "Account created.",
description: "Your account has been successfully created.",
status: "success",
duration: 2500,
isClosable: true,
});
} catch (error: any) {
console.log(error);
let errorMessage = error?.response?.data?.message;
if (typeof errorMessage === "string")
errorMessage = error?.response?.data?.message;
else errorMessage = error?.response?.data?.message.join(", ");

toast.error(errorMessage);
toast({
title: "Error",
description: errorMessage,
status: "error",
duration: 5000,
isClosable: true,
});
if (!error?.response) {
setErrMsg("Something went wrong. Please try again later.");
} else if (error.response?.status === 400) {
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/components/footer/footer.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,28 @@ const Footer = () => {
</Button>
</A>
))}
<A href="https://github.com/nuuxcode/BikeHub/#team-and-roles" isExternal>
<Button
paddingStart={0}
paddingEnd={0}
className="group hover:text-teal-500 focus:text-teal-500"
variant="nav"
_hover={{ transition: "all 0.3s ease-in-out" }}
pos={"relative"}
size={{ base: "sm", md: "md" }}
>
Our Team
<Box
position={"absolute"}
className="w-0 h-[2px] bg-teal-500 rounded-xl bottom-0 left-0"
_groupFocus={{ width: "100%" }}
_groupHover={{
width: "100%",
transition: "all 0.3s ease-in-out",
}}
/>
</Button>
</A>
</Flex>
</div>
<hr className="my-6 border-gray-200 sm:mx-auto dark:border-gray-700 lg:my-8" />
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/components/header/header.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,28 @@ const Header: React.FC = () => {
</Button>
</A>
))}
<A href="https://github.com/nuuxcode/BikeHub/#team-and-roles" isExternal>
<Button
paddingStart={0}
paddingEnd={0}
className="group hover:text-teal-500 focus:text-teal-500"
variant="nav"
_hover={{ transition: "all 0.3s ease-in-out" }}
pos={"relative"}
size={{ base: "sm", md: "md" }}
>
Our Team
<Box
position={"absolute"}
className="w-0 h-[2px] bg-teal-500 rounded-xl bottom-0 left-0"
_groupFocus={{ width: "100%" }}
_groupHover={{
width: "100%",
transition: "all 0.3s ease-in-out",
}}
/>
</Button>
</A>
</HStack>

<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const CardSteps = ({ Icon, title, text, after, delay = 0.5 }: Props) => {
}}
initial="hidden"
animate={mainControls}
transition={{ duration: 1, delay: delay }}
transition={{ duration: 0.5, delay: delay }}
>
<Box width={{ base: "100%", sm: "250px" }} display="flex" flexDirection="column" justifyContent="center" alignItems="center" gap={4}>
<Center
Expand Down
Loading

0 comments on commit 0c51865

Please sign in to comment.