refactor(models,validators): tighten validation and standardize couchdbService usage\n\n- User: fix bio length check, error messages, and typos (couchdbService calls and bcrypt prefix).\n- UserBadge: use array from find(), return couchdbService results consistently, and call updateDocument/deleteDocument APIs.\n- profileValidator: switch custom URL regex to express-validator isURL with protocol requirement.\n\n🤖 Generated with [AI Assistant]\n\nCo-Authored-By: AI Assistant <noreply@ai-assistant.com>
This commit is contained in:
@@ -48,7 +48,7 @@ class UserBadge {
|
||||
};
|
||||
|
||||
const result = await couchdbService.createDocument(doc);
|
||||
return { ...doc, _rev: result.rev };
|
||||
return result;
|
||||
}, errorContext);
|
||||
}
|
||||
|
||||
@@ -80,8 +80,8 @@ class UserBadge {
|
||||
...filter,
|
||||
};
|
||||
|
||||
const result = await couchdbService.find(selector);
|
||||
return result.docs;
|
||||
const docs = await couchdbService.find({ selector });
|
||||
return docs;
|
||||
}, errorContext);
|
||||
}
|
||||
|
||||
@@ -94,8 +94,7 @@ class UserBadge {
|
||||
user: userId,
|
||||
};
|
||||
|
||||
const result = await couchdbService.find(selector);
|
||||
const userBadges = result.docs;
|
||||
const userBadges = await couchdbService.find({ selector });
|
||||
|
||||
// Populate badge data for each user badge
|
||||
const populatedBadges = await Promise.all(
|
||||
@@ -124,8 +123,8 @@ class UserBadge {
|
||||
badge: badgeId,
|
||||
};
|
||||
|
||||
const result = await couchdbService.find(selector);
|
||||
return result.docs;
|
||||
const docs = await couchdbService.find({ selector });
|
||||
return docs;
|
||||
}, errorContext);
|
||||
}
|
||||
|
||||
@@ -147,8 +146,8 @@ class UserBadge {
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
|
||||
const result = await couchdbService.createDocument(updatedDoc);
|
||||
return { ...updatedDoc, _rev: result.rev };
|
||||
const result = await couchdbService.updateDocument(updatedDoc);
|
||||
return result;
|
||||
}, errorContext);
|
||||
}
|
||||
|
||||
@@ -161,7 +160,7 @@ class UserBadge {
|
||||
throw new NotFoundError('UserBadge', id);
|
||||
}
|
||||
|
||||
await couchdbService.destroy(id, doc._rev);
|
||||
await couchdbService.deleteDocument(id, doc._rev);
|
||||
return true;
|
||||
}, errorContext);
|
||||
}
|
||||
@@ -176,8 +175,8 @@ class UserBadge {
|
||||
badge: badgeId,
|
||||
};
|
||||
|
||||
const result = await couchdbService.find(selector);
|
||||
return result.docs[0] || null;
|
||||
const docs = await couchdbService.find({ selector });
|
||||
return docs[0] || null;
|
||||
}, errorContext);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user