fix auction position query
This commit is contained in:
		
							parent
							
								
									73033dc015
								
							
						
					
					
						commit
						aed7e0f667
					
				@ -553,30 +553,37 @@ export default {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    auctionPosition: async (parent, { id, sub, bid }, { models, me }) => {
 | 
					    auctionPosition: async (parent, { id, sub, bid }, { models, me }) => {
 | 
				
			||||||
      // count items that have a bid gte to the current bid or
 | 
					      const createdAt = id ? (await getItem(parent, { id }, { models, me })).createdAt : new Date()
 | 
				
			||||||
      // gte current bid and older
 | 
					      let where
 | 
				
			||||||
      const where = {
 | 
					      if (bid > 0) {
 | 
				
			||||||
        where: {
 | 
					        // if there's a bid
 | 
				
			||||||
          subName: sub,
 | 
					        // it's ACTIVE and has a larger bid than ours, or has an equal bid and is older
 | 
				
			||||||
          status: { not: 'STOPPED' }
 | 
					        // count items: (bid > ours.bid OR (bid = ours.bid AND create_at < ours.created_at)) AND status = 'ACTIVE'
 | 
				
			||||||
 | 
					        where = {
 | 
				
			||||||
 | 
					          status: 'ACTIVE',
 | 
				
			||||||
 | 
					          OR: [
 | 
				
			||||||
 | 
					            { maxBid: { gt: bid } },
 | 
				
			||||||
 | 
					            { maxBid: bid, createdAt: { lt: createdAt } }
 | 
				
			||||||
 | 
					          ]
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
 | 
					        // else
 | 
				
			||||||
 | 
					        // it's an active with a bid gt ours, or its newer than ours and not STOPPED
 | 
				
			||||||
 | 
					        // count items: ((bid > ours.bid AND status = 'ACTIVE') OR (created_at > ours.created_at AND status <> 'STOPPED'))
 | 
				
			||||||
 | 
					        where = {
 | 
				
			||||||
 | 
					          OR: [
 | 
				
			||||||
 | 
					            { maxBid: { gt: 0 }, status: 'ACTIVE' },
 | 
				
			||||||
 | 
					            { createdAt: { gt: createdAt }, status: { not: 'STOPPED' } }
 | 
				
			||||||
 | 
					          ]
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (bid > 0) {
 | 
					      where.subName = sub
 | 
				
			||||||
        where.where.maxBid = { gte: bid }
 | 
					 | 
				
			||||||
      } else {
 | 
					 | 
				
			||||||
        const createdAt = id ? (await getItem(parent, { id }, { models, me })).createdAt : new Date()
 | 
					 | 
				
			||||||
        where.where.OR = [
 | 
					 | 
				
			||||||
          { maxBid: { gt: 0 } },
 | 
					 | 
				
			||||||
          { createdAt: { gt: createdAt } }
 | 
					 | 
				
			||||||
        ]
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if (id) {
 | 
					      if (id) {
 | 
				
			||||||
        where.where.id = { not: Number(id) }
 | 
					        where.id = { not: Number(id) }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      return await models.item.count(where) + 1
 | 
					      return await models.item.count({ where }) + 1
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user