-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/No-Country-simulation/s1…
…7-12-t-node-react into perfilUser
- Loading branch information
Showing
158 changed files
with
7,003 additions
and
2,852 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
## TICKET | ||
|
||
- [INSERTAR NOMBRE LA ISSUE AQUI](INSERTAR DEL LINK TICKET AQUI) | ||
|
||
## Descripción | ||
|
||
Describe brevemente el cambio que has hecho. | ||
|
||
## Evidencia: | ||
|
||
### Happy Path | ||
|
||
(Poner screenshots/video/gifs aquí) | ||
|
||
### Unhappy Path | ||
|
||
(Poner screenshots/video/gifs aquí) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Deploy Backend | ||
on: | ||
pull_request: | ||
types: [closed] | ||
paths: | ||
- "backend/**" | ||
- ".github/workflows/deploy-backend.yml" | ||
|
||
jobs: | ||
deploy-backend: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: "20" | ||
|
||
- name: Install Dependencies | ||
run: | | ||
rm package-lock.json | ||
npm install | ||
# Pasos para el deploy en Railway | ||
- name: Install Railway | ||
run: npm i -g @railway/cli | ||
|
||
- name: Deploy | ||
run: npm run deploy -w backend | ||
env: | ||
RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Vercel Production Deployment | ||
env: | ||
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} | ||
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} | ||
on: | ||
push: | ||
paths: | ||
- "frontend/**" | ||
jobs: | ||
Deploy-Production: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: "18" | ||
|
||
- name: Install Vercel CLI | ||
run: npm install --global vercel@latest | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Deploy to Vercel | ||
env: | ||
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} # Configura la variable de entorno | ||
run: npm run deploy -w frontend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
node_modules | ||
mongoDataBase | ||
mongo | ||
mongoDataBase | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
NODE_ENV=development | ||
PORT=3000 | ||
|
||
DB_URI=mongodb://user:admin1@localhost:27018/ | ||
|
||
JWT_SECRET_KEY=a_secret_key_3434 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,12 @@ | |
/dist | ||
/node_modules | ||
/build | ||
/mongo-data | ||
|
||
# Customs | ||
.http | ||
compose.yml | ||
pnpm-lock.yaml | ||
|
||
# Logs | ||
logs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Oh My Trip</title> | ||
</head> | ||
<body> | ||
<h2>Welcome to the OhMyTrip API!</h2> | ||
<p>Here you will see the documentation soon.</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { | ||
Body, | ||
Controller, | ||
Delete, | ||
Get, | ||
Param, | ||
Patch, | ||
Post, | ||
Query, | ||
} from '@nestjs/common'; | ||
|
||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; | ||
import { Types } from 'mongoose'; | ||
|
||
import { GetUser } from '../auth/decorators'; | ||
import { type User } from '../user/entities/user.entity'; | ||
import { Auth } from '../auth/decorators/auth.decorator'; | ||
import { ObjectIdValidationPipe } from '../common/pipes/object-id-validation.pipe'; | ||
import { AlbumService } from './album.service'; | ||
import { CreateAlbumDto, UpdateAlbumDto } from './dto'; | ||
|
||
//! refactor in the future | ||
type UserTemporalType = User & { _id: Types.ObjectId }; | ||
|
||
@ApiTags('Album') | ||
@Controller('album') | ||
export class AlbumController { | ||
constructor(private readonly albumService: AlbumService) {} | ||
|
||
@Get('search') | ||
async searchAlbums(@Query('q') query: string) { | ||
return await this.albumService.searchAlbums(query); | ||
} | ||
|
||
@Get('all') | ||
async allAlbums() { | ||
return await this.albumService.findAllAlbums(); | ||
} | ||
|
||
@Get(':id') | ||
async findOne(@Param('id', ObjectIdValidationPipe) id: string) { | ||
return await this.albumService.findOneById(id); | ||
} | ||
|
||
@Get('user/:userId') | ||
async findAll(@Param('userId', ObjectIdValidationPipe) userId: string) { | ||
return await this.albumService.findAllByUserId(userId); | ||
} | ||
|
||
@ApiBearerAuth() | ||
@Post() | ||
@Auth() | ||
async create( | ||
@GetUser() user: UserTemporalType, | ||
@Body() createAlbumDto: CreateAlbumDto, | ||
) { | ||
return await this.albumService.create(user._id, createAlbumDto); | ||
} | ||
|
||
@ApiBearerAuth() | ||
@Patch(':id') | ||
@Auth() | ||
async update( | ||
@Param('id', ObjectIdValidationPipe) id: string, | ||
@Body() updateAlbumDto: UpdateAlbumDto, | ||
) { | ||
return await this.albumService.update(id, updateAlbumDto); | ||
} | ||
|
||
@ApiBearerAuth() | ||
@Delete(':id') | ||
@Auth() | ||
async delete(@Param('id', ObjectIdValidationPipe) id: string) { | ||
return await this.albumService.delete(id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { AlbumService } from './album.service'; | ||
import { AlbumController } from './album.controller'; | ||
import { MongooseModule } from '@nestjs/mongoose'; | ||
import { Album, AlbumSchema } from './schemas/album.schema'; | ||
import { UserModule } from 'src/user/user.module'; | ||
|
||
@Module({ | ||
imports: [ | ||
MongooseModule.forFeature([{ name: Album.name, schema: AlbumSchema }]), | ||
UserModule, | ||
], | ||
controllers: [AlbumController], | ||
providers: [AlbumService], | ||
exports: [AlbumService, MongooseModule], | ||
}) | ||
export class AlbumModule { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { Injectable, NotFoundException } from '@nestjs/common'; | ||
import { InjectModel } from '@nestjs/mongoose'; | ||
|
||
import { Model, Types } from 'mongoose'; | ||
import * as sw from 'stopword'; | ||
import { CreateAlbumDto, UpdateAlbumDto } from './dto'; | ||
import { Album } from './schemas'; | ||
import { UserService } from '../user/user.service'; | ||
|
||
@Injectable() | ||
export class AlbumService { | ||
constructor( | ||
@InjectModel(Album.name) | ||
private readonly albumModel: Model<Album>, | ||
private readonly userService: UserService, | ||
) {} | ||
|
||
async create(userId: Types.ObjectId, createAlbumDto: CreateAlbumDto) { | ||
const createdAlbum = await this.albumModel.create({ | ||
...createAlbumDto, | ||
userId: userId, | ||
}); | ||
|
||
return createdAlbum; | ||
} | ||
|
||
async update(id: string, updateAlbumDto: UpdateAlbumDto) { | ||
await this.findOneById(id); | ||
|
||
const updatedAlbum = await this.albumModel.findByIdAndUpdate( | ||
id, | ||
updateAlbumDto, | ||
{ new: true }, | ||
); | ||
|
||
return updatedAlbum; | ||
} | ||
|
||
async delete(id: string) { | ||
await this.findOneById(id); | ||
await this.albumModel.findByIdAndDelete(id); | ||
} | ||
|
||
async findOneById(id: string) { | ||
const foundAlbum = await this.albumModel.findById(id); | ||
|
||
if (!foundAlbum) throw new NotFoundException(`Album with ${id} not found`); | ||
|
||
return foundAlbum; | ||
} | ||
|
||
async findAllByUserId(userId: string) { | ||
await this.userService.findOne(userId); | ||
|
||
const userIdToObjectId = new Types.ObjectId(userId); | ||
|
||
const foundAlbums = await this.albumModel | ||
.find({ userId: userIdToObjectId }) | ||
.exec(); | ||
|
||
return foundAlbums; | ||
} | ||
|
||
async searchAlbums(query: string) { | ||
const words = query.split(' '); | ||
const significantWords = sw.removeStopwords(words, sw.es); // 'sw.es' is the Spanish stopword list | ||
if (significantWords.length === 0) { | ||
return []; // Return an empty array if no significant words are left | ||
} | ||
const regexes = significantWords.map((word) => new RegExp(word, 'i')); | ||
|
||
const foundAlbums = await this.albumModel.find({ | ||
$or: [ | ||
{ title: { $in: regexes } }, | ||
{ description: { $in: regexes } }, | ||
{ tags: { $in: regexes } }, | ||
], | ||
}); | ||
return foundAlbums; | ||
} | ||
|
||
async findOneByCommentId(commentId: Types.ObjectId) { | ||
const albumFound = await this.albumModel.findOne({ | ||
comments: { | ||
$elemMatch: { _id: commentId }, | ||
}, | ||
}); | ||
|
||
if (!albumFound) | ||
throw new NotFoundException( | ||
`Album with comment id ${commentId} not found`, | ||
); | ||
|
||
return albumFound; | ||
} | ||
|
||
async findAllAlbums() { | ||
const foundAllAlbums = await this.albumModel.find(); | ||
return foundAllAlbums; | ||
} | ||
} |
Oops, something went wrong.