46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { Injectable, NotFoundException } from '@nestjs/common';
|
|
import { Modules, Users } from '@prisma/client';
|
|
import { toKeysFromBoolean } from 'src/common/utils/boolean-utils';
|
|
import { PrismaService } from 'src/prisma/prisma.service';
|
|
|
|
@Injectable()
|
|
export abstract class AbstractUserService {
|
|
constructor(protected readonly prisma: PrismaService) { }
|
|
|
|
async findOneByEmail(email: string): Promise<Partial<Users>> {
|
|
const user = await this.prisma.users.findUnique({
|
|
where: { email },
|
|
include: {
|
|
user_module_access: {
|
|
select: {
|
|
dashboard: true,
|
|
employee_list: true,
|
|
employee_management: true,
|
|
personal_profile: true,
|
|
timesheets: true,
|
|
timesheets_approval: true,
|
|
},
|
|
},
|
|
},
|
|
|
|
});
|
|
if (!user) {
|
|
throw new NotFoundException(`No user with email #${email} exists`);
|
|
}
|
|
|
|
let module_access: Modules[] = [];
|
|
if (user.user_module_access !== null) module_access = toKeysFromBoolean(user.user_module_access);
|
|
console.log('module access: ', module_access);
|
|
|
|
const clean_user = {
|
|
first_name: user.first_name,
|
|
last_name: user.last_name,
|
|
email: user.email,
|
|
role: user.role,
|
|
user_module_access: module_access,
|
|
}
|
|
|
|
return clean_user;
|
|
}
|
|
}
|