-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #163 from mia-ajuda/develop
Mia Ajuda V3.0.0 (Corgi)
- Loading branch information
Showing
68 changed files
with
2,973 additions
and
1,271 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
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,32 @@ | ||
const ActivityService = require('../services/ActivityService'); | ||
|
||
class ActivityController { | ||
constructor() { | ||
this.ActivityService = new ActivityService(); | ||
} | ||
|
||
async fetchActivityList(req, res) { | ||
const { id } = req.query; | ||
const { isUserEntity } = global; | ||
const coords = req.query.coords.split(',').map((coord) => Number(coord)); | ||
const categoryArray = req.query.categoryId?.split(','); | ||
const activitiesArray = req.query.activityId?.split(',') || ['getAll']; | ||
const getOtherUsers = req.query.getOtherUsers === 'true'; | ||
|
||
try { | ||
const activityList = await this.ActivityService.fetchActivityList( | ||
coords, | ||
id, | ||
isUserEntity, | ||
categoryArray, | ||
activitiesArray, | ||
getOtherUsers, | ||
); | ||
return res.json(activityList); | ||
} catch (error) { | ||
return res.status(400).json({ error: error.message }); | ||
} | ||
} | ||
} | ||
|
||
module.exports = ActivityController; |
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,75 @@ | ||
const BadgeService = require('../services/BadgeService'); | ||
const saveError = require('../utils/ErrorHistory'); | ||
const parseBadgeByCategory = require('../utils/parseBadgeByCategory'); | ||
|
||
class BadgeController { | ||
constructor() { | ||
this.BadgeService = new BadgeService(); | ||
} | ||
|
||
async updateOrCreateBadge(req, res, next) { | ||
const { userId, category } = req.body; | ||
|
||
try { | ||
let result = await this.BadgeService.createOrUpdateBadge( | ||
userId, | ||
category, | ||
); | ||
if ( | ||
result.badge.template.nextBadge | ||
&& result.badge.currentValue >= result.badge.template.nextBadge.neededValue | ||
) { | ||
result = await this.BadgeService.updateBadgeReference(result.badge); | ||
} | ||
res.status(201).json(result); | ||
next(); | ||
} catch (err) { | ||
await saveError(err); | ||
res.status(400).json({ error: err.message }); | ||
next(); | ||
} | ||
} | ||
|
||
async getBadgeHistory(req, res, next) { | ||
const userId = req.query.userId || null; | ||
try { | ||
const userBadges = await this.BadgeService.getBadgeList(userId); | ||
const allBadges = await this.BadgeService.getAllBadges(); | ||
const parsedUserBadges = parseBadgeByCategory(userBadges); | ||
res.status(200).json({ userBadges: parsedUserBadges, allBadges }); | ||
next(); | ||
} catch (err) { | ||
await saveError(err); | ||
res.status(400).json({ error: err.message }); | ||
next(); | ||
} | ||
} | ||
|
||
async getBadgeList(req, res, next) { | ||
const userId = req.query.userId || null; | ||
try { | ||
const result = await this.BadgeService.getBadgeList(userId); | ||
res.status(200).json(result); | ||
next(); | ||
} catch (err) { | ||
await saveError(err); | ||
res.status(400).json({ error: err.message }); | ||
next(); | ||
} | ||
} | ||
|
||
async markBadgeAsViewed(req, res, next) { | ||
const { badgeId } = req.params; | ||
try { | ||
await this.BadgeService.markBadgeAsViewed(badgeId); | ||
res.status(200).json({ message: 'Badge visualized' }); | ||
next(); | ||
} catch (err) { | ||
await saveError(err); | ||
res.status(400).json({ error: err.message }); | ||
next(); | ||
} | ||
} | ||
} | ||
|
||
module.exports = BadgeController; |
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,43 @@ | ||
const FeedbackService = require('../services/FeedbackService'); | ||
const TimelineEventService = require('../services/TimelineEventService'); | ||
const saveError = require('../utils/ErrorHistory'); | ||
const timelineEnum = require('../utils/enums/timelineEnum'); | ||
|
||
class FeedbackController { | ||
constructor() { | ||
this.FeedbackService = new FeedbackService(); | ||
this.TimelineEventService = new TimelineEventService(); | ||
} | ||
|
||
async create(req, res) { | ||
try { | ||
const { message, sender, receiver } = req.body; | ||
const feedback = { | ||
sender, | ||
receiver, | ||
message, | ||
}; | ||
const newFeedback = await this.FeedbackService.create(feedback); | ||
await this.TimelineEventService.create({ user: sender, template: timelineEnum.feedback }); | ||
res.status(200).json(newFeedback); | ||
} catch (error) { | ||
saveError(error); | ||
res.status(500).json({ error: 'Erro ao criar feedback' }); | ||
} | ||
} | ||
|
||
async listByReceiver(req, res) { | ||
try { | ||
const { receiver } = req.params; | ||
const feedbacks = await this.FeedbackService.listByReceiver( | ||
receiver, | ||
); | ||
res.status(200).json(feedbacks); | ||
} catch (error) { | ||
saveError(error); | ||
res.status(500).json({ error: 'Erro ao listar feedbacks' }); | ||
} | ||
} | ||
} | ||
|
||
module.exports = FeedbackController; |
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
Oops, something went wrong.