@@ -636,12 +636,8 @@ module.exports.authQuery = async (event: { body: { query: any; pars: any; }; cog
636636 return await updateGameSettings ( event . cognitoPoolClaims . sub , pars ) ;
637637 case "update_user_settings" :
638638 return await updateUserSettings ( event . cognitoPoolClaims . sub , pars ) ;
639- case "update_meta_game_counts" :
640- return await updateMetaGameCounts ( event . cognitoPoolClaims . sub ) ;
641639 case "mark_published" :
642640 return await markAsPublished ( event . cognitoPoolClaims . sub , pars ) ;
643- case "update_meta_game_ratings" :
644- return await updateMetaGameRatings ( event . cognitoPoolClaims . sub ) ;
645641 case "new_tournament" :
646642 return await newTournament ( event . cognitoPoolClaims . sub , pars ) ;
647643 case "join_tournament" :
@@ -7181,221 +7177,6 @@ async function sendPush(opts: PushOptions) {
71817177 }
71827178}
71837179
7184- async function updateMetaGameCounts ( userId : string ) {
7185- // Make sure people aren't getting clever
7186- try {
7187- const user = await ddbDocClient . send (
7188- new GetCommand ( {
7189- TableName : process . env . ABSTRACT_PLAY_TABLE ,
7190- Key : {
7191- "pk" : "USER" ,
7192- "sk" : userId
7193- } ,
7194- } ) ) ;
7195- if ( user . Item === undefined || user . Item . admin !== true ) {
7196- return {
7197- statusCode : 200 ,
7198- body : JSON . stringify ( { } ) ,
7199- headers
7200- } ;
7201- }
7202-
7203- const metaGamesDataWork = ddbDocClient . send (
7204- new GetCommand ( {
7205- TableName : process . env . ABSTRACT_PLAY_TABLE ,
7206- Key : {
7207- "pk" : "METAGAMES" , "sk" : "COUNTS"
7208- } ,
7209- } ) ) ;
7210-
7211- const games : string [ ] = [ ] ;
7212- gameinfo . forEach ( ( game ) => games . push ( game . uid ) ) ;
7213- const currentgames = games . map ( game => ddbDocClient . send (
7214- new QueryCommand ( {
7215- TableName : process . env . ABSTRACT_PLAY_TABLE ,
7216- KeyConditionExpression : "#pk = :pk and begins_with(#sk, :sk)" ,
7217- ExpressionAttributeValues : { ":pk" : "GAME" , ":sk" : game + '#0#' } ,
7218- ExpressionAttributeNames : { "#pk" : "pk" , "#sk" : "sk" } ,
7219- ProjectionExpression : "#pk, #sk"
7220- } ) ) ) ;
7221- const completedgames = games . map ( game => ddbDocClient . send (
7222- new QueryCommand ( {
7223- TableName : process . env . ABSTRACT_PLAY_TABLE ,
7224- KeyConditionExpression : "#pk = :pk" ,
7225- ExpressionAttributeValues : { ":pk" : "COMPLETEDGAMES#" + game } ,
7226- ExpressionAttributeNames : { "#pk" : "pk" , "#sk" : "sk" } ,
7227- ProjectionExpression : "#pk, #sk"
7228- } ) ) ) ;
7229- const standingchallenges = games . map ( game => ddbDocClient . send (
7230- new QueryCommand ( {
7231- TableName : process . env . ABSTRACT_PLAY_TABLE ,
7232- KeyConditionExpression : "#pk = :pk" ,
7233- ExpressionAttributeValues : { ":pk" : "STANDINGCHALLENGE#" + game } ,
7234- ExpressionAttributeNames : { "#pk" : "pk" , "#sk" : "sk" } ,
7235- ProjectionExpression : "#pk, #sk"
7236- } ) ) ) ;
7237-
7238- const metaGamesData = await metaGamesDataWork ;
7239- let metaGameCounts : MetaGameCounts ;
7240- if ( metaGamesData . Item === undefined )
7241- metaGameCounts = { } ;
7242- else
7243- metaGameCounts = metaGamesData . Item as MetaGameCounts ;
7244-
7245- const work = await Promise . all ( [ Promise . all ( currentgames ) , Promise . all ( completedgames ) , Promise . all ( standingchallenges ) ] ) ;
7246- console . log ( "work" , work ) ;
7247-
7248- // process stars
7249- const players = await getAllUsers ( ) ;
7250- console . log ( "All players" ) ;
7251- console . log ( JSON . stringify ( players . map ( p => p . name ) ) ) ;
7252- const starCounts = new Map < string , number > ( ) ;
7253- for ( const p of players ) {
7254- if ( p . stars !== undefined ) {
7255- for ( const star of p . stars ) {
7256- if ( starCounts . has ( star ) ) {
7257- const val = starCounts . get ( star ) ! ;
7258- starCounts . set ( star , val + 1 ) ;
7259- } else {
7260- starCounts . set ( star , 1 ) ;
7261- }
7262- }
7263- }
7264- }
7265-
7266- games . forEach ( ( game , ind ) => {
7267- if ( metaGameCounts [ game ] === undefined ) {
7268- metaGameCounts [ game ] = {
7269- "currentgames" : work [ 0 ] [ ind ] . Items ? work [ 0 ] [ ind ] . Items ! . length : 0 ,
7270- "completedgames" : work [ 1 ] [ ind ] . Items ? work [ 1 ] [ ind ] . Items ! . length : 0 ,
7271- "standingchallenges" : work [ 2 ] [ ind ] . Items ? work [ 2 ] [ ind ] . Items ! . length : 0 ,
7272- "stars" : starCounts . has ( game ) ? starCounts . get ( game ) ! : 0 ,
7273- } ;
7274- } else {
7275- metaGameCounts [ game ] . currentgames = work [ 0 ] [ ind ] . Items ? work [ 0 ] [ ind ] . Items ! . length : 0 ;
7276- metaGameCounts [ game ] . completedgames = work [ 1 ] [ ind ] . Items ? work [ 1 ] [ ind ] . Items ! . length : 0 ;
7277- metaGameCounts [ game ] . standingchallenges = work [ 2 ] [ ind ] . Items ? work [ 2 ] [ ind ] . Items ! . length : 0 ;
7278- metaGameCounts [ game ] . stars = starCounts . has ( game ) ? starCounts . get ( game ) ! : 0 ;
7279- }
7280- } ) ;
7281-
7282- console . log ( metaGameCounts ) ;
7283- await ddbDocClient . send (
7284- new PutCommand ( {
7285- TableName : process . env . ABSTRACT_PLAY_TABLE ,
7286- Item : {
7287- "pk" : "METAGAMES" ,
7288- "sk" : "COUNTS" ,
7289- ...metaGameCounts
7290- }
7291- } )
7292- ) ;
7293- } catch ( err ) {
7294- logGetItemError ( err ) ;
7295- return formatReturnError ( `Unable to update meta game counts ${ userId } ` ) ;
7296- }
7297- }
7298-
7299- async function updateMetaGameRatings ( userId : string ) {
7300- // Make sure people aren't getting clever
7301- try {
7302- const user = await ddbDocClient . send (
7303- new GetCommand ( {
7304- TableName : process . env . ABSTRACT_PLAY_TABLE ,
7305- Key : {
7306- "pk" : "USER" ,
7307- "sk" : userId
7308- } ,
7309- } ) ) ;
7310- if ( user . Item === undefined || user . Item . admin !== true ) {
7311- return {
7312- statusCode : 200 ,
7313- body : JSON . stringify ( { } ) ,
7314- headers
7315- } ;
7316- }
7317-
7318- const metaGamesDataWork = ddbDocClient . send (
7319- new GetCommand ( {
7320- TableName : process . env . ABSTRACT_PLAY_TABLE ,
7321- Key : {
7322- "pk" : "METAGAMES" , "sk" : "COUNTS"
7323- } ,
7324- } ) ) ;
7325-
7326- const data = await ddbDocClient . send (
7327- new QueryCommand ( {
7328- TableName : process . env . ABSTRACT_PLAY_TABLE ,
7329- KeyConditionExpression : "#pk = :pk" ,
7330- ExpressionAttributeValues : { ":pk" : "USER" } ,
7331- ExpressionAttributeNames : { "#pk" : "pk" }
7332- } ) ) ;
7333- if ( data . Items === undefined ) {
7334- return ;
7335- }
7336- const ratings : {
7337- [ metaGame : string ] : { player : string , name : string , rating : Rating } [ ] ;
7338- } = { } ;
7339- const users = data . Items as FullUser [ ] ;
7340- users . forEach ( player => {
7341- if ( player . ratings ) {
7342- Object . keys ( player . ratings ) . forEach ( metaGame => {
7343- if ( ratings [ metaGame ] === undefined )
7344- ratings [ metaGame ] = [ ] ;
7345- ratings [ metaGame ] . push ( { player : player . id , name : player . name , rating : player . ratings ! [ metaGame ] } ) ;
7346- } ) ;
7347- }
7348- } ) ;
7349-
7350- const work : Promise < any > [ ] = [ ] ;
7351- const metaGamesData = await metaGamesDataWork ;
7352- const metaGameCounts = metaGamesData . Item as MetaGameCounts ;
7353- Object . keys ( ratings ) . forEach ( metaGame => {
7354- if ( metaGameCounts [ metaGame ] === undefined )
7355- metaGameCounts [ metaGame ] = { currentgames : 0 , completedgames : 0 , standingchallenges : 0 } ;
7356-
7357- // Use new flattened ratings structure
7358- const flattenedKey = `${ metaGame } _ratings` ;
7359- const ratingsArray : string [ ] = [ ] ;
7360-
7361- ratings [ metaGame ] . forEach ( rating => {
7362- if ( ! ratingsArray . includes ( rating . player ) ) {
7363- ratingsArray . push ( rating . player ) ;
7364- }
7365- work . push ( sendCommandWithRetry (
7366- new PutCommand ( {
7367- TableName : process . env . ABSTRACT_PLAY_TABLE ,
7368- Item : {
7369- "pk" : "RATINGS#" + metaGame ,
7370- "sk" : rating . player ,
7371- "id" : rating . player ,
7372- "name" : rating . name ,
7373- "rating" : rating . rating
7374- }
7375- } )
7376- ) ) ;
7377- } ) ;
7378-
7379- // Set flattened ratings
7380- ( metaGameCounts as any ) [ flattenedKey ] = ratingsArray ;
7381- } ) ;
7382-
7383- work . push ( sendCommandWithRetry (
7384- new PutCommand ( {
7385- TableName : process . env . ABSTRACT_PLAY_TABLE ,
7386- Item : {
7387- "pk" : "METAGAMES" ,
7388- "sk" : "COUNTS" ,
7389- ...metaGameCounts
7390- }
7391- } )
7392- ) ) ;
7393- await Promise . all ( work ) ;
7394- } catch ( err ) {
7395- logGetItemError ( err ) ;
7396- return formatReturnError ( `Unable to update meta game counts ${ userId } ` ) ;
7397- }
7398- }
73997180
74007181async function invokePie ( userid : string , pars : { id : string , metaGame : string , cbit : number } ) {
74017182 if ( pars . cbit !== 0 ) {
0 commit comments