Skip to content

Commit

Permalink
Fixing user creation
Browse files Browse the repository at this point in the history
  • Loading branch information
kiran-rean committed Aug 24, 2024
1 parent 814bb2b commit 5a191e4
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/routes/users/[userId]/users/create/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const createUserSchema = zfd.formData({
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),
email: z.string().email().min(5).max(64),
role: z.string().min(10).max(64),
password: z.string().min(6).max(15),
// imageResourceId: z.string().optional(),
Expand Down Expand Up @@ -64,24 +64,27 @@ export const actions = {
const defaultTimeZone = result.countryCode === '+1' ? '-05:00' : '+05:30';
const currentTimeZone = result.countryCode === '+1' ? '-05:00' : '+05:30';
const phone = result.countryCode + '-' + result.phone;
const response = await createUser(
sessionId,
tenantId,
result.firstName,
result.lastName,
phone,
result.email,
result.role,
result.selectedUserRoleId,
result.password,
defaultTimeZone,
currentTimeZone
);
const id = response.Data.User.id;

if (response.Status === 'failure' || response.HttpCode !== 201) {
throw redirect(303, `/users/${userId}/users`, errorMessage(response.Message), event);
var response;
try {
response = await createUser(
sessionId,
tenantId,
result.firstName,
result.lastName,
phone,
result.email,
result.role,
result.selectedUserRoleId,
result.password,
defaultTimeZone,
currentTimeZone
);
}
catch (err) {
console.error(`Error creating user : ${err.body.message}`);
throw redirect(303, `/users/${userId}/users`, errorMessage(err.body.message), event);
}
const id = response.Data.User.id;
throw redirect(
303,
`/users/${userId}/users/${id}/view`,
Expand Down

0 comments on commit 5a191e4

Please sign in to comment.