-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into feat/create-new-product-form
- Loading branch information
Showing
44 changed files
with
604 additions
and
102 deletions.
There are no files selected for viewing
Binary file added
BIN
+34.1 KB
.yarn/cache/@cspotcode-source-map-support-npm-0.8.1-964f2de99d-5718f26708.zip
Binary file not shown.
Binary file added
BIN
+27.5 KB
.yarn/cache/@jridgewell-trace-mapping-npm-0.3.9-91625cd7fb-d89597752f.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+17.2 KB
.yarn/cache/jest-mock-extended-npm-4.0.0-beta1-e929c470a7-de84487f07.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* eslint-disable no-undef */ | ||
|
||
module.exports = { | ||
process() { | ||
return { | ||
code: "module.exports = { messages: {} }" | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,35 @@ | ||
"use server"; | ||
|
||
import { HTTPError } from "ky"; | ||
import { pcomparatorApiClient } from "~/clients/PcomparatorApiClient"; | ||
import { auth } from "~/libraries/nextauth/authConfig"; | ||
|
||
/** | ||
* `deleteAccount` deletes a user account. | ||
* Deletes the authenticated user's account. | ||
* | ||
* @async | ||
* @function deleteAccount | ||
* @throws {Error} Throws an error if the user is not authenticated. | ||
* @throws {Error} Throws an error with message "404 NOT FOUND" if the account is not found on the server. | ||
* @throws {HTTPError} Re-throws any other HTTP errors encountered during the request. | ||
* @returns {Promise<void>} Resolves to `void` upon successful account deletion. | ||
*/ | ||
export const deleteAccount = async (): Promise<void> => { | ||
const session = await auth(); | ||
|
||
await pcomparatorApiClient.delete(`user/${session?.user?.id}/account/delete`).json(); | ||
if (!session?.user?.id) throw new Error("User not authenticated"); | ||
|
||
try { | ||
await pcomparatorApiClient.delete(`user/${session?.user?.id}/account/delete`).json(); | ||
} catch (err) { | ||
if (err instanceof HTTPError) { | ||
switch (err.response.status) { | ||
case 404: { | ||
console.log("Not Found"); | ||
throw new Error("404 NOT FOUND"); | ||
} | ||
} | ||
} | ||
throw err; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,59 @@ | ||
"use server"; | ||
|
||
import { HTTPError } from "ky"; | ||
import { z } from "zod"; | ||
import { pcomparatorApiClient } from "~/clients/PcomparatorApiClient"; | ||
import { pcomparatorAuthenticatedApiClient } from "~/clients/PcomparatorApiClient"; | ||
import { auth } from "~/libraries/nextauth/authConfig"; | ||
|
||
const ParamsSchema = z.object({ | ||
avatar: z.any() | ||
image: z.instanceof(File) | ||
}); | ||
|
||
const PayloadSchema = z.object({ | ||
image: z.string() | ||
}); | ||
|
||
export type UpdateAvatarParams = z.infer<typeof ParamsSchema>; | ||
export type UpdateAvatarPayload = z.infer<typeof PayloadSchema>; | ||
|
||
/** | ||
* `updateAvatar` updates a user's avatar | ||
* | ||
* Returns: user's avatar | ||
* Updates the authenticated user's avatar. | ||
* | ||
* @async | ||
* @function updateAvatar | ||
* @param {z.infer<typeof ParamsSchema>} params - The parameters containing the image file to upload as the user's new avatar. | ||
* @throws {Error} Throws an error if the user is not authenticated. | ||
* @throws {Error} Throws an error with the message "404 NOT FOUND" if the user is not found on the server. | ||
* @throws {HTTPError} Re-throws any other HTTP errors encountered during the request. | ||
* @returns {Promise<UpdateAvatarPayload>} Resolves to an object containing the updated avatar image URL upon successful update. | ||
*/ | ||
export const updateAvatar = async (params: z.infer<typeof ParamsSchema>): Promise<{ avatar: string }> => { | ||
export const updateAvatar = async (params: z.infer<typeof ParamsSchema>): Promise<UpdateAvatarPayload> => { | ||
const paramsPayload = ParamsSchema.parse(params); | ||
const session = await auth(); | ||
|
||
const updatedUser = await pcomparatorApiClient | ||
.post(`user/${session?.user?.id}/profile?filename=${paramsPayload.avatar.name}`, { | ||
body: paramsPayload.avatar | ||
}) | ||
.json(); | ||
if (!session?.user?.id) throw new Error("User not authenticated"); | ||
|
||
try { | ||
const updatedUser = await pcomparatorAuthenticatedApiClient | ||
.post(`user/${session.user.id}/profile?filename=${paramsPayload.image.name}`, { | ||
body: paramsPayload.image | ||
}) | ||
.json(); | ||
|
||
const updatedUserPayload = PayloadSchema.parse(updatedUser); | ||
const updatedUserPayload = PayloadSchema.parse(updatedUser); | ||
|
||
return { | ||
avatar: updatedUserPayload.image | ||
}; | ||
return { | ||
image: updatedUserPayload.image | ||
}; | ||
} catch (err) { | ||
if (err instanceof HTTPError) { | ||
switch (err.response.status) { | ||
case 404: { | ||
console.log("Not Found"); | ||
throw new Error("404 NOT FOUND"); | ||
} | ||
} | ||
} | ||
throw err; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,60 @@ | ||
"use server"; | ||
|
||
import { HTTPError } from "ky"; | ||
import { z } from "zod"; | ||
import { pcomparatorApiClient } from "~/clients/PcomparatorApiClient"; | ||
import type { Profile } from "~/applications/Profile/Domain/Entities/Profile"; | ||
import { pcomparatorAuthenticatedApiClient } from "~/clients/PcomparatorApiClient"; | ||
import { auth } from "~/libraries/nextauth/authConfig"; | ||
|
||
const ParamsSchema = z.object({ | ||
fullname: z.string() | ||
name: z.string().min(0).max(32) | ||
}); | ||
|
||
const PayloadSchema = z.object({ | ||
name: z.string().min(0).max(32) | ||
}); | ||
|
||
export type UpdateFullnameParams = z.infer<typeof ParamsSchema>; | ||
export type UpdateFullnamePayload = z.infer<typeof PayloadSchema>; | ||
|
||
/** | ||
* `updateFullname` updates the fullname of a user profile | ||
* Updates the authenticated user's full name. | ||
* | ||
* Args: `fullname`: string | ||
* @async | ||
* @function updateFullname | ||
* @param {z.infer<typeof ParamsSchema>} params - The parameters containing the new name to update in the user profile. | ||
* @throws {Error} Throws an error if the user is not authenticated. | ||
* @throws {Error} Throws an error with the message "404 NOT FOUND" if the user is not found on the server. | ||
* @throws {HTTPError} Re-throws any other HTTP errors encountered during the request. | ||
* @returns {Promise<UpdateFullnamePayload>} Resolves to an object containing the updated name upon successful update. | ||
*/ | ||
export const updateFullname = async (params: z.infer<typeof ParamsSchema>): Promise<void> => { | ||
export const updateFullname = async ( | ||
params: z.infer<typeof ParamsSchema> | ||
): Promise<UpdateFullnamePayload> => { | ||
const paramsPayload = ParamsSchema.parse(params); | ||
const session = await auth(); | ||
|
||
await pcomparatorApiClient | ||
.patch(`user/${session?.user?.id}/profile`, { | ||
json: { name: paramsPayload.fullname } | ||
}) | ||
.json(); | ||
if (!session?.user?.id) throw new Error("User not authenticated"); | ||
|
||
try { | ||
const userPayload = PayloadSchema.parse( | ||
await pcomparatorAuthenticatedApiClient | ||
.patch(`user/${session.user.id}/profile`, { | ||
json: { name: paramsPayload.name } | ||
}) | ||
.json<Profile>() | ||
); | ||
|
||
return { name: userPayload.name }; | ||
} catch (err) { | ||
if (err instanceof HTTPError) { | ||
switch (err.response.status) { | ||
case 404: { | ||
console.log("Not Found"); | ||
throw new Error("404 NOT FOUND"); | ||
} | ||
} | ||
} | ||
throw err; | ||
} | ||
}; |
Oops, something went wrong.