Skip to content

Commit

Permalink
βœ” πŸ’©
Browse files Browse the repository at this point in the history
  • Loading branch information
bifeldy committed Jul 7, 2023
1 parent 4df0d9f commit a2b8cf7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dist/fansubid/browser/ngsw.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"configVersion": 1,
"timestamp": 1688710318952,
"timestamp": 1688711343460,
"index": "/index.html",
"assetGroups": [
{
Expand Down
2 changes: 1 addition & 1 deletion dist/fansubid/server/main.js

Large diffs are not rendered by default.

28 changes: 13 additions & 15 deletions src/api/controllers/promote.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller, HttpCode, HttpException, HttpStatus, Post, Req, Res } from '@nestjs/common';
import { ApiExcludeController } from '@nestjs/swagger';
import { Request, Response } from 'express';
import { Equal, Not, In, ILike } from 'typeorm';
import { Equal, ILike } from 'typeorm';

import { environment } from '../../environments/api/environment';

Expand Down Expand Up @@ -35,8 +35,15 @@ export class PromoteController {
try {
if ('role' in req.body && ('id' in req.body || 'username' in req.body || 'email' in req.body)) {
const adminMod: UserModel = res.locals['user'];
const excludedRole = adminMod.role === RoleModel.MODERATOR ? [RoleModel.ADMIN] : [RoleModel.ADMIN, RoleModel.MODERATOR];
if (adminMod.role !== RoleModel.ADMIN && excludedRole.includes(req.body.role)) {
let excludedRole = [];
if (adminMod.role === RoleModel.ADMIN) {
excludedRole = [];
} else if (adminMod.role === RoleModel.MODERATOR) {
excludedRole = [RoleModel.ADMIN];
} else {
excludedRole = [RoleModel.ADMIN, RoleModel.MODERATOR];
}
if (excludedRole.includes(req.body.role)) {
throw new HttpException({
info: 'πŸ™„ 403 - Promote API :: Authorisasi Pengguna Gagal πŸ˜ͺ',
result: {
Expand All @@ -46,18 +53,9 @@ export class PromoteController {
}
const user = await this.userRepo.findOneOrFail({
where: [
{
id: Equal(req.body.id),
role: Not(In(excludedRole))
},
{
username: ILike(req.body.username),
role: Not(In(excludedRole))
},
{
email: ILike(req.body.email),
role: Not(In(excludedRole))
}
{ id: Equal(req.body.id) },
{ username: ILike(req.body.username) },
{ email: ILike(req.body.email) }
],
relations: ['kartu_tanda_penduduk_', 'profile_']
});
Expand Down

0 comments on commit a2b8cf7

Please sign in to comment.