add function of username search in admin vocabulary scoreaudit
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user