Skip to content

Commit

Permalink
Merge branch 'main' into user_favs
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseAlbDR authored Feb 16, 2024
2 parents 6f0895c + 626ce6b commit bb6570e
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 27 deletions.
46 changes: 22 additions & 24 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,8 @@ on:
env:
DOCKER_USER: ${{ secrets.DOCKER_USER }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}

jobs:

# test:
# name: Jest Tests
# runs-on: ubuntu-latest

# steps:
# - name: Checkout code
# uses: actions/checkout@v3

# - name: Set up NodeJS
# uses: actions/setup-node@v1
# with:
# node-version: 20

# - name: Install all dependencies
# run: npm install

# - name: Run Tests
# run: npm test

build:
runs-on: ubuntu-latest

Expand All @@ -40,6 +20,14 @@ jobs:
with:
fetch-depth: 0

- name: Git Semantic Version
uses: PaulHatch/semantic-version@v5.4.0
with:
major_pattern: "major:"
minor_pattern: "feat:"
version_format: "${major}.${minor}.${patch}-prerelease${increment}"
id: version

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

Expand All @@ -49,6 +37,16 @@ jobs:
username: ${{ env.DOCKER_USER }}
password: ${{ env.DOCKER_PASSWORD }}

- name: Build and push Docker Image
uses: docker/build-push-action@v2
env:
NEW_VERSION: ${{ steps.version.outputs.version }}
with:
context: ./
push: true
dockerfile: ./Dockerfile
tags: jaderodev/aup-backend:${{ env.NEW_VERSION }}

- name: Build and push Docker Image
uses: docker/build-push-action@v2
with:
Expand Down Expand Up @@ -77,15 +75,15 @@ jobs:
- name: Move to project folder
run: |
ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@3.82.157.13 'cd backend/ && sudo docker compose down'
ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@3.228.164.55 'cd backend/ && sudo docker compose down'
- name: Remove old image
run: |
ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@3.82.157.13 'sudo docker image rm -f backend-aup-backend:latest'
ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@3.228.164.55 'sudo docker image rm -f backend-aup-backend:latest'
- name: Run new containers
run: |
ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@3.82.157.13 'cd backend/ && git pull && sudo docker compose up -d'
ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@3.228.164.55 'cd backend/ && git pull && sudo docker compose up -d'


5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ services:
RABBITMQ_USER: ${RABBITMQ_USER}
RABBITMQ_PASS: ${RABBITMQ_PASS}
RABBITMQ_URL: ${RABBITMQ_URL}
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
AWS_REGION: ${AWS_REGION}
AWS_BUCKET: ${AWS_BUCKET}
AWS_BUCKET_URL: ${AWS_BUCKET_URL}

proxy:
build: ./nginx
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Animal" ADD COLUMN "numFavs" INTEGER NOT NULL DEFAULT 0;
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ model Animal {
numFavs Int @default(0)
images String[]
easyTrain Boolean
numFavs Int @default(0)
energyLevel energy
moltingAmount molting
status status_pet @default(awaiting_home)
Expand Down
6 changes: 6 additions & 0 deletions src/presentation/animals/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ export class AnimalRoutes {
animalController.delete
);

router.post(
'/:id/add-favorite',
authMiddleware.authenticateUser,
animalController.addToFavorites
);

return router;
}
}
5 changes: 2 additions & 3 deletions src/presentation/services/animal.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,12 @@ export class AnimalService {

const updateQuery = this.buildQuery(updateAnimalDto);

console.log({ updateQuery });

const updatedAnimal = await prisma.animal.update({
where: { id: animal.id },
data: updateQuery,
});

return 'Update Animal';
return updatedAnimal;
}

public async delete(user: PayloadUser, term: string) {
Expand Down Expand Up @@ -302,6 +300,7 @@ export class AnimalService {
}

public async addFavorite(userId: string, animalId: string) {

const animal = await prisma.animal.findUnique({ where: { id: animalId } });

if (!animal) throw new NotFoundError('Animal not found');
Expand Down

0 comments on commit bb6570e

Please sign in to comment.