Skip to content

Commit cf315bb

Browse files
authored
Instance Standing Bug Fixes (#92)
* return data that wasnt there before * docs
1 parent bee4fb3 commit cf315bb

4 files changed

Lines changed: 31 additions & 14 deletions

File tree

open-api/openapi.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,8 @@
634634
"type": "string"
635635
},
636636
"individualReason": {
637-
"type": "string"
637+
"type": "string",
638+
"nullable": true
638639
},
639640
"createdAt": {
640641
"type": "string",

src/schema/components/InstanceStanding.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export const zInstancePlayerStanding = registry.register(
142142
instanceId: zInt64(),
143143
instanceDate: zISODateString(),
144144
reason: z.string(),
145-
individualReason: z.string(),
145+
individualReason: z.string().nullable(),
146146
createdAt: zISODateString()
147147
})
148148
),

src/services/reporting/standing.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,19 @@ describe("getInstancePlayersStanding", () => {
5353
expect(parsed.success).toBe(true)
5454
}
5555
})
56+
57+
it("returns the correct shape #2", async () => {
58+
const standing = await getInstancePlayersStanding("16327328028")
59+
expect(standing.length).toBe(6)
60+
expect(standing[1].playerInfo.membershipId).toBe("4611686018470558748")
61+
expect(standing[1].blacklistedInstances.length).toBeGreaterThan(0)
62+
63+
const parsed = z.array(zInstancePlayerStanding).safeParse(standing)
64+
if (!parsed.success) {
65+
console.error(parsed.error.errors)
66+
expect(parsed.error.errors).toEqual([])
67+
} else {
68+
expect(parsed.success).toBe(true)
69+
}
70+
})
5671
})

src/services/reporting/standing.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,31 +89,32 @@ export const getInstancePlayersStanding = async (instanceId: bigint | string) =>
8989
'flaggedAt', fip.flagged_at
9090
) AS "data"
9191
FROM flag_instance_player fip
92-
JOIN instance i ON i.instance_id = fip.instance_id
92+
JOIN instance i USING (instance_id)
9393
WHERE fip.membership_id = p.membership_id
9494
AND fip.instance_id <> $1::bigint
95-
ORDER BY date_trunc('week', fip.flagged_at) DESC, fip.cheat_probability DESC
96-
LIMIT 10
95+
ORDER BY (fip.cheat_probability - EXTRACT(EPOCH FROM (NOW() - i.date_started)) / 86400 / 365) DESC
96+
LIMIT 15
9797
) AS f
9898
) AS "otherRecentFlags",
9999
(
100100
SELECT COALESCE(jsonb_agg(b.data), '[]'::jsonb)
101101
FROM (
102102
SELECT json_build_object(
103-
'instanceId', bip.instance_id,
103+
'instanceId', bi.instance_id::text,
104104
'individualReason', bip.reason,
105105
'reason', bi.reason,
106106
'createdAt', bi.created_at,
107107
'instanceDate', i.date_started
108108
) AS "data"
109-
FROM blacklist_instance_player bip
110-
JOIN instance i ON i.instance_id = bip.instance_id
111-
JOIN blacklist_instance bi ON bi.instance_id = bip.instance_id
112-
WHERE bip.membership_id = p.membership_id
113-
AND bip.instance_id <> $1::bigint
114-
AND i.date_started < NOW() - INTERVAL '6 months'
115-
ORDER BY bip.instance_id DESC
116-
LIMIT 10
109+
FROM blacklist_instance bi
110+
JOIN instance i ON i.instance_id = bi.instance_id
111+
JOIN instance_player ip ON ip.instance_id = bi.instance_id AND ip.membership_id = p.membership_id
112+
LEFT JOIN blacklist_instance_player bip ON bi.instance_id = bip.instance_id
113+
AND bip.membership_id = p.membership_id
114+
WHERE bi.instance_id <> $1::bigint
115+
AND NOT (bi.report_source = 'BlacklistedPlayerCascade' AND bip.membership_id IS NOT NULL)
116+
ORDER BY i.date_started DESC
117+
LIMIT 15
117118
) AS b
118119
) AS "blacklistedInstances"
119120
FROM instance_player ip

0 commit comments

Comments
 (0)