Skip to content

Commit

Permalink
Some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kiran-rean committed Aug 23, 2024
1 parent 3a6df03 commit 99011d2
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 48 deletions.
25 changes: 16 additions & 9 deletions src/lib/components/input/password.input.svelte
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
<script lang="ts">
import Icon from '@iconify/svelte';
//////////////////////////////////////////////////////////////////
import { createEventDispatcher } from 'svelte';
export let name = 'password';
export let password = '';
let showPassword = false;
function togglePasswordVisibility() {
showPassword = !showPassword;
}
const dispatch = createEventDispatcher();
function onFocus() {
dispatch('focus');
}
function onBlur() {
dispatch('blur');
}
</script>

<div class="flex relative items-center">
<!-- <input
type={showPassword ? 'text' : 'password'}
name = {name}
bind:value={password}
required
class="input mb-4 mt-2"
/> -->
{#if showPassword}
<input
type="text"
{name}
bind:value={password}
required
class="input"
on:focus={onFocus}
on:blur={onBlur}
/>
{:else}
<input
Expand All @@ -34,6 +39,8 @@
bind:value={password}
required
class="input"
on:focus={onFocus}
on:blur={onBlur}
/>
{/if}
{#if password !== ''}
Expand Down
10 changes: 5 additions & 5 deletions src/routes/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const load: PageServerLoad = async (event: RequestEvent) => {
// console.log(Object.fromEntries(data));

// const username = data.has('username') ? (data.get('username') as string) : null;

// const password = data.has('password') ? (data.get('password') as string) : null;
// const loginRoleId_ = data.has('loginRoleId') ? data.get('loginRoleId') : null;
// const loginRoleId = loginRoleId_.valueOf() as number;
Expand Down Expand Up @@ -71,7 +70,7 @@ export const load: PageServerLoad = async (event: RequestEvent) => {
// console.log(JSON.stringify(userSession, null, 2));

// CookieUtils.setCookieHeader(event, 'sessionId', sessionId);

// throw redirect(303, `/users/${userId}/home`, successMessage(`Login successful!`), event);
// }
// };
Expand All @@ -86,6 +85,7 @@ const loginSchema = zfd.formData({
});

export const actions = {

login: async (event: RequestEvent) => {
const request = event.request;
const data = await request.formData();
Expand Down Expand Up @@ -137,7 +137,7 @@ export const actions = {
const user = response.Data.User;
user.SessionId = response.Data.SessionId;
const accessToken = response.Data.AccessToken;
const refreshToken = response.Data.RefreshToken;
const refreshToken = response.Data.RefreshToken;
const expiryDate = new Date(response.Data.SessionValidTill);
const sessionId = response.Data.SessionId;
const userId: string = response.Data.User.id;
Expand All @@ -152,7 +152,7 @@ export const actions = {
console.log(JSON.stringify(userSession, null, 2));

CookieUtils.setCookieHeader(event, 'sessionId', sessionId);

throw redirect(303, `/users/${userId}/home`, successMessage(`Login successful!`), event);
}
};
};
10 changes: 5 additions & 5 deletions src/routes/api/server/notifications/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ export const DELETE = async (event: RequestEvent) => {
const data = await request.json();
console.log('Inside notification server endpoints');
let response;
try{
try {
response = await deleteNotification(data.sessionId, data.notificationId);
}catch(error){
} catch (error) {
throw redirect(
errorMessage('Error deleting notification.'),
errorMessage('Error deleting notification.'),
event
);
);
}
throw redirect(
successMessage(response.Message),
event
);
);
};
20 changes: 10 additions & 10 deletions src/routes/api/server/users/search/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { searchUsers, addPermissionMatrix } from '$routes/api/services/reancare/

export const GET = async (event: RequestEvent) => {
const sessionId = event.locals.sessionUser.sessionId;
const tenantId = event.locals.sessionUser.tenantId;
const userRole = event.locals.sessionUser.roleName;
const userId = event.locals.sessionUser.userId;
const userRoleId = event.locals.sessionUser.roleId;
const tenantId = event.locals.sessionUser.tenantId;
const userRole = event.locals.sessionUser.roleName;
const userId = event.locals.sessionUser.userId;
const userRoleId = event.locals.sessionUser.roleId;
const searchParams: URLSearchParams = event.url.searchParams;
const firstName = searchParams.get('firstName') ?? undefined;
const email = searchParams.get('email') ?? undefined;
const phone = searchParams.get('phone') ?? undefined;
const roleIds = searchParams.get('roleIds') ?? undefined;
const roleIds = searchParams.get('roleIds') ?? undefined;
const sortBy = searchParams.get('sortBy') ?? 'CreatedAt';
const sortOrder = searchParams.get('sortOrder') ?? 'ascending';
const itemsPerPage_ = searchParams.get('itemsPerPage');
Expand All @@ -25,19 +25,19 @@ export const GET = async (event: RequestEvent) => {
firstName,
phone,
email,
roleIds,
roleIds,
orderBy: sortBy,
order: sortOrder,
itemsPerPage,
pageIndex
};
const response = await searchUsers(sessionId, searchParams);

const users = response.Data.Users;
// console.log("---", users);
users.Items = await addPermissionMatrix(sessionId, users.Items, userRole, userId, tenantId, userRoleId);
// console.log("---", users);
users.Items = await addPermissionMatrix(sessionId, users.Items, userRole, userId, tenantId, userRoleId);
// console.log("***", users);
return new Response(JSON.stringify(users));
return new Response(JSON.stringify(users));
} catch (err) {
console.error(`Error retriving users: ${err.message}`);
return new Response(err.message);
Expand Down
38 changes: 19 additions & 19 deletions src/routes/api/services/reancare/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ export const login = async (roleId: string, password: string, username?: string,
return response;
};

const getLoginModel = (roleId:string, password: string, username?: string, email?: string, phone?: string): LoginModel => {
const loginModel: LoginModel = {
Password: password,
LoginRoleId:roleId
};
const getLoginModel = (roleId: string, password: string, username?: string, email?: string, phone?: string): LoginModel => {
const loginModel: LoginModel = {
Password: password,
LoginRoleId: roleId
};

if (username){
loginModel.UserName = username
}
if (phone){
loginModel.Phone = phone
}
if (email){
loginModel.Email = email
}
return loginModel;
if (username) {
loginModel.UserName = username;
}
if (phone) {
loginModel.Phone = phone;
}
if (email) {
loginModel.Email = email;
}
return loginModel;
};

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -236,7 +236,7 @@ export const getUserRoleList = async (userRole: string) => {

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
Expand All @@ -253,10 +253,10 @@ export const addPermissionMatrix = async (sessionId: string, userRoleList: any[]

if (userRole === 'Tenant admin') {
userRoleList.forEach((userRole) => {
if ((userRole.RoleId === roleId &&
userRole.TenantId === tenantId &&
if ((userRole.RoleId === roleId &&
userRole.TenantId === tenantId &&
userRole.id === userId) ||
(userRole.TenantId === tenantId &&
(userRole.TenantId === tenantId &&
userRole.RoleId === selectedUserRoleId)) {
permissionMatrix.push({...userRole, IsPermitted: 1});
} else {
Expand Down

0 comments on commit 99011d2

Please sign in to comment.