-
Notifications
You must be signed in to change notification settings - Fork 5
/
actionUser.ts
34 lines (31 loc) · 928 Bytes
/
actionUser.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { json } from "@remix-run/node"
import { getSdk, UpdateUser, User } from "~/models/portal/sdk"
import { ActionDataStruct } from "~/types/global"
import { getErrorMessage } from "~/utils/catchError"
export type ActionUser = { user: User }
export const actionUser = async (
portal: ReturnType<typeof getSdk>,
input: UpdateUser,
) => {
try {
const updatePortalUserResponse = await portal.updatePortalUser({
updateUser: input,
})
if (!updatePortalUserResponse.updatePortalUser) {
throw new Error("User not able to be updated")
}
return json<ActionDataStruct<ActionUser>>({
data: {
user: updatePortalUserResponse.updatePortalUser as User,
},
error: false,
message: "User profile updated",
})
} catch (error) {
return json<ActionDataStruct<ActionUser>>({
data: null,
error: true,
message: getErrorMessage(error),
})
}
}