add function of username search in admin vocabulary scoreaudit

This commit is contained in:
2026-06-04 20:09:38 +08:00
parent 37e4837e3f
commit 8fd1606424
3 changed files with 27 additions and 3 deletions

View File

@@ -70,6 +70,7 @@ const INVALIDATING_VOCABULARY_RISK_FLAGS = [
];
const getObjectIdString = (value: any): string => value?._id?.toString?.() || value?.toString?.() || '';
const escapeRegex = (value: string): string => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const parseAdminDateRange = (source: Record<string, any>) => {
const start = new Date(String(source.start || source.startTime || ''));
@@ -544,6 +545,17 @@ router.get('/vocabulary/test-pass-summary', adminAuth, async (req, res) => {
}
const { start, end } = range as { start: Date; end: Date };
const studentNo = String(req.query.studentNo || '').trim();
const userMatchStages = studentNo
? [{
$match: {
'user.username': {
$regex: escapeRegex(studentNo),
$options: 'i'
}
}
}]
: [];
const validPassItems = await VocabularyTestRecord.aggregate([
{
$match: {
@@ -575,6 +587,7 @@ router.get('/vocabulary/test-pass-summary', adminAuth, async (req, res) => {
}
},
{ $unwind: { path: '$user', preserveNullAndEmptyArrays: true } },
...userMatchStages,
{
$project: {
_id: 0,
@@ -630,6 +643,7 @@ router.get('/vocabulary/test-pass-summary', adminAuth, async (req, res) => {
}
},
{ $unwind: { path: '$user', preserveNullAndEmptyArrays: true } },
...userMatchStages,
{
$project: {
_id: 0,