Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HK-180-Fixed Extra Resumes #145

Open
wants to merge 25 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3dbc9bb
Removed bootstrap
jacobellerbrock Nov 18, 2024
5253bc9
generate migration file (#139)
joshuasilva414 Nov 18, 2024
c144f7b
Merge remote-tracking branch 'origin/dev' into HK-180-no-duplicate-re…
jacobellerbrock Nov 25, 2024
6fedfec
Added deleting of old resumes
jacobellerbrock Dec 2, 2024
9fd5462
Merge remote-tracking branch 'origin/dev' into HK-180-no-duplicate-re…
christianhelp Dec 7, 2024
bef6bc2
fixes journal
christianhelp Dec 7, 2024
ffcd85d
fixes package json
christianhelp Dec 7, 2024
fd3dd3d
Merge remote-tracking branch 'origin/dev' into HK-180-no-duplicate-re…
christianhelp Dec 17, 2024
e558d1c
Removed db transaction
jacobellerbrock Dec 30, 2024
e0578a5
Fixed deleting resumes on error
jacobellerbrock Dec 30, 2024
674202a
Simplified redundant user verification
jacobellerbrock Dec 30, 2024
8168e07
Simplified redundant user verification
jacobellerbrock Dec 30, 2024
e229323
Fixed resume put into buckets
jacobellerbrock Dec 30, 2024
e883938
Merge branch 'HK-180-no-duplicate-resumes' of https://github.com/acmu…
jacobellerbrock Dec 30, 2024
a7ef7ac
Fixed config import
jacobellerbrock Dec 30, 2024
b06e199
fixes remove resume bug
christianhelp Dec 31, 2024
cea703f
prettier run
christianhelp Dec 31, 2024
6159373
commit for now
christianhelp Jan 3, 2025
147cac5
Merge remote-tracking branch 'origin/dev' into HK-180-no-duplicate-re…
christianhelp Jan 3, 2025
00450fa
format run
christianhelp Jan 3, 2025
235d344
fixes prevent update bug
christianhelp Jan 4, 2025
a3f1832
format write
christianhelp Jan 4, 2025
2c31028
updates account settings
christianhelp Jan 4, 2025
bcb53a7
adds email to settings
christianhelp Jan 4, 2025
e375afe
fix pfp upload bug
christianhelp Jan 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 74 additions & 73 deletions apps/web/src/actions/user-profile-mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import { z } from "zod";
import { db } from "db";
import { userCommonData, userHackerData } from "db/schema";
import { eq } from "db/drizzle";
import { put } from "@vercel/blob";
import { del, put } from "@vercel/blob";
import { decodeBase64AsFile } from "@/lib/utils/shared/files";
import { returnValidationErrors } from "next-safe-action";
import { revalidatePath } from "next/cache";
import { getUser, getUserByTag } from "db/functions";
import { RegistrationSettingsFormValidator } from "@/validators/shared/RegistrationSettingsForm";

import { UNIQUE_KEY_CONSTRAINT_VIOLATION_CODE } from "@/lib/constants";
import c from "config";
import { DatabaseError } from "db/types";
import { registrationSettingsFormValidator, modifyAccountSettingsSchema, profileSettingsSchema } from "@/validators/settings";
import { clerkClient, type User as ClerkUser, } from "@clerk/nextjs/server";
import { PAYLOAD_TOO_LARGE_CODE } from "@/lib/constants";
import { isClerkAPIResponseError } from "@clerk/nextjs";
export const modifyRegistrationData = authenticatedAction
.schema(RegistrationSettingsFormValidator)
.schema(registrationSettingsFormValidator)
.action(
async ({
parsedInput: {
Expand All @@ -37,12 +40,12 @@ export const modifyRegistrationData = authenticatedAction
personalWebsite,
phoneNumber,
countryOfResidence,
uploadedFile,
},
ctx: { userId },
}) => {
const user = await getUser(userId);
if (!user) throw new Error("User not found");
await Promise.all([
// attempts to update both tables with Promise.all
db
.update(userCommonData)
.set({
Expand All @@ -56,7 +59,7 @@ export const modifyRegistrationData = authenticatedAction
phoneNumber,
countryOfResidence,
})
.where(eq(userCommonData.clerkID, user.clerkID)),
.where(eq(userCommonData.clerkID, userId)),
db
.update(userHackerData)
.set({
Expand All @@ -71,9 +74,18 @@ export const modifyRegistrationData = authenticatedAction
GitHub: github,
LinkedIn: linkedin,
PersonalWebsite: personalWebsite,
resume: uploadedFile,
})
.where(eq(userHackerData.clerkID, user.clerkID)),
]);
.where(eq(userHackerData.clerkID, userId)),
]).catch(async (err) => {
console.log(
`Error occured at modify registration data: ${err}`,
);
// If there's an error
return {
success: false,
};
});
return {
success: true,
newAge: age,
Expand All @@ -96,99 +108,78 @@ export const modifyRegistrationData = authenticatedAction
newPersonalWebsite: personalWebsite,
newPhoneNumber: phoneNumber,
newCountryOfResidence: countryOfResidence,
newUploadedFile: uploadedFile,
};
},
);

