Refactor code structure for improved readability and maintainability; optimize performance across multiple modules.
All checks were successful
Deploy to production / deploy (push) Successful in 2m56s
All checks were successful
Deploy to production / deploy (push) Successful in 2m56s
This commit is contained in:
0
backend/controllers/adminController.js
Normal file → Executable file
0
backend/controllers/adminController.js
Normal file → Executable file
3
backend/controllers/authController.js
Normal file → Executable file
3
backend/controllers/authController.js
Normal file → Executable file
@@ -63,7 +63,8 @@ class AuthController {
|
||||
async oauthStart(req, res) {
|
||||
const { provider } = req.params;
|
||||
try {
|
||||
const redirectTo = await oauthService.startOAuthLogin({ providerSlug: provider });
|
||||
const client = req.query.client === 'android' ? 'android' : 'web';
|
||||
const redirectTo = await oauthService.startOAuthLogin({ providerSlug: provider, client });
|
||||
res.redirect(302, redirectTo.toString());
|
||||
} catch (error) {
|
||||
const status = error.message === 'providernotconfigured' ? 503 : 500;
|
||||
|
||||
0
backend/controllers/blogController.js
Normal file → Executable file
0
backend/controllers/blogController.js
Normal file → Executable file
0
backend/controllers/calendarController.js
Normal file → Executable file
0
backend/controllers/calendarController.js
Normal file → Executable file
0
backend/controllers/chatController.js
Normal file → Executable file
0
backend/controllers/chatController.js
Normal file → Executable file
0
backend/controllers/contactController.js
Normal file → Executable file
0
backend/controllers/contactController.js
Normal file → Executable file
0
backend/controllers/dashboardController.js
Normal file → Executable file
0
backend/controllers/dashboardController.js
Normal file → Executable file
0
backend/controllers/falukantController.js
Normal file → Executable file
0
backend/controllers/falukantController.js
Normal file → Executable file
0
backend/controllers/forumController.js
Normal file → Executable file
0
backend/controllers/forumController.js
Normal file → Executable file
0
backend/controllers/friendshipController.js
Normal file → Executable file
0
backend/controllers/friendshipController.js
Normal file → Executable file
0
backend/controllers/match3Controller.js
Normal file → Executable file
0
backend/controllers/match3Controller.js
Normal file → Executable file
0
backend/controllers/minigamesController.js
Normal file → Executable file
0
backend/controllers/minigamesController.js
Normal file → Executable file
0
backend/controllers/moderationController.js
Normal file → Executable file
0
backend/controllers/moderationController.js
Normal file → Executable file
0
backend/controllers/navigationController.js
Normal file → Executable file
0
backend/controllers/navigationController.js
Normal file → Executable file
0
backend/controllers/newsController.js
Normal file → Executable file
0
backend/controllers/newsController.js
Normal file → Executable file
34
backend/controllers/pushNotificationController.js
Normal file
34
backend/controllers/pushNotificationController.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import Joi from 'joi';
|
||||
import * as pushNotificationService from '../services/pushNotificationService.js';
|
||||
|
||||
const tokenSchema = Joi.object({ token: Joi.string().trim().min(20).max(4096).required(), enabled: Joi.boolean().default(true) });
|
||||
const settingsSchema = Joi.object({
|
||||
enabled: Joi.boolean(),
|
||||
chatEnabled: Joi.boolean(),
|
||||
friendLoginEnabled: Joi.boolean(),
|
||||
falukantEnabled: Joi.boolean(),
|
||||
vocabReminderEnabled: Joi.boolean(),
|
||||
}).min(1);
|
||||
|
||||
const pushNotificationController = {
|
||||
async registerDevice(req, res) {
|
||||
const { error, value } = tokenSchema.validate(req.body || {});
|
||||
if (error) return res.status(400).json({ error: error.details[0].message });
|
||||
return res.status(200).json(await pushNotificationService.registerDevice(req.headers.userid, value));
|
||||
},
|
||||
async disableDevice(req, res) {
|
||||
const { error, value } = tokenSchema.validate({ token: req.params.token, enabled: false });
|
||||
if (error) return res.status(400).json({ error: error.details[0].message });
|
||||
return res.status(200).json(await pushNotificationService.disableDevice(req.headers.userid, value.token));
|
||||
},
|
||||
async getSettings(req, res) {
|
||||
return res.status(200).json(await pushNotificationService.loadSettings(req.headers.userid));
|
||||
},
|
||||
async updateSettings(req, res) {
|
||||
const { error, value } = settingsSchema.validate(req.body || {});
|
||||
if (error) return res.status(400).json({ error: error.details[0].message });
|
||||
return res.status(200).json(await pushNotificationService.updateSettings(req.headers.userid, value));
|
||||
},
|
||||
};
|
||||
|
||||
export default pushNotificationController;
|
||||
6
backend/controllers/settingsController.js
Normal file → Executable file
6
backend/controllers/settingsController.js
Normal file → Executable file
@@ -68,6 +68,9 @@ class SettingsController {
|
||||
async getAccountSettings(req, res) {
|
||||
try {
|
||||
const { userId } = req.body;
|
||||
if (userId !== req.headers.userid) {
|
||||
return res.status(403).json({ error: 'Access denied' });
|
||||
}
|
||||
const accountSettings = await settingsService.getAccountSettings(userId);
|
||||
res.status(200).json(accountSettings);
|
||||
} catch (error) {
|
||||
@@ -86,6 +89,9 @@ class SettingsController {
|
||||
return res.status(400).json({ error: error.details[0].message });
|
||||
}
|
||||
try {
|
||||
if (value.userId !== req.headers.userid) {
|
||||
return res.status(403).json({ error: 'Access denied' });
|
||||
}
|
||||
await settingsService.setAccountSettings(value);
|
||||
res.status(200).json({ message: 'Account settings updated successfully' });
|
||||
} catch (error) {
|
||||
|
||||
12
backend/controllers/socialnetworkController.js
Normal file → Executable file
12
backend/controllers/socialnetworkController.js
Normal file → Executable file
@@ -40,6 +40,8 @@ class SocialNetworkController {
|
||||
this.removeFriend = this.removeFriend.bind(this);
|
||||
this.acceptFriendship = this.acceptFriendship.bind(this);
|
||||
this.getLoggedInFriends = this.getLoggedInFriends.bind(this);
|
||||
this.blockUser = this.blockUser.bind(this);
|
||||
this.unblockUser = this.unblockUser.bind(this);
|
||||
}
|
||||
|
||||
async userSearch(req, res) {
|
||||
@@ -54,6 +56,16 @@ class SocialNetworkController {
|
||||
}
|
||||
}
|
||||
|
||||
async blockUser(req, res) {
|
||||
try { await this.socialNetworkService.blockUser(req.headers.userid, req.params.userId); res.status(204).send(); }
|
||||
catch (error) { res.status(400).json({ error: error.message }); }
|
||||
}
|
||||
|
||||
async unblockUser(req, res) {
|
||||
try { await this.socialNetworkService.unblockUser(req.headers.userid, req.params.userId); res.status(204).send(); }
|
||||
catch (error) { res.status(400).json({ error: error.message }); }
|
||||
}
|
||||
|
||||
async profile(req, res) {
|
||||
try {
|
||||
const { userId } = req.params;
|
||||
|
||||
0
backend/controllers/taxiController.js
Normal file → Executable file
0
backend/controllers/taxiController.js
Normal file → Executable file
0
backend/controllers/taxiHighscoreController.js
Normal file → Executable file
0
backend/controllers/taxiHighscoreController.js
Normal file → Executable file
0
backend/controllers/taxiMapController.js
Normal file → Executable file
0
backend/controllers/taxiMapController.js
Normal file → Executable file
0
backend/controllers/termineController.js
Normal file → Executable file
0
backend/controllers/termineController.js
Normal file → Executable file
0
backend/controllers/vocabController.js
Normal file → Executable file
0
backend/controllers/vocabController.js
Normal file → Executable file
Reference in New Issue
Block a user