Skip to content

Commit

Permalink
Merge pull request #36 from fis-g4/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
davbarsal1 authored Jan 23, 2024
2 parents 21eab8c + 07c965e commit cbf37a1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 31 deletions.
4 changes: 3 additions & 1 deletion server/.env.dev
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
DB_URI=mongodb://localhost:27017
DB_DATABASE=courses-db
DB_DATABASE_TEST=test
DB_USER=root
DB_PASS=password
AUTH_DB=auth-db
PORT=8000
NODE_ENV=development
JWT_SECRET=secret
JWT_EXPIRATION_TIME="24h"
JWT_EXPIRATION_TIME=24h
SALT_ROUNDS=10
RABBITMQ_USER=admin
RABBITMQ_PASSWORD=testing1
Expand Down
15 changes: 9 additions & 6 deletions server/.env.prod
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
DB_URI=mongodb://mongo-db:27017
DB_URI=mongodb://localhost:27017
DB_DATABASE=courses-db
DB_DATABASE_TEST=test
DB_USER=root
DB_PASS=password
AUTH_DB=auth-db
PORT=8000
NODE_ENV=production
JWT_SECRET=secret # or your jwt secret
JWT_EXPIRATION_TIME=24h # or your jwt expiration time
SALT_ROUNDS=10 # or your salt rounds for bcrypt
NODE_ENV=development
JWT_SECRET=secret
JWT_EXPIRATION_TIME=24h
SALT_ROUNDS=10
RABBITMQ_USER=admin
RABBITMQ_PASSWORD=testing1
RABBITMQ_ADDRESS=34.163.8.143:5672
API_KEY=LKA534534FSDGEHJDSHGIOERHVIODSA2423U54GNV39Q8755
API_DOMAIN=api.javiercavlop.com
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_PASSWORD=password # or your salt rounds for bcrypt
REDIS_PASSWORD=password
GCF_GENERATE_TOKEN_ENDPOINT=https://europe-west9-fisg4-411716.cloudfunctions.net/generateToken
GCF_VERIFY_TOKEN_ENDPOINT=https://europe-west9-fisg4-411716.cloudfunctions.net/verifyToken
GCF_GET_PAYLOAD_FROM_TOKEN_ENDPOINT=https://europe-west9-fisg4-411716.cloudfunctions.net/getPayloadFromToken
2 changes: 1 addition & 1 deletion server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const MICROSERVICE_QUEUE = 'courses_microservice'
app.use('/v1/courses', courses)
app.use('/v1/reviews', reviews)

//receiveMessages(MICROSERVICE_QUEUE)
receiveMessages(MICROSERVICE_QUEUE)

