1+ import { getRepository } from 'typeorm' ;
12import Story from '../../entities/Story' ;
3+ import User from '../../entities/User' ;
24import StoryState from '../../enum/StoryState' ;
35import StoryRepository from '../../repositories/StoryRepository' ;
46import {
@@ -20,6 +22,7 @@ function getStoryOrThrow(
2022
2123async function onStorySubmitted ( storyId : Story [ 'id' ] ) : Promise < void > {
2224 const story = await getStoryOrThrow ( storyId , StoryState . SUBMITTED ) ;
25+ const userRepository = getRepository ( User ) ;
2326
2427 const hasSubmittedBefore = story . hasEverSubmitted ;
2528
@@ -36,6 +39,22 @@ async function onStorySubmitted(storyId: Story['id']): Promise<void> {
3639 await StoryRepository ( ) . update ( story . id , {
3740 hasEverSubmitted : true ,
3841 } ) ;
42+
43+ try {
44+ // If user with this email is banned, reject the story
45+ const maybeUser = await userRepository . findOneBy ( {
46+ email : story . storytellerEmail ?? '' ,
47+ } ) ;
48+ const isUserBanned = maybeUser ?. isBanned ?? false ;
49+ if ( isUserBanned ) {
50+ await StoryRepository ( ) . update ( story . id , {
51+ state : StoryState . REJECTED ,
52+ lastReviewer : 'system' ,
53+ } ) ;
54+ }
55+ } catch ( e ) {
56+ console . error ( 'Error auto-reviewing story' , e ) ;
57+ }
3958}
4059
4160async function onStoryPublished ( storyId : Story [ 'id' ] ) : Promise < void > {
0 commit comments