Skip to content

Commit

Permalink
Merge pull request #40 from REAN-Foundation/user-validation-issue
Browse files Browse the repository at this point in the history
Fixed issue of user form validation.
  • Loading branch information
nisha-inflectionzone authored Jun 25, 2024
2 parents 3dece7e + a6d420d commit bd5009e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const GET = async (event: RequestEvent) => {
const roleId = event.locals.sessionUser.roleId;
let response;
try {
if (roleId == "1") {
if (roleId == "1" || roleId == "2") {
response = await getDailySystemStatistics(sessionId);
} else {
response = await getDailyTenantStatistics(sessionId, tenantId);
Expand Down
18 changes: 14 additions & 4 deletions src/routes/api/services/reancare/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { LoginModel } from '$lib/types/domain.models';
import { Helper } from '$lib/utils/helper';
import { API_CLIENT_INTERNAL_KEY, BACKEND_API_URL } from '$env/static/private';
import { del, get, post, put } from './common.reancare';
import { searchPersonRoleTypes } from './person-role-types';
////////////////////////////////////////////////////////////////

export const login = async (roleId: string, password: string, username?: string, email?: string, phone?: string) => {
Expand Down Expand Up @@ -233,10 +234,17 @@ export const getUserRoleList = async (userRole: string) => {
return [];
}

export const addPermissionMatrix = async (userRoleList: any[], userRole?: string, userId?: string, tenantId?: string, roleId?: string) => {
console.log('User Role',userRole);
export const addPermissionMatrix = async (sessionId: string, userRoleList: any[], userRole?: string, userId?: string, tenantId?: string, roleId?: string) => {
const permissionMatrix: any[] = [];

const response = await searchPersonRoleTypes(sessionId)
let selectedUserRoleId;
const personRoleTypes = response.Data.PersonRoleTypes
const selectedRole = personRoleTypes?.find((x) => x.RoleName === 'Tenant user');
if (selectedRole) {
selectedUserRoleId = selectedRole.id;
}

if (userRole === 'System admin') {
userRoleList.forEach((userRole) => {
permissionMatrix.push({...userRole, IsPermitted: 1});
Expand All @@ -245,9 +253,11 @@ export const addPermissionMatrix = async (userRoleList: any[], userRole?: string

if (userRole === 'Tenant admin') {
userRoleList.forEach((userRole) => {
if (userRole.RoleId === roleId &&
if ((userRole.RoleId === roleId &&
userRole.TenantId === tenantId &&
userRole.id === userId) {
userRole.id === userId) ||
(userRole.TenantId === tenantId &&
userRole.RoleId === selectedUserRoleId)) {
permissionMatrix.push({...userRole, IsPermitted: 1});
} else {
permissionMatrix.push({...userRole, IsPermitted: 0});
Expand Down
8 changes: 6 additions & 2 deletions src/routes/users/[userId]/home/users-stats/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ export const load: PageServerLoad = async (event: RequestEvent) => {
throw error (401, 'Unauthorized Access');
}

if (event.locals.sessionUser.roleName === 'System admin') {
if (event.locals.sessionUser.roleName === 'System admin' ||
event.locals.sessionUser.roleName === 'System user'
) {
response = await getDailyStatistics(sessionId);
} else if (event.locals.sessionUser.roleName === 'Tenant admin') {
} else if (event.locals.sessionUser.roleName === 'Tenant admin' ||
event.locals.sessionUser.roleName === 'Tenant user'
) {
response = await getDailyTenantStatistics(sessionId, event.locals.sessionUser.tenantId);
} else {
throw error (401, 'Unauthorized Access');
Expand Down
2 changes: 1 addition & 1 deletion src/routes/users/[userId]/users/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const load: PageServerLoad = async (event: ServerLoadEvent) => {
throw error(response.HttpCode, response.Message);
}
const users = response.Data.Users;
users.Items = await addPermissionMatrix(users.Items, userRole, userId, tenantId, userRoleId);
users.Items = await addPermissionMatrix(sessionId, users.Items, userRole, userId, tenantId, userRoleId);
console.log('User Role After Add Permission Matrix', users.Items);
return {
users,
Expand Down
4 changes: 2 additions & 2 deletions src/routes/users/[userId]/users/create/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export const load: PageServerLoad = async (event: ServerLoadEvent) => {
};

const createUserSchema = zfd.formData({
firstName: z.string().min(3).max(256),
lastName: z.string().min(3).max(256),
firstName: z.string().min(1).max(256),
lastName: z.string().min(1).max(256),
phone: z.string().min(10).max(64),
email: z.string().email().min(10).max(64),
role: z.string().min(10).max(64),
Expand Down
6 changes: 3 additions & 3 deletions src/routes/users/[userId]/users/create/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@
: 'border-primary-200'}"
/> -->
<PasswordInput/>
{#if form?.errors?.password}
<p class="text-error-500 text-xs">{form?.errors?.password[0]}</p>
{/if}
<!-- {#if form?.errors?.password} -->
<p class="border-b-surface-700">Password should be of minimum 8 characters & contain at least 1 capital letter , 1 digit & 1 special character</p>
<!-- {/if} -->
</td>
</tr>
<!-- <tr class="!border-b !border-b-secondary-100 dark:!border-b-surface-700">
Expand Down

0 comments on commit bd5009e

Please sign in to comment.