Skip to content

Commit

Permalink
fix: mongoose validate error and upgrade (#10102)
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-mba committed Jan 5, 2024
1 parent 35dbbe3 commit 052f076
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 74 deletions.
87 changes: 34 additions & 53 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"leaflet": "^1.9.4",
"micro": "^10.0.1",
"micro-cors": "^0.1.1",
"mongoose": "^7.6.4",
"mongoose": "^8.0.3",
"next": "^14.0.4",
"next-auth": "^4.24.5",
"next-pwa": "^5.6.0",
Expand Down
42 changes: 22 additions & 20 deletions pages/api/account/manage/link/[[...data]].js
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,20 @@ export async function addLinkApi(context, username, data) {
const log = logger.child({ username });

let getLink = {};
const errors = await Link.validate(data, [
"group",
"name",
"icon",
"url",
"animation",
]);
if (errors) {
try {
await Link.validate(data, [
"group",
"name",
"icon",
"url",
"animation",
]);
} catch(error) {
log.error(
errors,
error.errors,
`validation failed to add link for username: ${username}`,
);
return { error: errors.errors };
return { error: error.errors };
}

try {
Expand Down Expand Up @@ -135,19 +136,20 @@ export async function updateLinkApi(context, username, id, data) {

let getLink = {};

const errors = await Link.validate(data, [
"group",
"name",
"icon",
"url",
"animation",
]);
if (errors) {
try {
await Link.validate(data, [
"group",
"name",
"icon",
"url",
"animation",
]);
} catch (error) {
log.error(
errors,
error.errors,
`validation failed to update link for username: ${username}`,
);
return { error: errors.errors };
return { error: error.errors };
}

try {
Expand Down

0 comments on commit 052f076

Please sign in to comment.