feat(preferences): added a getter function and modified schema to use boolean
This commit is contained in:
parent
439e005936
commit
5f7f639c62
|
|
@ -41,7 +41,7 @@ model userModuleAccess {
|
||||||
employee_list Boolean @default(false) //wich shows the lists of employee to show names, emails, titles and profile picture
|
employee_list Boolean @default(false) //wich shows the lists of employee to show names, emails, titles and profile picture
|
||||||
employee_management Boolean @default(false) //wich offers CRUD for employees, schedule_presets and manage module access
|
employee_management Boolean @default(false) //wich offers CRUD for employees, schedule_presets and manage module access
|
||||||
personnal_profile Boolean @default(false) //wich governs profile details, preferances and dashboard access
|
personnal_profile Boolean @default(false) //wich governs profile details, preferances and dashboard access
|
||||||
blocked Boolean @default(false)
|
blocked Boolean @default(false)
|
||||||
|
|
||||||
@@map("user_module_access")
|
@@map("user_module_access")
|
||||||
}
|
}
|
||||||
|
|
@ -347,14 +347,12 @@ model Preferences {
|
||||||
user Users @relation("UserPreferences", fields: [user_id], references: [id])
|
user Users @relation("UserPreferences", fields: [user_id], references: [id])
|
||||||
user_id String @unique @db.Uuid
|
user_id String @unique @db.Uuid
|
||||||
|
|
||||||
notifications Int @default(0)
|
notifications Boolean @default(false)
|
||||||
dark_mode Int @default(0)
|
dark_mode Boolean @default(false)
|
||||||
lang_switch Int @default(0)
|
lang_switch Boolean @default(false)
|
||||||
lefty_mode Int @default(0)
|
lefty_mode Boolean @default(false)
|
||||||
|
employee_list_display Boolean @default(false)
|
||||||
employee_list_display Int @default(0)
|
approval_display Boolean @default(false)
|
||||||
validation_display Int @default(0)
|
|
||||||
timesheet_display Int @default(0)
|
|
||||||
|
|
||||||
@@map("preferences")
|
@@map("preferences")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Body, Controller, Patch, Req } from "@nestjs/common";
|
import { Body, Controller, Get, Patch, Query, Req } from "@nestjs/common";
|
||||||
import { PreferencesService } from "../services/preferences.service";
|
import { PreferencesService } from "../services/preferences.service";
|
||||||
import { PreferencesDto } from "../dtos/preferences.dto";
|
import { PreferencesDto } from "../dtos/preferences.dto";
|
||||||
import { Result } from "src/common/errors/result-error.factory";
|
import { Result } from "src/common/errors/result-error.factory";
|
||||||
|
|
@ -7,7 +7,7 @@ import { Result } from "src/common/errors/result-error.factory";
|
||||||
export class PreferencesController {
|
export class PreferencesController {
|
||||||
constructor(private readonly service: PreferencesService){}
|
constructor(private readonly service: PreferencesService){}
|
||||||
|
|
||||||
@Patch('update_preferences')
|
@Patch('update')
|
||||||
async updatePreferences(
|
async updatePreferences(
|
||||||
@Req()req,
|
@Req()req,
|
||||||
@Body() payload: PreferencesDto
|
@Body() payload: PreferencesDto
|
||||||
|
|
@ -16,4 +16,10 @@ export class PreferencesController {
|
||||||
return this.service.updatePreferences(email, payload);
|
return this.service.updatePreferences(email, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
async findPreferences(@Req() req, @Query() employee_email?:string) {
|
||||||
|
const email = req.user?.email;
|
||||||
|
return this.service.findPreferences(email, employee_email);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -6,6 +6,5 @@ export class PreferencesDto {
|
||||||
lang_switch: number;
|
lang_switch: number;
|
||||||
lefty_mode: number;
|
lefty_mode: number;
|
||||||
employee_list_display: number;
|
employee_list_display: number;
|
||||||
validation_display: number;
|
approval_display: number;
|
||||||
timesheet_display: number;
|
|
||||||
}
|
}
|
||||||
|
|
@ -10,9 +10,37 @@ export class PreferencesService {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly prisma: PrismaService,
|
private readonly prisma: PrismaService,
|
||||||
private readonly emailResolver: EmailToIdResolver,
|
private readonly emailResolver: EmailToIdResolver,
|
||||||
|
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
|
async findPreferences(email: string, employee_email?: string): Promise<Result<PreferencesDto, string>> {
|
||||||
|
const account_email = employee_email ?? email;
|
||||||
|
const user_id = await this.emailResolver.resolveUserIdWithEmail(account_email);
|
||||||
|
if (!user_id.success) return { success: false, error: 'EMPLOYEE_NOT_FOUND' };
|
||||||
|
|
||||||
|
const user_preferences = await this.prisma.preferences.findUnique({
|
||||||
|
where: { user_id: user_id.data },
|
||||||
|
select: {
|
||||||
|
dark_mode: true,
|
||||||
|
lang_switch: true,
|
||||||
|
lefty_mode: true,
|
||||||
|
notifications: true,
|
||||||
|
employee_list_display: true,
|
||||||
|
approval_display: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!user_preferences) return { success: false, error: 'PREFERENCES_NOT_FOUND' };
|
||||||
|
|
||||||
|
const preferences: PreferencesDto = {
|
||||||
|
dark_mode: user_preferences.dark_mode,
|
||||||
|
lang_switch: user_preferences.lang_switch,
|
||||||
|
lefty_mode: user_preferences.lefty_mode,
|
||||||
|
notifications: user_preferences.notifications,
|
||||||
|
employee_list_display: user_preferences.employee_list_display,
|
||||||
|
approval_display: user_preferences.approval_display,
|
||||||
|
};
|
||||||
|
return { success: true, data: preferences };
|
||||||
|
}
|
||||||
|
|
||||||
async updatePreferences(email: string, dto: PreferencesDto): Promise<Result<Preferences, string>> {
|
async updatePreferences(email: string, dto: PreferencesDto): Promise<Result<Preferences, string>> {
|
||||||
const user_id = await this.emailResolver.resolveUserIdWithEmail(email);
|
const user_id = await this.emailResolver.resolveUserIdWithEmail(email);
|
||||||
if (!user_id.success) return { success: false, error: user_id.error }
|
if (!user_id.success) return { success: false, error: user_id.error }
|
||||||
|
|
@ -26,8 +54,7 @@ export class PreferencesService {
|
||||||
lang_switch: dto.lang_switch,
|
lang_switch: dto.lang_switch,
|
||||||
lefty_mode: dto.lefty_mode,
|
lefty_mode: dto.lefty_mode,
|
||||||
employee_list_display: dto.employee_list_display,
|
employee_list_display: dto.employee_list_display,
|
||||||
validation_display: dto.validation_display,
|
approval_display: dto.approval_display,
|
||||||
timesheet_display: dto.timesheet_display,
|
|
||||||
},
|
},
|
||||||
include: { user: true },
|
include: { user: true },
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { ModuleAccess } from "src/identity-and-account/user-module-access/dtos/m
|
||||||
import { AccessGetService } from "src/identity-and-account/user-module-access/services/module-access-get.service";
|
import { AccessGetService } from "src/identity-and-account/user-module-access/services/module-access-get.service";
|
||||||
import { AccessUpdateService } from "src/identity-and-account/user-module-access/services/module-access-update.service";
|
import { AccessUpdateService } from "src/identity-and-account/user-module-access/services/module-access-update.service";
|
||||||
|
|
||||||
@Controller()
|
@Controller('module_access')
|
||||||
export class ModuleAccessController {
|
export class ModuleAccessController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly getService: AccessGetService,
|
private readonly getService: AccessGetService,
|
||||||
|
|
@ -19,7 +19,7 @@ export class ModuleAccessController {
|
||||||
await this.getService.findModuleAccess(email, employee_email);
|
await this.getService.findModuleAccess(email, employee_email);
|
||||||
};
|
};
|
||||||
|
|
||||||
@Patch()
|
@Patch('update')
|
||||||
async updateAccess(
|
async updateAccess(
|
||||||
@Req() req,
|
@Req() req,
|
||||||
@Body() dto: ModuleAccess,
|
@Body() dto: ModuleAccess,
|
||||||
|
|
@ -29,7 +29,7 @@ export class ModuleAccessController {
|
||||||
await this.updateService.updateModuleAccess(email, dto, employee_email);
|
await this.updateService.updateModuleAccess(email, dto, employee_email);
|
||||||
};
|
};
|
||||||
|
|
||||||
@Patch()
|
@Patch('revoke')
|
||||||
async revokeModuleAccess(
|
async revokeModuleAccess(
|
||||||
@Req() req,
|
@Req() req,
|
||||||
@Query('employee_email') employee_email?: string
|
@Query('employee_email') employee_email?: string
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user