Merge pull request #1963 from stackernews/fix-item-cost
Fix item cost in details
This commit is contained in:
		
						commit
						9aad2fd903
					
				@ -20,18 +20,15 @@ export async function getBaseCost ({ models, bio, parentId, subName }) {
 | 
			
		||||
 | 
			
		||||
  if (parentId) {
 | 
			
		||||
    // the subname is stored in the root item of the thread
 | 
			
		||||
    const parent = await models.item.findFirst({
 | 
			
		||||
      where: { id: Number(parentId) },
 | 
			
		||||
      include: {
 | 
			
		||||
        root: { include: { sub: true } },
 | 
			
		||||
        sub: true
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
    const [sub] = await models.$queryRaw`
 | 
			
		||||
      SELECT s."replyCost"
 | 
			
		||||
      FROM "Item" i
 | 
			
		||||
      LEFT JOIN "Item" r ON r.id = i."rootId"
 | 
			
		||||
      LEFT JOIN "Sub" s ON s.name = COALESCE(r."subName", i."subName")
 | 
			
		||||
      WHERE i.id = ${Number(parentId)}`
 | 
			
		||||
 | 
			
		||||
    const root = parent.root ?? parent
 | 
			
		||||
 | 
			
		||||
    if (!root.sub) return DEFAULT_ITEM_COST
 | 
			
		||||
    return satsToMsats(root.sub.replyCost)
 | 
			
		||||
    if (!sub) return DEFAULT_ITEM_COST
 | 
			
		||||
    return satsToMsats(sub.replyCost)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const sub = await models.sub.findUnique({ where: { name: subName } })
 | 
			
		||||
 | 
			
		||||
@ -108,6 +108,7 @@ export const ITEM_FULL_FIELDS = gql`
 | 
			
		||||
        moderated
 | 
			
		||||
        meMuteSub
 | 
			
		||||
        meSubscription
 | 
			
		||||
        replyCost
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    forwards {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user