app.listen(port, () => {
console.info(`Courses microservice listening on port ${port}`)
Expand Down
2 changes: 1 addition & 1 deletion server/rabbitmq/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function sendMessage(

async function receiveMessages(queue: string) {
try {
const amqpServer = `amqp://${process.env.RABBITMQ_USER}:${process.env.RABBITMQ_PASSWORD}@34.163.248.83:5672`
const amqpServer = `amqp://${process.env.RABBITMQ_USER}:${process.env.RABBITMQ_PASSWORD}@${process.env.RABBITMQ_ADDRESS}`
connection = await amqplib.connect(amqpServer)
channel = await connection.createChannel()
await channel.consume(queue, (data) => {
Expand Down
45 changes: 23 additions & 22 deletions server/routes/courses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,22 @@ router.get('/best', async (req: Request, res: Response) => {
try {
const courses = await Course.find().sort({ score: -1 }).limit(6);

return res.status(200).json(courses);
const modifiedCourses = await Promise.all(courses.map(async course => {
const user = await MaterliaziedView.findOne({ username: course.creator });
if (user) {
return {
...course.toObject(), // Convert Mongoose document to plain JavaScript object
creator: user.firstName + " " + user.lastName // Change 'newUsername' to the desired value
};
}
else {
return {
course
};
}
}))

return res.status(200).json(modifiedCourses);
} catch (error) {
return res.status(500).json({ error: 'Internal Server Error' });
}
Expand All @@ -34,7 +49,6 @@ router.post('/new', async (req: Request, res: Response) => {
)
const username: string = decodedToken.username

/*
const firstName: string = decodedToken.firstName
const lastName: string = decodedToken.lastName
const profilePicture: string = decodedToken.profilePicture
Expand All @@ -47,7 +61,6 @@ router.post('/new', async (req: Request, res: Response) => {
});

await MaterliaziedView.findOneAndUpdate({ username : username }, materializedView, { upsert: true });
*/

const { name, description, price, categories, language }: CourseFormInputs = req.body

Expand Down Expand Up @@ -84,7 +97,6 @@ router.get('/list', async (req: Request, res: Response) => {
getTokenFromRequest(req) ?? ''
)
const username: string = decodedToken.username
/*
const firstName: string = decodedToken.firstName
const lastName: string = decodedToken.lastName
const profilePicture: string = decodedToken.profilePicture
Expand All @@ -96,9 +108,7 @@ router.get('/list', async (req: Request, res: Response) => {
profilePicture: profilePicture,
});

await MaterliaziedView.findOneAndUpdate({ username : username }, materializedView);
*/
await MaterliaziedView.findOneAndUpdate({ username : username }, materializedView, { upsert: true });

let filters: { [key: string]: any } = {};

Expand Down Expand Up @@ -136,7 +146,6 @@ router.put('/:courseId', async (req: Request, res: Response) => {
)
const username: string = decodedToken.username

/*
const firstName: string = decodedToken.firstName
const lastName: string = decodedToken.lastName
const profilePicture: string = decodedToken.profilePicture
Expand All @@ -148,8 +157,7 @@ router.put('/:courseId', async (req: Request, res: Response) => {
profilePicture: profilePicture,
});

await MaterliaziedView.findOneAndUpdate({ username : username }, materializedView);
*/
await MaterliaziedView.findOneAndUpdate({ username : username }, materializedView, { upsert: true });

const { name, description, price, categories, language }: CourseFormInputs = req.body
const courseId = req.params.courseId;
Expand Down Expand Up @@ -182,7 +190,6 @@ router.delete('/:courseId', async (req: Request, res: Response) => {
)
const username: string = decodedToken.username

/*
const firstName: string = decodedToken.firstName
const lastName: string = decodedToken.lastName
const profilePicture: string = decodedToken.profilePicture
Expand All @@ -194,8 +201,7 @@ router.delete('/:courseId', async (req: Request, res: Response) => {
profilePicture: profilePicture,
});

await MaterliaziedView.findOneAndUpdate({ username : username }, materializedView);
*/
await MaterliaziedView.findOneAndUpdate({ username : username }, materializedView, { upsert: true });

const courseId = req.params.courseId;

Expand Down Expand Up @@ -236,7 +242,6 @@ router.get('/:courseId', async (req: Request, res: Response) => {
)
const username: string = decodedToken.username

/*
const firstName: string = decodedToken.firstName
const lastName: string = decodedToken.lastName
const profilePicture: string = decodedToken.profilePicture
Expand All @@ -248,8 +253,7 @@ router.get('/:courseId', async (req: Request, res: Response) => {
profilePicture: profilePicture,
});

await MaterliaziedView.findOneAndUpdate({ username : username }, materializedView);
*/
await MaterliaziedView.findOneAndUpdate({ username : username }, materializedView, { upsert: true });

const courseId = req.params.courseId;
const course = await Course.findById(courseId);
Expand All @@ -274,7 +278,7 @@ router.get('/:courseId/classes', async (req: Request, res: Response) => {
getTokenFromRequest(req) ?? ''
)
const username: string = decodedToken.username
/*

const firstName: string = decodedToken.firstName
const lastName: string = decodedToken.lastName
const profilePicture: string = decodedToken.profilePicture
Expand All @@ -286,8 +290,7 @@ router.get('/:courseId/classes', async (req: Request, res: Response) => {
profilePicture: profilePicture,
});

await MaterliaziedView.findOneAndUpdate({ username : username }, materializedView);
*/
await MaterliaziedView.findOneAndUpdate({ username : username }, materializedView, { upsert: true });

const courseId = req.params.courseId;
const course = await Course.findById(courseId);
Expand Down Expand Up @@ -333,7 +336,6 @@ router.get('/:courseId/materials', async (req: Request, res: Response) => {
getTokenFromRequest(req) ?? ''
)

/*
const username: string = decodedToken.username
const firstName: string = decodedToken.firstName
const lastName: string = decodedToken.lastName
Expand All @@ -346,8 +348,7 @@ router.get('/:courseId/materials', async (req: Request, res: Response) => {
profilePicture: profilePicture,
});

await MaterliaziedView.findOneAndUpdate({ username : username }, materializedView);
*/
await MaterliaziedView.findOneAndUpdate({ username : username }, materializedView, { upsert: true });

const courseId = req.params.courseId;
const course = await Course.findById(courseId);
Expand Down

0 comments on commit cbf37a1

Please sign in to comment.