@@ -5,30 +5,6 @@ import { db } from '@app/backend-shared';
55
66const postBuyCreature = Router ( ) ;
77
8- // check how many creatures we can unlock in this zone
9- function getTotalCreaturesByZone ( zoneId : number ) {
10- return db
11- . selectFrom ( 'creatures' )
12- . select ( [ db . fn . count ( 'creatures.id' ) . as ( 'quantityCreature' ) ] )
13- . where ( 'creatures.zone_id' , '=' , zoneId )
14- . executeTakeFirst ( ) ;
15- }
16-
17- //check how many creatures user has unlocked in this zone
18- function getCreaturesUnlockedByZone ( zoneId : number , parkId : number ) {
19- return db
20- . selectFrom ( 'park_creatures' )
21- . leftJoin ( 'creatures' , 'park_creatures.creature_id' , 'creatures.id' )
22- . select ( [
23- sql < number > `COUNT(DISTINCT ${ sql . ref ( 'park_creatures.creature_id' ) } )` . as (
24- 'countCreaturesUnlockedByZone' ,
25- ) ,
26- ] )
27- . where ( 'creatures.zone_id' , '=' , zoneId )
28- . where ( 'park_creatures.park_id' , '=' , parkId )
29- . executeTakeFirst ( ) ;
30- }
31-
328//Check if we have already the next zone in bdd
339function getIsNextZoneUnlocked ( parkId : number , zoneId : number ) {
3410 return db
@@ -161,12 +137,7 @@ postBuyCreature.post('/buy', async (req: Request, res) => {
161137 } )
162138 . executeTakeFirst ( ) ;
163139
164- const [ isNextZoneUnlocked ] = await Promise . all ( [
165- getTotalCreaturesByZone ( zoneId ) ,
166- getCreaturesUnlockedByZone ( zoneId , parkId ) ,
167- getIsNextZoneUnlocked ( parkId , zoneId ) ,
168- ] ) ;
169-
140+ const isNextZoneUnlocked = await getIsNextZoneUnlocked ( parkId , zoneId ) ;
170141 const zone = await db
171142 . selectFrom ( 'zones' )
172143 . select ( [ 'name' ] )
0 commit comments