export const modifyResume = authenticatedAction
export const deleteResume = authenticatedAction
.schema(
z.object({
resume: z.string(),
oldFileLink: z.string(),
}),
)
.action(async ({ parsedInput: { resume }, ctx: { userId } }) => {
await db
.update(userHackerData)
.set({ resume })
.where(eq(userHackerData.clerkID, userId));
return {
success: true,
newResume: resume,
};
.action(async ({ parsedInput: { oldFileLink } }) => {
console.log("called");
if (oldFileLink === c.noResumeProvidedURL) return null;
await del(oldFileLink);
});

export const modifyProfileData = authenticatedAction
.schema(
z.object({
pronouns: z.string(),
bio: z.string(),
skills: z.string().array(),
discord: z.string(),
}),
profileSettingsSchema,
)
.action(
async ({
parsedInput: { bio, discord, pronouns, skills },
parsedInput,
ctx: { userId },
}) => {
const user = await getUser(userId);
if (!user) {
throw new Error("User not found");
}
await db
.update(userCommonData)
.set({ pronouns, bio, skills, discord })
.where(eq(userCommonData.clerkID, user.clerkID));
.set({ ...parsedInput, skills:parsedInput.skills.map((v) => v.text.toLowerCase()) })
.where(eq(userCommonData.clerkID, userId));
return {
success: true,
newPronouns: pronouns,
newBio: bio,
newSkills: skills,
newDiscord: discord,
};
},
);

// TODO: Fix after registration enhancements to allow for failure on conflict and return appropriate error message
export const modifyAccountSettings = authenticatedAction
.schema(
z.object({
firstName: z.string().min(1).max(50),
lastName: z.string().min(1).max(50),
hackerTag: z.string().min(1).max(50),
hasSearchableProfile: z.boolean(),
}),
modifyAccountSettingsSchema,
)
.action(
async ({
parsedInput: {
firstName,
lastName,
hackerTag,
hasSearchableProfile,
isSearchable: hasSearchableProfile,
},
ctx: { userId },
}) => {
const user = await getUser(userId);
if (!user) throw new Error("User not found");
let oldHackerTag = user.hackerTag; // change when hackertag is not PK on profileData table
if (oldHackerTag != hackerTag)
if (await getUserByTag(hackerTag))
//if hackertag changed
// copied from /api/registration/create
try {
await db
.update(userCommonData)
.set({
firstName,
lastName,
hackerTag,
isSearchable: hasSearchableProfile,
})
.where(eq(userCommonData.clerkID, userId));
} catch (err) {
if (
err instanceof DatabaseError &&
err.code === UNIQUE_KEY_CONSTRAINT_VIOLATION_CODE
) {
return {
success: false,
message: "hackertag_not_unique",
};
await db
.update(userCommonData)
.set({
firstName,
lastName,
hackerTag,
isSearchable: hasSearchableProfile,
})
.where(eq(userCommonData.clerkID, userId));
}
throw err;
}
return {
success: true,
newFirstName: firstName,
Expand All @@ -199,23 +190,33 @@ export const modifyAccountSettings = authenticatedAction
},
);

// come back and fix this tmr
export const updateProfileImage = authenticatedAction
.schema(z.object({ fileBase64: z.string(), fileName: z.string() }))
.action(
async ({ parsedInput: { fileBase64, fileName }, ctx: { userId } }) => {
const image = await decodeBase64AsFile(fileBase64, fileName);
const user = await db.query.userCommonData.findFirst({
where: eq(userCommonData.clerkID, userId),
});
if (!user) throw new Error("User not found");
const file = await decodeBase64AsFile(fileBase64, fileName);
let clerkUser:ClerkUser;
try{
clerkUser = await clerkClient.users.updateUserProfileImage(userId, {
file
});
}
catch(err){
if (typeof err === "object" && err != null && 'status' in err && err.status === PAYLOAD_TOO_LARGE_CODE) {
return {
success: false,
message: "file_too_large",
};
}
console.error(`Error updating Clerk profile image: ${err}`);
throw err;
}

const blobUpload = await put(image.name, image, {
access: "public",
});
await db
.update(userCommonData)
.set({ profilePhoto: blobUpload.url })
.where(eq(userCommonData.clerkID, user.clerkID));
.set({ profilePhoto: clerkUser.imageUrl })
.where(eq(userCommonData.clerkID, userId));
revalidatePath("/settings#profile");
return { success: true };
},
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default async function Page() {
return (
<main>
<Header tag="Account" />
<AccountSettings user={user} />
<AccountSettings user={user} email={user.email} />
<Header tag="Profile" />
<ProfileSettings profile={user} />
<Header tag={"Registration"} />
Expand Down
Loading
Loading