- Here you should find everything you need from getting started with - creating your Profile to more advanced topics. We welcome - contributions, check out the - - LinkFree Repo - - and the - - documentation source - {" "} - on GitHub for more information. -
-For example: EddieCon v0.1 @@ -132,18 +161,24 @@ export default function ManageEvent({ BASE_URL, event }) {
For example: 2022-12-09T16:00:00.000+00:00 @@ -151,13 +186,15 @@ export default function ManageEvent({ BASE_URL, event }) {
- For example: 2022-12-10T16:00:00.000+00:00 + For example: DD / MM / YYYY
You can{" "} @@ -124,12 +150,16 @@ export default function ManageLink({ BASE_URL, username, link }) {
For example: https://twitter.com/eddiejaoude @@ -141,6 +171,9 @@ export default function ManageLink({ BASE_URL, username, link }) { label="Display Name" onChange={(e) => setName(e.target.value)} value={name} + required + minLength="2" + maxLength="32" />
For example: Follow me on Twitter @@ -152,6 +185,9 @@ export default function ManageLink({ BASE_URL, username, link }) { label="Icon" onChange={(e) => setIcon(e.target.value)} value={icon} + required + minLength="2" + maxLength="32" />
Search for available{" "}
diff --git a/pages/account/manage/milestone/[[...data]].js b/pages/account/manage/milestone/[[...data]].js
index 80c60750bcc..82a4051a7dc 100644
--- a/pages/account/manage/milestone/[[...data]].js
+++ b/pages/account/manage/milestone/[[...data]].js
@@ -43,11 +43,20 @@ export async function getServerSideProps(context) {
}
export default function ManageMilestone({ BASE_URL, milestone }) {
- const [showNotification, setShowNotification] = useState(false);
- const [title, setTitle] = useState(milestone.title);
- const [description, setDescription] = useState(milestone.description);
- const [url, setUrl] = useState(milestone.url);
- const [icon, setIcon] = useState(milestone.icon);
+ const [showNotification, setShowNotification] = useState({
+ show: false,
+ type: "",
+ message: "",
+ additionalMessage: "",
+ });
+ const [title, setTitle] = useState(
+ milestone.title || "Title of your Milestone"
+ );
+ const [description, setDescription] = useState(
+ milestone.description || "Description of your Milestone"
+ );
+ const [url, setUrl] = useState(milestone.url || "");
+ const [icon, setIcon] = useState(milestone.icon || "FaGithub");
const [date, setDate] = useState(milestone.date);
const [isGoal, setIsGoal] = useState(milestone.isGoal);
@@ -75,8 +84,25 @@ export default function ManageMilestone({ BASE_URL, milestone }) {
},
body: JSON.stringify(putMilestone),
});
- await res.json();
- setShowNotification(true);
+ const update = await res.json();
+
+ if (update.message) {
+ return setShowNotification({
+ show: true,
+ type: "error",
+ message: "Milestone update failed",
+ additionalMessage: `Please check the fields: ${Object.keys(
+ update.message
+ ).join(", ")}`,
+ });
+ }
+
+ return setShowNotification({
+ show: true,
+ type: "success",
+ message: "Milestone added/updated",
+ additionalMessage: "Your milestone has been added/updated successfully",
+ });
};
return (
@@ -90,11 +116,13 @@ export default function ManageMilestone({ BASE_URL, milestone }) {
For example: GitHub Star
@@ -128,6 +159,9 @@ export default function ManageMilestone({ BASE_URL, milestone }) {
label="Description"
onChange={(e) => setDescription(e.target.value)}
value={description}
+ required
+ minLength="2"
+ maxLength="512"
/>
Describe this Milestone
@@ -135,10 +169,13 @@ export default function ManageMilestone({ BASE_URL, milestone }) {
Link to more information (optional)
@@ -146,13 +183,15 @@ export default function ManageMilestone({ BASE_URL, milestone }) {
- For example: May 2010
+ For example: DD / MM / YYYY
Search for available{" "}
diff --git a/pages/account/manage/profile.js b/pages/account/manage/profile.js
index e3e4f774411..02b87f5854b 100644
--- a/pages/account/manage/profile.js
+++ b/pages/account/manage/profile.js
@@ -63,11 +63,11 @@ export default function Profile({ BASE_URL, profile, fileExists }) {
additionalMessage: "",
});
const [layout, setLayout] = useState(profile.layout || "classic");
- const [name, setName] = useState(profile.name);
+ const [name, setName] = useState(profile.name || "Your name");
const [bio, setBio] = useState(
profile.bio || "Have a look at my links below..."
);
- const [tags, setTags] = useState(profile.tags || []);
+ const [tags, setTags] = useState(profile.tags || ["EddieHub"]);
const layouts = ["classic", "inline"];
const handleSubmit = async (e) => {
diff --git a/pages/api/account/manage/event/[[...data]].js b/pages/api/account/manage/event/[[...data]].js
index fa78056dc64..7069f1dc37d 100644
--- a/pages/api/account/manage/event/[[...data]].js
+++ b/pages/api/account/manage/event/[[...data]].js
@@ -5,6 +5,7 @@ import { ObjectId } from "bson";
import connectMongo from "@config/mongo";
import logger from "@config/logger";
import Profile from "@models/Profile";
+import { Event } from "@models/Profile/Event";
export default async function handler(req, res) {
const session = await getServerSession(req, res, authOptions);
@@ -70,11 +71,19 @@ export async function getEventApi(username, id) {
return JSON.parse(JSON.stringify(getEvent[0]));
}
-export async function updateEventApi(username, id, event) {
+export async function updateEventApi(username, id, updateEvent) {
await connectMongo();
const log = logger.child({ username });
let getEvent = {};
+
+ try {
+ await Event.validate(updateEvent, ["name", "description", "url", "date"]);
+ } catch (e) {
+ log.error(e, `validation failed to update event for username: ${username}`);
+ return { error: e.errors };
+ }
+
try {
getEvent = await Profile.findOneAndUpdate(
{
@@ -84,7 +93,7 @@ export async function updateEventApi(username, id, event) {
{
$set: {
source: "database",
- "events.$": event,
+ "events.$": updateEvent,
},
},
{ upsert: true }
@@ -96,17 +105,26 @@ export async function updateEventApi(username, id, event) {
return JSON.parse(JSON.stringify(getEvent));
}
-export async function addEventApi(username, event) {
+export async function addEventApi(username, addEvent) {
await connectMongo();
const log = logger.child({ username });
+
let getEvent = {};
+
+ try {
+ await Event.validate(addEvent, ["name", "description", "url", "date"]);
+ } catch (e) {
+ log.error(e, `validation failed to add event for username: ${username}`);
+ return { error: e.errors };
+ }
+
try {
getEvent = await Profile.findOneAndUpdate(
{
username,
},
{
- $push: { events: event },
+ $push: { events: addEvent },
},
{ upsert: true }
);
diff --git a/pages/api/account/manage/link/[[...data]].js b/pages/api/account/manage/link/[[...data]].js
index e20f343fd07..aec19677e0a 100644
--- a/pages/api/account/manage/link/[[...data]].js
+++ b/pages/api/account/manage/link/[[...data]].js
@@ -54,6 +54,17 @@ export async function updateLinkApi(username, url, data) {
const log = logger.child({ username });
let getLink = {};
+
+ try {
+ await Link.validate(data, ["group", "name", "icon", "url"]);
+ } catch (e) {
+ log.error(
+ e,
+ `validation failed to add/update link for username: ${username}`
+ );
+ return { error: e.errors };
+ }
+
try {
getLink = await Link.findOneAndUpdate(
{
diff --git a/pages/api/account/manage/milestone/[[...data]].js b/pages/api/account/manage/milestone/[[...data]].js
index 578888acbd6..d5d32a3239f 100644
--- a/pages/api/account/manage/milestone/[[...data]].js
+++ b/pages/api/account/manage/milestone/[[...data]].js
@@ -5,6 +5,7 @@ import { ObjectId } from "bson";
import connectMongo from "@config/mongo";
import logger from "@config/logger";
import Profile from "@models/Profile";
+import { Milestone } from "@models/Profile/Milestone";
export default async function handler(req, res) {
const session = await getServerSession(req, res, authOptions);
@@ -26,9 +27,9 @@ export default async function handler(req, res) {
}
if (req.method === "PUT") {
if (data?.length && data[0]) {
- milestone = await updateMilstoneApi(username, data[0], req.body);
+ milestone = await updateMilestoneApi(username, data[0], req.body);
} else {
- milestone = await addMilstoneApi(username, req.body);
+ milestone = await addMilestoneApi(username, req.body);
}
}
@@ -70,11 +71,28 @@ export async function getMilestoneApi(username, id) {
return JSON.parse(JSON.stringify(getMilestone[0]));
}
-export async function updateMilstoneApi(username, id, milestone) {
+export async function updateMilestoneApi(username, id, updateMilestone) {
await connectMongo();
const log = logger.child({ username });
let getMilestone = {};
+
+ try {
+ await Milestone.validate(updateMilestone, [
+ "url",
+ "date",
+ "title",
+ "icon",
+ "description",
+ ]);
+ } catch (e) {
+ log.error(
+ e,
+ `validation failed to update milestone for username: ${username}`
+ );
+ return { error: e.errors };
+ }
+
try {
getMilestone = await Profile.findOneAndUpdate(
{
@@ -84,10 +102,10 @@ export async function updateMilstoneApi(username, id, milestone) {
{
$set: {
source: "database",
- "milestones.$": milestone,
+ "milestones.$": updateMilestone,
},
},
- { upsert: true }
+ { upsert: true, new: true }
);
} catch (e) {
log.error(e, `failed to update milestone for username: ${username}`);
@@ -96,22 +114,39 @@ export async function updateMilstoneApi(username, id, milestone) {
return JSON.parse(JSON.stringify(getMilestone));
}
-export async function addMilstoneApi(username, milestone) {
+export async function addMilestoneApi(username, addMilestone) {
await connectMongo();
const log = logger.child({ username });
let getMilestone = {};
+
+ try {
+ await Milestone.validate(addMilestone, [
+ "url",
+ "date",
+ "title",
+ "icon",
+ "description",
+ ]);
+ } catch (e) {
+ log.error(
+ e,
+ `validation failed to add milestone for username: ${username}`
+ );
+ return { error: e.errors };
+ }
+
try {
getMilestone = await Profile.findOneAndUpdate(
{
username,
},
{
- $push: { milestones: milestone },
+ $push: { milestones: addMilestone },
},
- { upsert: true }
+ { upsert: true, new: true }
);
} catch (e) {
- log.error(e, `failed to update milestone for username: ${username}`);
+ log.error(e, `failed to add milestone for username: ${username}`);
}
return JSON.parse(JSON.stringify(getMilestone));