Skip to content

Commit

Permalink
Merge pull request #54 from Code-Hammers/CHE-30/subtask/Design-And-Im…
Browse files Browse the repository at this point in the history
…plement-Profile-Model

[CHE-30] Design And Implement Profile Model
  • Loading branch information
brok3turtl3 authored Mar 28, 2024
2 parents 4248956 + 554608e commit 91292c9
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 77 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions client/src/components/ProfileThumb/ProfileThumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const ProfileThumb = ({ profile }: ProfileThumbProps): JSX.Element => {

return (
<div className="min-h-screen bg-gray-100 flex flex-col items-center justify-center">
<h1 className="text-4xl font-extrabold mb-4">{profile.firstName}</h1>
<h2 className="text-4xl font-extrabold mb-4">{profile.bio}</h2>
<h1 className="text-4xl font-extrabold mb-4">{profile.fullName}</h1>
<h2 className="text-4xl font-extrabold mb-4">{profile.personalBio}</h2>
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/Profile/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Profile = (): JSX.Element => {
<div className="min-h-screen bg-gray-100 flex flex-col items-center justify-center">
<h1 className="text-4xl font-extrabold mb-4">Profile</h1>
<h2 className="text-4xl font-extrabold mb-4">{user?._id}</h2>
<h2 className="text-4xl font-extrabold mb-4">{userProfile?.bio}</h2>
<h2 className="text-4xl font-extrabold mb-4">{userProfile?.fullName}</h2>
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/Profiles/Profiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Profiles = (): JSX.Element => {
</div>
<div>
{profiles.map((profile) => (
<ProfileThumb key={profile.user} profile={profile} />
<ProfileThumb key={profile._id} profile={profile} />
))}
</div>
</>
Expand Down
78 changes: 63 additions & 15 deletions client/types/profile.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,71 @@
interface ISocial {
linkedIn?: string;
github?: string;
import { Document, ObjectId } from "mongoose";

interface ISocialLinks {
twitter?: string;
facebook?: string;
instagram?: string;
blog?: string;
other?: string[];
}

interface IProject {
name: string;
description?: string;
link?: string;
}

interface IJob {
interface ICareerPosition {
title?: string;
company?: string;
description?: string;
date?: Date;
startDate?: Date;
endDate?: Date;
}

interface IEducation {
institution: string;
degree?: string;
fieldOfStudy?: string;
startDate?: Date;
endDate?: Date;
}

interface ITestimonial {
from: string;
relation?: string;
text: string;
}

interface IBlogOrWriting {
title: string;
link: string;
}

export interface IProfile {
user: string;
firstName: string;
lastName: string;
bio?: string;
job?: IJob;
socials?: ISocial;
export interface IProfile extends Document {
user: ObjectId;
fullName: string;
profilePhoto?: string;
cohort?: string;
graduationYear?: number;
email?: string;
linkedInProfile?: string;
professionalSummary?: string;
skills?: string[];
specializations?: string[];
careerInformation?: {
currentPosition?: {
title?: string;
company?: string;
};
pastPositions?: ICareerPosition[];
};
education?: IEducation[];
projects?: IProject[];
personalBio?: string;
testimonials?: ITestimonial[];
socialMediaLinks?: ISocialLinks;
availabilityForNetworking?: boolean;
bootcampExperience?: string;
achievementsAndCertifications?: string[];
volunteerWork?: string[];
eventParticipation?: string[];
gallery?: string[];
blogOrWriting?: IBlogOrWriting[];
}
60 changes: 52 additions & 8 deletions server/controllers/profileController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,70 @@ const createProfile = async (
res: Response,
next: NextFunction
) => {
const { user, firstName, lastName, bio, job, socials } = req.body;
const {
user,
fullName,
profilePhoto,
cohort,
graduationYear,
email,
linkedInProfile,
professionalSummary,
skills,
specializations,
careerInformation,
education,
projects,
personalBio,
testimonials,
socialMediaLinks,
availabilityForNetworking,
bootcampExperience,
achievementsAndCertifications,
volunteerWork,
eventParticipation,
gallery,
blogOrWriting,
} = req.body;

try {
const profile: IProfile = await Profile.create({
const profile = await Profile.create({
user,
firstName,
lastName,
bio,
job,
socials,
fullName,
profilePhoto,
cohort,
graduationYear,
email,
linkedInProfile,
professionalSummary,
skills,
specializations,
careerInformation,
education,
projects,
personalBio,
testimonials,
socialMediaLinks,
availabilityForNetworking,
bootcampExperience,
achievementsAndCertifications,
volunteerWork,
eventParticipation,
gallery,
blogOrWriting,
});

if (profile) {
return res.status(201).json(profile);
}
} catch (error) {
console.error(error);
return next({
log: "Express error in createProfile Middleware",
status: 500,
message: { err: "An error occurred during profile creation" },
message: {
err: "An error occurred during profile creation. Please try again.",
},
});
}
};
Expand Down
99 changes: 64 additions & 35 deletions server/models/profileModel.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,75 @@
import mongoose from "mongoose";
// profileModel.ts
import mongoose, { Schema } from "mongoose";
import { IProfile } from "../types/profile";

const profileSchema = new mongoose.Schema<IProfile>({
user: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
required: true,
},
bio: {
type: String,
},
firstName: {
type: String,
},
lastName: {
type: String,
},
job: {
title: String,
company: String,
description: String,
date: Date,
},
socials: {
linkedIn: {
type: String,
},
github: {
type: String,
const profileSchema = new Schema<IProfile>({
user: { type: Schema.Types.ObjectId, ref: "User", required: true },
fullName: { type: String, required: true },
profilePhoto: String,
cohort: String,
graduationYear: Number,
email: String,
linkedInProfile: String,
professionalSummary: String,
skills: [String],
specializations: [String],
careerInformation: {
currentPosition: {
title: String,
company: String,
},
twitter: {
type: String,
pastPositions: [
{
title: String,
company: String,
startDate: Date,
endDate: Date,
},
],
},
education: [
{
institution: String,
degree: String,
fieldOfStudy: String,
startDate: Date,
endDate: Date,
},
facebook: {
type: String,
],
projects: [
{
name: String,
description: String,
link: String,
},
instagram: {
type: String,
],
personalBio: String,
testimonials: [
{
from: String,
relation: String,
text: String,
},
],
socialMediaLinks: {
twitter: String,
blog: String,
other: [String],
},
availabilityForNetworking: Boolean,
bootcampExperience: String,
achievementsAndCertifications: [String],
volunteerWork: [String],
eventParticipation: [String],
gallery: [String],
blogOrWriting: [
{
title: String,
link: String,
},
],
});

const Profile = mongoose.model("Profile", profileSchema);
const Profile = mongoose.model<IProfile>("profiles", profileSchema);

export default Profile;
4 changes: 2 additions & 2 deletions server/models/userModel.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import mongoose, { Document } from "mongoose";
import mongoose, { Schema } from "mongoose";
import bcrypt from "bcryptjs";
import { IUser } from "../types/user";

const userSchema = new mongoose.Schema<IUser>({
const userSchema = new Schema<IUser>({
firstName: {
type: String,
required: true,
Expand Down
Loading

0 comments on commit 91292c9

Please sign in to comment.