@@ -7,9 +7,11 @@ import {
77 ChatMessageMetadata ,
88 ChatThread ,
99 ModerationFlag ,
10+ ModerationSeverity ,
1011 OfficialRule ,
1112 User ,
1213 VerifiedStatus ,
14+ VerificationResult ,
1315} from "./models" ;
1416import {
1517 createAcsChatThread ,
@@ -391,6 +393,55 @@ export async function listModerationFlags(
391393 return resources . map ( stripCosmosFields ) ;
392394}
393395
396+ export type ModerationFlagDetail = ModerationFlag & { message ?: ChatMessage } ;
397+ export type VerificationDetail = AIVerification & { message ?: ChatMessage } ;
398+
399+ export async function listModerationFlagsBySeverity (
400+ severity : ModerationSeverity
401+ ) : Promise < ModerationFlagDetail [ ] > {
402+ const container = await moderationContainerPromise ;
403+ const { resources } = await container . items
404+ . query < WithId < ModerationFlag > > ( {
405+ query :
406+ "SELECT * FROM c WHERE c.severity = @severity ORDER BY c.createdAt DESC" ,
407+ parameters : [ { name : "@severity" , value : severity } ] ,
408+ } )
409+ . fetchAll ( ) ;
410+
411+ const flags = resources . map ( stripCosmosFields ) ;
412+ const messages = await Promise . all (
413+ flags . map ( ( flag ) => findMessage ( flag . messageId ) )
414+ ) ;
415+
416+ return flags . map ( ( flag , index ) => ( {
417+ ...flag ,
418+ message : messages [ index ] ,
419+ } ) ) ;
420+ }
421+
422+ export async function listVerificationsByResult (
423+ verificationResult : VerificationResult
424+ ) : Promise < VerificationDetail [ ] > {
425+ const container = await verificationsContainerPromise ;
426+ const { resources } = await container . items
427+ . query < WithId < AIVerification > > ( {
428+ query :
429+ "SELECT * FROM c WHERE c.verificationResult = @verificationResult ORDER BY c.createdAt DESC" ,
430+ parameters : [ { name : "@verificationResult" , value : verificationResult } ] ,
431+ } )
432+ . fetchAll ( ) ;
433+
434+ const verifications = resources . map ( stripCosmosFields ) ;
435+ const messages = await Promise . all (
436+ verifications . map ( ( verification ) => findMessage ( verification . messageId ) )
437+ ) ;
438+
439+ return verifications . map ( ( verification , index ) => ( {
440+ ...verification ,
441+ message : messages [ index ] ,
442+ } ) ) ;
443+ }
444+
394445export function getOfficialRules ( schoolId : string , language : string ) {
395446 return store . rules . filter (
396447 ( rule ) => rule . schoolId === schoolId && rule . language === language
0 commit comments