-
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.
- Loading branch information
Showing
18 changed files
with
304 additions
and
371 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 was deleted.
Oops, something went wrong.
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,33 @@ | ||
import ResponseService from '../services/response.service'; | ||
import UserService from '../services/user.service'; | ||
/** | ||
* | ||
* | ||
* @class SettingsController | ||
*/ | ||
class SettingsController { | ||
/** | ||
* super_admin can assign a role to user by email | ||
* @static | ||
* @description PATCH /api/admin/reset-user-role | ||
* @param {object} req request object | ||
* @param {object} res response object | ||
* @memberof UserRoleSettingsController | ||
* @returns {object} ResponseService | ||
*/ | ||
static async changeUserRole(req, res) { | ||
const { userEmail, userRole } = req.body; | ||
const findUser = await UserService.findUserByProperty({ email: userEmail.trim() }); | ||
if (findUser && findUser.role !== 'super_admin') { | ||
await UserService.updateUser({ email: userEmail.trim() }, { role: userRole.trim() }); | ||
const data = await UserService.findUserByProperty({ email: userEmail.trim() }); | ||
const { role } = data; | ||
ResponseService.setSuccess(200, 'User role successfully updated', { role }); | ||
ResponseService.send(res); | ||
} else { | ||
ResponseService.setError(404, `User role not updated. ${userEmail.trim()} is either a super admin or Not Registered`); | ||
ResponseService.send(res); | ||
} | ||
} | ||
} | ||
export default SettingsController; |
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
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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import express from 'express'; | ||
import authRoute from './auth.route'; | ||
import tripRoute from './trip.route'; | ||
import profileSettingsRoute from './profile-settings.route'; | ||
import accommodationRoute from './accommodation.route'; | ||
import notificationRoute from './notification.route'; | ||
import settingsRoute from './settings.route'; | ||
|
||
const app = express(); | ||
|
||
app.use('/api/auth', authRoute); | ||
app.use('/api/', tripRoute); | ||
app.use('/api/accommodations', accommodationRoute); | ||
app.use('/api/users', profileSettingsRoute); | ||
app.use('/api/notifications', notificationRoute); | ||
app.use('/api/users/settings', settingsRoute); | ||
|
||
export default app; |
This file was deleted.
Oops, something went wrong.
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,10 @@ | ||
import express from 'express'; | ||
import authMiddleware from '../middlewares/auth.middleware'; | ||
import SettingsController from '../controllers/settings.controller'; | ||
import { validateUserRole } from '../validations/role.validation'; | ||
|
||
const router = express.Router(); | ||
|
||
router.patch('/reset-roles', authMiddleware.checkUserLoggedIn, validateUserRole, authMiddleware.verifyIfUserIsAdmin, SettingsController.changeUserRole); | ||
|
||
export default router; |
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,53 @@ | ||
/** | ||
* @swagger | ||
* definitions: | ||
* Super Admin Set or Reset User Role: | ||
* type: object | ||
* properties: | ||
* userEmail: | ||
* type: string | ||
* format: email | ||
* userRole: | ||
* type: string | ||
*/ | ||
|
||
/** | ||
* @swagger | ||
* /api/users/settings/reset-roles: | ||
* patch: | ||
* tags: | ||
* - User | ||
* name: Set or Reset User Role | ||
* summary: Edit User Role By Super Admin | ||
* produces: | ||
* - application/json | ||
* consumes: | ||
* - application/json | ||
* parameters: | ||
* - name: authorization | ||
* in: header | ||
* schema: | ||
* type: string | ||
* - name: body | ||
* in: body | ||
* schema: | ||
* $ref: '#/definitions/Super Admin Set or Reset User Role' | ||
* type: object | ||
* properties: | ||
* userEmail: | ||
* type: string | ||
* userRole: | ||
* type: string | ||
* responses: | ||
* '200': | ||
* description: User Role Updated successfully. | ||
* '400': | ||
* description: Bad request. | ||
* '401': | ||
* description: No Token Supplied. | ||
* '403': | ||
* description: Forbiden. | ||
* '404': | ||
* description: User Not Found | ||
* | ||
*/ |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.