Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: several json returns, updated to work better with front end #34

Merged
merged 1 commit into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,67 @@ jobs:
- name: Build
run: npm run build

- name: Prepare and clean server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_KEY }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
script: |
# Create a backup directory if it doesn't exist
mkdir -p /home/wooster/backend/backup

# Stop the server
pm2 stop wooster-server || true

# Backup current version (just in case)
timestamp=$(date +%Y%m%d_%H%M%S)
tar -czf /home/wooster/backend/backup/backup_${timestamp}.tar.gz /home/wooster/backend/dist /home/wooster/backend/src || true

# Clean the deployment directory while preserving important files
cd /home/wooster/backend
find . -mindepth 1 -maxdepth 1 \
! -name 'node_modules' \
! -name '.env' \
! -name 'backup' \
! -name 'logs' \
! -name 'pm2' \
-exec rm -rf {} +

- name: Deploy to server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_KEY }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
source: './'
source: '.,!node_modules,!.git,!.github,!backup,!test,!.env,!.env.*'
target: '/home/wooster/backend'
strip_components: 0

- name: Restart application
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_KEY }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
script: |
cd /home/wooster/backend

# Install production dependencies if needed
npm ci --production

# Ensure correct permissions
chmod +x dist/index.js

# Restart the application
pm2 restart wooster-server || pm2 start dist/index.js --name wooster-server

# Save PM2 config
pm2 save

# Clean old backups (keep last 5)
cd backup
ls -t | tail -n +6 | xargs -r rm --
5 changes: 4 additions & 1 deletion src/controllers/destinations/get-all-destinations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ import { fetchDestinations } from '../../services/destination-service';

export const handleGetDestinations = async (_req: Request, res: Response) => {
const destinations = await fetchDestinations();
res.json(destinations);
res.json({
message: 'Fetched destinations successfully',
destinations,
});
};
5 changes: 4 additions & 1 deletion src/controllers/destinations/get-destination-activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@
);
logger.info({ count: activities.length }, 'Activities fetched');

return res.json(activities);
return res.json({

Check warning on line 27 in src/controllers/destinations/get-destination-activities.ts

View check run for this annotation

Codecov / codecov/patch

src/controllers/destinations/get-destination-activities.ts#L27

Added line #L27 was not covered by tests
activities: activities,
message: 'Activities fetched successfully',
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ describe('Destination API', () => {
.get('/api/destinations')
.set('Authorization', authHeader)
.expect(200);
const destinationsRes = response.body.destinations;
console.log(destinationsRes);
expect(destinationsRes).toBeInstanceOf(Array);
expect(destinationsRes.length).toBe(2);

expect(response.body).toBeInstanceOf(Array);
expect(response.body.length).toBe(2);

expect(response.body[0]).toEqual(
expect(destinationsRes[0]).toEqual(
expect.objectContaining({
destinationId: expect.any(Number),
destinationName: expect.any(String),
Expand Down Expand Up @@ -248,7 +249,7 @@ describe('Destination API', () => {
.get('/api/destinations')
.set('Authorization', authHeader);

expect(getResponse.body).toEqual([]);
expect(getResponse.body.destinations).toEqual([]);
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import pino from 'pino';

export const logger = pino({
level:
process.env.NODE_ENV === 'test' ? 'error' : process.env.LOG_LEVEL || 'info',
process.env.NODE_ENV === 'test' ? 'debug' : process.env.LOG_LEVEL || 'info',
...(process.env.NODE_ENV === 'development'
? {
transport: {
Expand Down