Combined both DTOs to reduce duplicate code

This commit is contained in:
devanshu052000 2025-05-21 16:48:33 +05:30
parent 82eb0204c2
commit e68b5c48ad
9 changed files with 31 additions and 54 deletions

View file

@ -177,7 +177,7 @@ export default function PagePermission({ darkMode }) {
const createPagePermission = () => {
const body = {
pageId: editingPage?.id,
id: editingPage?.id,
type: PERMISSION_TYPES[pagePermissionType],
...(pagePermissionType === 'group'
? { groups: selectedUserGroups.map((group) => group?.value) }
@ -205,7 +205,7 @@ export default function PagePermission({ darkMode }) {
const updatePagePermission = () => {
const body = {
pageId: editingPage?.id,
id: editingPage?.id,
type: PERMISSION_TYPES[pagePermissionType],
...(pagePermissionType === 'group'
? { groups: selectedUserGroups.map((group) => group?.value) }

@ -1 +1 @@
Subproject commit c1d051b04364f9a2db333b3cffb77d611d50c8eb
Subproject commit f61295c5f85c354048f15275d4b3af52019d95b3

View file

@ -8,7 +8,7 @@ import { MODULES } from '@modules/app/constants/modules';
import { InitFeature } from '@modules/app/decorators/init-feature.decorator';
import { FEATURE_KEY } from './constants';
import { JwtAuthGuard } from '@modules/session/guards/jwt-auth.guard';
import { CreatePagePermissionDto, CreateQueryPermissionDto } from './dto';
import { CreatePermissionDto } from './dto';
@InitModule(MODULES.APP_PERMISSIONS)
@UseGuards(JwtAuthGuard, FeatureAbilityGuard)
@ -53,7 +53,7 @@ export class AppPermissionsController implements IAppPermissionsController {
@User() user,
@Param('appId') appId: string,
@Param('pageId') pageId: string,
@Body() body: CreatePagePermissionDto,
@Body() body: CreatePermissionDto,
@Res({ passthrough: true }) response: Response
): Promise<any> {
throw new NotFoundException();
@ -65,7 +65,7 @@ export class AppPermissionsController implements IAppPermissionsController {
@User() user,
@Param('appId') appId: string,
@Param('pageId') pageId: string,
@Body() body: CreatePagePermissionDto,
@Body() body: CreatePermissionDto,
@Res({ passthrough: true }) response: Response
): Promise<any> {
throw new NotFoundException();
@ -99,7 +99,7 @@ export class AppPermissionsController implements IAppPermissionsController {
@User() user,
@Param('appId') appId: string,
@Param('queryId') queryId: string,
@Body() body: CreateQueryPermissionDto,
@Body() body: CreatePermissionDto,
@Res({ passthrough: true }) response: Response
): Promise<any> {
throw new NotFoundException();
@ -111,7 +111,7 @@ export class AppPermissionsController implements IAppPermissionsController {
@User() user,
@Param('appId') appId: string,
@Param('queryId') queryId: string,
@Body() body: CreateQueryPermissionDto,
@Body() body: CreatePermissionDto,
@Res({ passthrough: true }) response: Response
): Promise<any> {
throw new NotFoundException();

View file

@ -2,33 +2,10 @@ import { IsUUID, IsEnum, IsArray, IsString, IsOptional, ValidateIf } from 'class
import { Type } from 'class-transformer';
import { PAGE_PERMISSION_TYPE } from '../constants';
export class CreatePagePermissionDto {
export class CreatePermissionDto {
@IsUUID(4)
@IsOptional()
pageId: string;
@IsEnum(PAGE_PERMISSION_TYPE)
type: PAGE_PERMISSION_TYPE;
@ValidateIf((o) => o.type === PAGE_PERMISSION_TYPE.SINGLE)
@IsArray()
@IsString({ each: true })
@IsOptional()
@Type(() => String)
users?: string[];
@ValidateIf((o) => o.type === PAGE_PERMISSION_TYPE.GROUP)
@IsArray()
@IsString({ each: true })
@IsOptional()
@Type(() => String)
groups?: string[];
}
export class CreateQueryPermissionDto {
@IsUUID(4)
@IsOptional()
queryId: string;
id: string;
@IsEnum(PAGE_PERMISSION_TYPE)
type: PAGE_PERMISSION_TYPE;

View file

@ -1,6 +1,6 @@
import { User } from '@entities/user.entity';
import { Response } from 'express';
import { CreatePagePermissionDto, CreateQueryPermissionDto } from '../dto';
import { CreatePermissionDto } from '../dto';
export interface IAppPermissionsController {
fetchUsers(user: User, appId: string, response: Response): Promise<any>;
@ -13,7 +13,7 @@ export interface IAppPermissionsController {
user: User,
appId: string,
pageId: string,
body: CreatePagePermissionDto,
body: CreatePermissionDto,
response: Response
): Promise<any>;
@ -21,7 +21,7 @@ export interface IAppPermissionsController {
user: User,
appId: string,
pageId: string,
body: CreatePagePermissionDto,
body: CreatePermissionDto,
response: Response
): Promise<any>;
@ -33,7 +33,7 @@ export interface IAppPermissionsController {
user: User,
appId: string,
queryId: string,
body: CreateQueryPermissionDto,
body: CreatePermissionDto,
response: Response
): Promise<any>;
@ -41,7 +41,7 @@ export interface IAppPermissionsController {
user: User,
appId: string,
queryId: string,
body: CreateQueryPermissionDto,
body: CreatePermissionDto,
response: Response
): Promise<any>;

View file

@ -1,5 +1,5 @@
import { User } from '@entities/user.entity';
import { CreatePagePermissionDto } from '../dto';
import { CreatePermissionDto } from '../dto';
import { PERMISSION_ENTITY_TYPE } from '../constants';
export interface IAppPermissionsService {
@ -7,17 +7,17 @@ export interface IAppPermissionsService {
fetchUserGroups(appId: string, user: User): Promise<any>;
fetchAppPermissions(type: PERMISSION_ENTITY_TYPE, pageId: string): Promise<any>;
fetchAppPermissions(type: PERMISSION_ENTITY_TYPE, id: string): Promise<any>;
createAppPermissions(type: PERMISSION_ENTITY_TYPE, pageId: string, body: CreatePagePermissionDto): Promise<any>;
createAppPermissions(type: PERMISSION_ENTITY_TYPE, id: string, body: CreatePermissionDto): Promise<any>;
updateAppPermissions(
type: PERMISSION_ENTITY_TYPE,
appId: string,
pageId: string,
body: CreatePagePermissionDto,
id: string,
body: CreatePermissionDto,
user: User
): Promise<any>;
deleteAppPermissions(type: PERMISSION_ENTITY_TYPE, pageId: string): Promise<any>;
deleteAppPermissions(type: PERMISSION_ENTITY_TYPE, id: string): Promise<any>;
}

View file

@ -1,13 +1,13 @@
import { User } from '@entities/user.entity';
import { GroupPermissions } from '@entities/group_permissions.entity';
import { CreatePagePermissionDto } from '../dto';
import { CreatePermissionDto } from '../dto';
export interface IUtilService {
getUsersWithViewAccess(appId: string, organizationId: string): Promise<User[]>;
getUserGroupsWithViewAccess(appId: string, organizationId: string): Promise<GroupPermissions[]>;
createPagePermission(pageId: string, body: CreatePagePermissionDto): Promise<any>;
createPagePermission(pageId: string, body: CreatePermissionDto): Promise<any>;
updatePagePermission(pageId: string, body: CreatePagePermissionDto): Promise<any>;
updatePagePermission(pageId: string, body: CreatePermissionDto): Promise<any>;
}

View file

@ -13,19 +13,19 @@ export class AppPermissionsService implements IAppPermissionsService {
throw new Error('Method not implemented.');
}
async fetchAppPermissions(type, pageId) {
async fetchAppPermissions(type, id) {
throw new Error('Method not implemented.');
}
async createAppPermissions(type, pageId, body) {
async createAppPermissions(type, id, body) {
throw new Error('Method not implemented.');
}
async updateAppPermissions(type, appId, pageId, body, user) {
async updateAppPermissions(type, appId, id, body, user) {
throw new Error('Method not implemented.');
}
async deleteAppPermissions(type, pageId) {
async deleteAppPermissions(type, id) {
throw new Error('Method not implemented.');
}
}

View file

@ -2,7 +2,7 @@ import { User } from '@entities/user.entity';
import { IUtilService } from './interfaces/IUtilService';
import { Injectable } from '@nestjs/common';
import { GroupPermissions } from '@entities/group_permissions.entity';
import { CreatePagePermissionDto } from './dto';
import { CreatePermissionDto } from './dto';
@Injectable()
export class AppPermissionsUtilService implements IUtilService {
@ -16,11 +16,11 @@ export class AppPermissionsUtilService implements IUtilService {
throw new Error('Method not implemented.');
}
async createPagePermission(pageId: string, body: CreatePagePermissionDto): Promise<any> {
async createPagePermission(pageId: string, body: CreatePermissionDto): Promise<any> {
throw new Error('Method not implemented.');
}
async updatePagePermission(pageId: string, body: CreatePagePermissionDto): Promise<any> {
async updatePagePermission(pageId: string, body: CreatePermissionDto): Promise<any> {
throw new Error('Method not implemented.');
}
}